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: friendship source #2120

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/user/friendship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
FriendshipPayload,
FriendshipType,
FriendshipSearchQueryFilter,
} from 'wechaty-puppet'
FriendshipSource, FriendshipPayloadReceive,
} from 'wechaty-puppet'

import {
Acceptable,
Expand Down Expand Up @@ -348,6 +349,25 @@ class Friendship extends EventEmitter implements Acceptable {
: FriendshipType.Unknown
}

/**
* Return FriendshipSource in FriendshipPayloadReceive
* Issue #2120: https://github.com/wechaty/wechaty/pull/2120
* Ref Issue #1801: https://github.com/wechaty/wechaty/issues/1801
* @author https://github.com/suhli
* @returns {FriendshipSource}
* @example
* const bot = new Wechaty()
* bot.on('friendship', async friendship => {
* if (friendship.type() === Friendship.Type.Receive) {
* console.log(JSON.stringify(friendship.source(),null,2))
* }
* }
* .start()
**/
public source (): FriendshipSource | null {
Copy link
Member

Choose a reason for hiding this comment

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

This new API name looks good.

Can we also think about this API a little bit future: what if we are using a Whatsapp puppet, or a WXWork/DingTalk/Lark puppet?

Does the FriendSource return type can also fulfill those IM platform requirements?

Copy link
Author

Choose a reason for hiding this comment

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

ok i know your means

return (this.payload as FriendshipPayloadReceive).source || null
}

/**
* get friendShipPayload Json
* @returns {FriendshipPayload}
Expand Down