From f6cd406c279b1ec1321761d33b05bd51bf09b656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Huan=20LI=20=28=E6=9D=8E=E5=8D=93=E6=A1=93=29?= Date: Wed, 19 Aug 2020 17:40:51 +0800 Subject: [PATCH] TODO: implement the dirty logic (https://github.com/wechaty/wechaty-puppet-hostie/issues/43) --- src/wechaty.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/wechaty.ts b/src/wechaty.ts index f88e08a7..4187b7fd 100644 --- a/src/wechaty.ts +++ b/src/wechaty.ts @@ -588,7 +588,37 @@ export class Wechaty extends WechatyEventEmitter implements Sayable { /** * TODO: Huan(202008) do we need to deal with the `dirty` event in Wechaty? * clean all the pools for Contact, Room, Message, etc. + * + * CAUTION: should update it smoothly instead of just delete the cache! + * there's lots of race conditions, like: + * 1. ... to be collected */ + puppet.on('dirty', async ({ payloadType, payloadId }) => { + switch (payloadType) { + case PayloadType.RoomMember: + case PayloadType.Contact: + await this.Contact.load(payloadId).ready(true) + break + case PayloadType.Room: + await this.Room.load(payloadId).ready(true) + break + + /** + * Huan(202008): noop for the following + */ + case PayloadType.Friendship: + // Friendship has no payload + // await this.Friendship.load(payloadId) + break + case PayloadType.Message: + // Message does not need to dirty (?) + break + + case PayloadType.Unknown: + default: + throw new Error('unknown payload type: ' + payloadType) + } + }) break default: -- GitLab