Skip to content

Commit

Permalink
fix: 🐛 revert dirty event in client (#68)
Browse files Browse the repository at this point in the history
* fix: 🐛 revert dirty event in client

* 1.0.88
  • Loading branch information
su-chang authored Dec 15, 2023
1 parent e94d850 commit 1a50c8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 10 additions & 9 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<void> {
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),
Expand All @@ -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<void> {
Expand Down

0 comments on commit 1a50c8c

Please sign in to comment.