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

Moment #143

Closed
wants to merge 8 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet",
"version": "0.43.10",
"version": "0.43.11",
"description": "Abstract Puppet for Wechaty",
"type": "module",
"exports": {
Expand Down
4 changes: 4 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export {
export {
MiniProgramPayload,
} from './schemas/mini-program.js'
export {
MomentPayload,
MomentListOption,
} from './schemas/moment.js'

export {
throwUnsupportedError,
Expand Down
21 changes: 21 additions & 0 deletions src/puppet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
YOU,
} from './schemas/puppet.js'
import { PayloadType } from './schemas/payload.js'
import { MomentListOption, MomentPayload } from './schemas/moment.js'

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

Expand Down Expand Up @@ -505,6 +506,26 @@ export abstract class Puppet extends PuppetEventEmitter {
abstract tagContactList () : Promise<string[]>
abstract tagContactRemove (tagId: string, contactId: string) : Promise<void>

/**
*
* Moment
*
*/
abstract momentSignature (signature?: string) : Promise<boolean | string>
abstract momentCoverage (image: FileBox) : Promise<boolean>
abstract postTextMoment (content: string, visibleList?: string[]) : Promise<string>
abstract postLinkMoment (urlLinkPayload: UrlLinkPayload, content?: string) : Promise<string>
abstract postImageMoment (images: FileBox[], content?: string) : Promise<string>
Comment on lines +516 to +518
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that possible to merge these functions into one?


abstract momentPayload (id: string) : Promise<MomentPayload>

abstract momentList (option?: MomentListOption) : Promise<string[]>
abstract revokeMoment (id: string) : Promise<boolean>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is delete or remove better than revoke?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see https://cloud.google.com/apis/design/standard_methods and let's follow the google APIs recommendation for standard methods

abstract likeMoment (id: string) : Promise<boolean>
abstract revokeLikeMoment (id: string) : Promise<boolean>
abstract commentMoment (id: string, comment: string, commentId?: string) : Promise<string>
abstract revokeCommentMoment (commentId: string) : Promise<boolean>

/**
*
* Contact
Expand Down
18 changes: 18 additions & 0 deletions src/schemas/moment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FileBox } from '../config'
import { UrlLinkPayload } from './url-link'

export interface MomentPayload {
authorId: string,
content?: string,
urlLink?: UrlLinkPayload,
images?: FileBox[],
id: string,
createTime: number,
updateTime: number,
}

export interface MomentListOption {
authorId?: string,
momentId?: string,
page?: 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 @@ -22,6 +22,7 @@ import { MessagePayloadFilterFunction } from '../../../src/schemas/message.js'
import { RoomPayloadFilterFunction } from '../../../src/schemas/room.js'
import { ContactPayloadFilterFunction } from '../../../src/schemas/contact.js'
import { FriendshipAddOptions } from '../../../src/schemas/friendship.js'
import { MomentListOption, MomentPayload } from '../../../src/schemas/moment.js'

class PuppetTest extends Puppet {

Expand Down Expand Up @@ -59,6 +60,26 @@ class PuppetTest extends Puppet {
override async tagContactDelete (tagId: string) : Promise<void> { void { tagId } }
override async tagContactList (contactId?: string) : Promise<string[]> { return [contactId || ''] }

/**
*
* Moment
*
*/
override async momentSignature (signature?: string): Promise<boolean | string> { return { signature } as any }
override async momentCoverage (image: FileBox): Promise<boolean> { return { image } as any }
override async postTextMoment (content: string, visibleList?: string[]): Promise<string> { return { content, visibleList } as any }
override async postLinkMoment (urlLinkPayload: UrlLinkPayload, content?: string): Promise<string> { return { urlLinkPayload, content } as any }
override async postImageMoment (images: FileBox[], content?: string): Promise<string> { return { images, content } as any }

override async momentPayload (id: string): Promise<MomentPayload> { return { id } as any }

override async momentList (option?: MomentListOption): Promise<string[]> { return { option } as any }
override async revokeMoment (id: string): Promise<boolean> { return { id } as any }
override async likeMoment (id: string): Promise<boolean> { return { id } as any }
override async revokeLikeMoment (id: string): Promise<boolean> { return { id } as any }
override async commentMoment (id: string, comment: string, commentId?: string): Promise<string> { return { id, comment, commentId } as any }
override async revokeCommentMoment (commentId: string): Promise<boolean> { return { commentId } as any }

/**
*
* Contact
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 @@ -11,6 +11,8 @@ import {

FriendshipPayload,
MessagePayload,
MomentPayload,
MomentListOption,
ImageType,

Puppet,
Expand Down Expand Up @@ -54,6 +56,26 @@ class PuppetTest extends Puppet {
override async tagContactDelete (id: string) : Promise<void> { return void { id } }
override async tagContactList (contactId?: string) : Promise<string[]> { return [contactId || ''] }

/**
*
* Moment
*
*/
override async momentSignature (signature?: string): Promise<boolean | string> { return { signature } as any }
override async momentCoverage (image: FileBox): Promise<boolean> { return { image } as any }
override async postTextMoment (content: string, visibleList?: string[]): Promise<string> { return { content, visibleList } as any }
override async postLinkMoment (urlLinkPayload: UrlLinkPayload, content?: string): Promise<string> { return { urlLinkPayload, content } as any }
override async postImageMoment (images: FileBox[], content?: string): Promise<string> { return { images, content } as any }

override async momentPayload (id: string): Promise<MomentPayload> { return { id } as any }

override async momentList (option?: MomentListOption): Promise<string[]> { return { option } as any }
override async revokeMoment (id: string): Promise<boolean> { return { id } as any }
override async likeMoment (id: string): Promise<boolean> { return { id } as any }
override async revokeLikeMoment (id: string): Promise<boolean> { return { id } as any }
override async commentMoment (id: string, comment: string, commentId?: string): Promise<string> { return { id, comment, commentId } as any }
override async revokeCommentMoment (commentId: string): Promise<boolean> { return { commentId } as any }

/**
*
* Contact
Expand Down