From 1a50c8cc2c46f8a8db94562c6841af0349d2b6f0 Mon Sep 17 00:00:00 2001 From: SuperChang Date: Fri, 15 Dec 2023 13:58:54 +0800 Subject: [PATCH] fix: :bug: revert dirty event in client (#68) * fix: :bug: revert dirty event in client * 1.0.88 --- package.json | 4 +++- src/client/puppet-service.ts | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index aa57f9e4..d57f4b45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@juzi/wechaty-puppet-service", - "version": "1.0.87", + "version": "1.0.88", "description": "Puppet Service for Wechaty", "type": "module", "exports": { @@ -54,6 +54,8 @@ "@juzi/wechaty-puppet": "^1.0.74", "@juzi/wechaty-puppet-mock": "^1.0.1", "@swc/core": "1.3.39", + "ts-node": "10.9.1", + "typescript": "4.9.5", "@types/google-protobuf": "^3.15.5", "@types/lru-cache": "^7.5.0", "@types/semver": "^7.3.9", diff --git a/src/client/puppet-service.ts b/src/client/puppet-service.ts index d8ee4b24..e5a4d586 100644 --- a/src/client/puppet-service.ts +++ b/src/client/puppet-service.ts @@ -324,7 +324,6 @@ class PuppetService extends PUPPET.Puppet { } break case grpcPuppet.EventType.EVENT_TYPE_DIRTY: - await this.fastDirty(JSON.parse(payload)) this.emit('dirty', JSON.parse(payload) as PUPPET.payloads.EventDirty) break case grpcPuppet.EventType.EVENT_TYPE_MESSAGE: @@ -449,13 +448,13 @@ class PuppetService extends PUPPET.Puppet { * `onDirty()` is called when the puppet emit `dirty` event. * the event listener will be registered in `start()` from the `PuppetAbstract` class */ - async fastDirty ( + override onDirty ( { payloadType, payloadId, }: PUPPET.payloads.EventDirty, - ): Promise { - log.verbose('PuppetService', 'fastDirty(%s<%s>, %s)', PUPPET.types.Dirty[payloadType], payloadType, payloadId) + ): void { + log.verbose('PuppetService', 'onDirty(%s<%s>, %s)', PUPPET.types.Dirty[payloadType], payloadType, payloadId) const dirtyMap = { [PUPPET.types.Dirty.Contact]: async (id: string) => this._payloadStore.contact?.delete(id), @@ -469,11 +468,13 @@ class PuppetService extends PUPPET.Puppet { [PUPPET.types.Dirty.Unspecified]: async (id: string) => { throw new Error('Unspecified type with id: ' + id) }, } - try { - await dirtyMap[payloadType](payloadId) - } catch (error) { - this.emit('error', error) - } + const dirtyFuncSync = this.wrapAsync(dirtyMap[payloadType]) + dirtyFuncSync(payloadId) + + /** + * We need to call `super.onDirty()` to clean the `PuppetAbstract` LRUCache + */ + super.onDirty({ payloadId, payloadType }) } override async enterVerifyCode (id: string, code: string): Promise {