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

Fix dirty room member #11

Merged
merged 3 commits into from
Jul 13, 2022
Merged
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": "@juzi/wechaty",
"version": "1.0.15",
"version": "1.0.16",
"description": "Wechaty is a RPA SDK for Chatbot Makers.",
"type": "module",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion src/user-modules/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ContactMixin extends MixinBase implements SayableSayer {
/**
* we need to use concurrencyExecuter to reduce the parallel number of the requests
*/
const CONCURRENCY = 10
const CONCURRENCY = 17
const contactIterator = concurrencyExecuter(CONCURRENCY)(idToContact)(contactIdList)

const contactList: ContactInterface[] = []
Expand Down
2 changes: 1 addition & 1 deletion src/user-modules/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class PostMixin extends wechatifyMixinBase() {
/**
* we need to use concurrencyExecuter to reduce the parallel number of the requests
*/
const CONCURRENCY = 10
const CONCURRENCY = 17
const postIterator = concurrencyExecuter(CONCURRENCY)(idToPost)(postIdList)

const postList: PostInterface[] = []
Expand Down
20 changes: 3 additions & 17 deletions src/user-modules/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ const MixinBase = wechatifyMixin(
)<RoomImplInterface>(),
)

const ROOM_MEMBER_DIRTY_THROTTLE = 30 * 60 * 1000

/**
* All WeChat rooms(groups) will be encapsulated as a Room.
*
Expand Down Expand Up @@ -158,7 +156,7 @@ class RoomMixin extends MixinBase implements SayableSayer {
/**
* we need to use concurrencyExecuter to reduce the parallel number of the requests
*/
const CONCURRENCY = 10
const CONCURRENCY = 17
const roomIterator = concurrencyExecuter(CONCURRENCY)(idToRoom)(roomIdList)

const roomList: RoomInterface[] = []
Expand Down Expand Up @@ -302,15 +300,10 @@ class RoomMixin extends MixinBase implements SayableSayer {
*/
async sync (): Promise<void> {
await this.wechaty.puppet.roomPayloadDirty(this.id)
// await this.wechaty.puppet.roomMemberPayloadDirty(this.id)
await this.wechaty.puppet.roomMemberPayloadDirty(this.id)
await this.ready(true)
}

/**
* record the last time of roomMemberDirty to prevent abundant dirty calls
*/

private lastMemberDirtyTimestamp?: number
/**
* Warning: `ready()` is for the framework internally use ONLY!
*
Expand All @@ -335,15 +328,8 @@ class RoomMixin extends MixinBase implements SayableSayer {
*/
const memberIdList = await this.wechaty.puppet.roomMemberList(this.id)

const roomMemberJustSynced = !this.lastMemberDirtyTimestamp || Date.now() - this.lastMemberDirtyTimestamp > ROOM_MEMBER_DIRTY_THROTTLE
if (!roomMemberJustSynced) {
this.lastMemberDirtyTimestamp = Date.now()
}
const doReady = async (id: string): Promise<void> => {
try {
if (roomMemberJustSynced) {
await this.wechaty.puppet.roomMemberPayloadDirty(id)
}
await this.wechaty.Contact.find({ id })
} catch (e) {
this.wechaty.emitError(e)
Expand All @@ -353,7 +339,7 @@ class RoomMixin extends MixinBase implements SayableSayer {
/**
* we need to use concurrencyExecuter to reduce the parallel number of the requests
*/
const CONCURRENCY = 10
const CONCURRENCY = 17
const contactIterator = concurrencyExecuter(CONCURRENCY)(doReady)(memberIdList)

for await (const contact of contactIterator) {
Expand Down
8 changes: 6 additions & 2 deletions src/wechaty-mixins/puppet-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
// issue #254
if (payload.removeeIdList.includes(puppet.currentUserId)) {
await puppet.roomPayloadDirty(payload.roomId)
// await puppet.roomMemberPayloadDirty(payload.roomId)
await puppet.roomMemberPayloadDirty(payload.roomId)
}
} catch (e) {
this.emit('error', GError.from(e))
Expand Down Expand Up @@ -436,7 +436,6 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
puppet.on('dirty', async ({ payloadType, payloadId }) => {
try {
switch (payloadType) {
case PUPPET.types.Payload.RoomMember:
case PUPPET.types.Payload.Contact: {
const contact = await this.Contact.find({ id: payloadId }) as unknown as undefined | ContactImpl
await contact?.ready(true)
Expand All @@ -447,6 +446,11 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
await room?.ready(true)
break
}
case PUPPET.types.Payload.RoomMember: {
const room = await this.Room.find({ id: payloadId }) as unknown as undefined | RoomImpl
await room?.ready()
break
}

/**
* Huan(202008): noop for the following
Expand Down