Skip to content

Move isDuplicatedMessage from Event Handler Class to Saga #116

@huan

Description

@huan

I think the Event Handler Class will be instantiated from time to time when there's a new event, and will not keep/reuse the class instance for the next one.

So the isDuplicatedMessage will always forget the hash it calculated last time.

/**
* TODO: make sure it works as expected
* Huan(20220228)
*/
private async isDuplicatedMessage (message: WECHATY.Message): Promise<boolean> {
this.log.verbose('PuppetMessageReceivedHandler', 'isDuplicatedMessage(%s)', message.id)
const sayable = await WECHATY.helpers.messageToSayable(message)
if (typeof sayable === 'undefined') {
return false
}
const payload = await WECHATY.helpers.sayableToPayload(sayable)
if (typeof payload === 'undefined') {
return false
}
const hash = crypto.createHash('sha256').update(
JSON.stringify(payload),
).digest('hex')
if (this.lastMessageHash === hash) {
return true
}
this.lastMessageHash = hash
return false
}

Should move to Saga.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions