UNPKG

@juzi/wechaty-puppet-whatsapp

Version:
46 lines 2.09 kB
/* eslint-disable no-case-declarations */ import WhatsAppBase from '../whatsapp-base.js'; import * as PUPPET from '@juzi/wechaty-puppet'; import { log } from '../../config.js'; import { v4 } from 'uuid'; const PRE = 'ContactEventHandler'; export default class ContactEventHandler extends WhatsAppBase { async onContactNameChange(contact, newName, oldName) { log.info(PRE, `onContactNameChange(${contact.id._serialized}, ${newName}, ${oldName})`); const type = contact.isGroup ? PUPPET.types.Dirty.Room : PUPPET.types.Dirty.Contact; await (await this.manager.getCacheManager()).deleteContactOrRoom(contact.id._serialized); this.emit('dirty', { payloadType: type, payloadId: contact.id._serialized, }); } async onContactAdd(contact) { log.info(PRE, `onContactAdd(${contact.id._serialized})`); const friendship = { contactId: contact.id._serialized, hello: '', id: v4(), timestamp: Date.now(), type: PUPPET.types.Friendship.Confirm, }; const cacheManager = await this.manager.getCacheManager(); await cacheManager.setFriendshipRawPayload(friendship.id, friendship); await cacheManager.deleteContactOrRoom(contact.id._serialized); this.emit('friendship', { friendshipId: friendship.id }); } async onContactRemove(contact) { log.info(PRE, `onContactRemove(${contact.id._serialized})`); // const friendship: PUPPET.payloads.Friendship = { // contactId: contact.id._serialized, // hello: '', // id: v4(), // timestamp: Date.now(), // type: PUPPET.types.Friendship.Delete, // } // const cacheManager = await this.manager.getCacheManager() // await cacheManager.setFriendshipRawPayload(friendship.id, friendship) // await cacheManager.deleteContactOrRoom(contact.id._serialized) // this.emit('friendship', { friendshipId: friendship.id }) } } //# sourceMappingURL=contact-event-handler.js.map