Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add comment and list related method and interface #149

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ import type {
import type {
MiniProgramPayload,
} from './schemas/mini-program.js'
import type {
CommentPayload,
} from './schemas/comment.js'
import type {
ListOption,
} from './schemas/list.js'

import type {
PuppetOptions,
Expand Down Expand Up @@ -159,6 +165,8 @@ export type {
RoomPayload,
RoomQueryFilter,
UrlLinkPayload,
CommentPayload,
ListOption,
}

export {
Expand Down
29 changes: 27 additions & 2 deletions src/puppet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ import type {
import type {
MiniProgramPayload,
} from './schemas/mini-program.js'
import type {
ListOption,
} from './schemas/list.js'
import type {
CommentPayload,
} from './schemas/comment.js'
import {
PuppetOptions,
YOU,
} from './schemas/puppet.js'
import { PayloadType } from './schemas/payload.js'
import { PayloadType } from './schemas/payload.js'

import { PuppetEventEmitter } from './events.js'
import { PuppetEventEmitter } from './events.js'

const DEFAULT_WATCHDOG_TIMEOUT = 60
let PUPPET_COUNTER = 0
Expand Down Expand Up @@ -504,6 +510,25 @@ export abstract class Puppet extends PuppetEventEmitter {
abstract tagContactList () : Promise<string[]>
abstract tagContactRemove (tagId: string, contactId: string) : Promise<void>

/**
*
* Comment
*
*/
abstract comment (messageId: string, content: string) : Promise<CommentPayload>
abstract replyComment (commentId: string, content: string) : Promise<CommentPayload>
abstract revokeComment (commentId: string) : Promise<boolean>
abstract listComments (messageId: string, option: ListOption) : Promise<boolean>

/**
*
* Like
*
*/
abstract like (messageId: string) : Promise<boolean>
abstract cancel (messageId: string) : Promise<boolean>
abstract listLikes (messageId: string, option: ListOption) : Promise<boolean>

/**
*
* Contact
Expand Down
7 changes: 7 additions & 0 deletions src/schemas/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface CommentPayload {
id? : string,
content : string,
creatorId : string,
messageId : string,
replyId? : string, // replied comment id
}
4 changes: 4 additions & 0 deletions src/schemas/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ListOption {
pageSize: number,
currentPage: number,
}
21 changes: 21 additions & 0 deletions tests/fixtures/puppet-test/puppet-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
RoomMemberPayload,
RoomQueryFilter,
ContactQueryFilter,
CommentPayload,
ListOption,
} from '../../../src/mod.js'

/**
Expand Down Expand Up @@ -126,6 +128,25 @@ class PuppetTest extends Puppet {
*/
override async conversationReadMark (conversationId: string, hasRead?: boolean): Promise<void | boolean> { void { conversationId, hasRead } }

/**
*
* Comment
*
*/
override async comment (messageId: string, content: string) : Promise<CommentPayload> { return { messageId, content} as any }
override async replyComment (commentId: string, content: string) : Promise<CommentPayload> { return { commentId, content} as any }
override async revokeComment (commentId: string) : Promise<boolean> { return { commentId } as any }
override async listComments (messageId: string, option: ListOption) : Promise<boolean> { return { messageId, option} as any }

/**
*
* Like
*
*/
override async like (messageId: string) : Promise<boolean> { return { messageId } as any}
override async cancel (messageId: string) : Promise<boolean> { return { messageId } as any}
override async listLikes (messageId: string, option: ListOption) : Promise<boolean> { return { messageId, option } as any}

/**
*
* Room Invitation
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/smoke-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {

UrlLinkPayload,
MiniProgramPayload,
CommentPayload,
ListOption,

VERSION,
} from 'wechaty-puppet'
Expand Down Expand Up @@ -121,6 +123,26 @@ class PuppetTest extends Puppet {
*/
override async conversationReadMark (conversationId: string, hasRead?: boolean) : Promise<void | boolean> { void conversationId, void hasRead }

/**
*
* Comment
*
*/
override async comment (messageId: string, content: string) : Promise<CommentPayload> { return { messageId, content} as any }
override async replyComment (commentId: string, content: string) : Promise<CommentPayload> { return { commentId, content} as any }
override async revokeComment (commentId: string) : Promise<boolean> { return { commentId } as any }
override async listComments (messageId: string, option: ListOption) : Promise<boolean> { return { messageId, option} as any }

/**
*
* Like
*
*/
override async like (messageId: string) : Promise<boolean> { return { messageId } as any}
override async cancel (messageId: string) : Promise<boolean> { return { messageId } as any}
override async listLikes (messageId: string, option: ListOption) : Promise<boolean> { return { messageId, option } as any}


/**
*
* Room Invitation
Expand Down