From 174b6775c4e9242e5f003094b2f9e10953c978f2 Mon Sep 17 00:00:00 2001 From: binsee Date: Sun, 3 Sep 2017 16:55:35 +0800 Subject: [PATCH] fix(wechaty-bro): resolved emit RECALLED type msg (fix #8) (#744) * fix(wechaty-bro): resolved emit RECALLED type msg fix #8 * add(message): add getRevokeId(), Return the recalled message id * fix(wechaty-bro): modify `hookProcess` to `hookRecalledProcess` modify `_this` to `chatFactory` * fix(wechaty-bro): Remain a blank message after repairing the recall message * fix(wechaty-bro): Unify the data returned by the RECALLED type message remove Message.getRevokeId function --- src/message.ts | 1 + src/puppet-web/wechaty-bro.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/message.ts b/src/message.ts index c14bd0862..7b3a8687f 100644 --- a/src/message.ts +++ b/src/message.ts @@ -564,6 +564,7 @@ export class Message implements Sayable { /** * Get the type from the message. * + * If type is equal to `MsgType.RECALLED`, {@link Message#id} is the msgId of the recalled message. * @see {@link MsgType} * @returns {MsgType} */ diff --git a/src/puppet-web/wechaty-bro.js b/src/puppet-web/wechaty-bro.js index 4e30064ff..bb46ec4f2 100644 --- a/src/puppet-web/wechaty-bro.js +++ b/src/puppet-web/wechaty-bro.js @@ -76,6 +76,7 @@ glueToAngular() connectSocket() hookEvents() + hookRecalledMsgProcess() checkScan() @@ -223,6 +224,7 @@ var confFactory = injector.get('confFactory') var emojiFactory = injector.get('emojiFactory') var loginFactory = injector.get('loginFactory') + var utilFactory = injector.get('utilFactory') var http = injector.get('$http') var state = injector.get('$state') @@ -276,6 +278,7 @@ , contactFactory: contactFactory , emojiFactory: emojiFactory , loginFactory: loginFactory + , utilFactory: utilFactory , rootScope: rootScope , appScope: appScope @@ -386,6 +389,34 @@ }) return true } + + function hookRecalledMsgProcess() { + var chatFactory = WechatyBro.glue.chatFactory + var utilFactory = WechatyBro.glue.utilFactory + var confFactory = WechatyBro.glue.confFactory + // hook chatFactory._recalledMsgProcess, resolve emit RECALLED type msg + chatFactory.__recalledMsgProcess = chatFactory._recalledMsgProcess + chatFactory._recalledMsgProcess = function(msg) { + chatFactory.__recalledMsgProcess(msg) + var m = Object.assign({},msg) + var content = utilFactory.htmlDecode(m.MMActualContent) + content = utilFactory.encodeEmoji(content) + var revokemsg = utilFactory.xml2json(content).revokemsg + if (revokemsg.msgid) { + var chatMsgs = chatFactory.getChatMessage(m.MMPeerUserName) + var i = chatFactory._findMessageByMsgId(chatMsgs, revokemsg.msgid) + if (i > -1) { + m = chatMsgs[i] + m.MsgType = confFactory.MSGTYPE_RECALLED + } else { + m.MsgId = revokemsg.msgid + m.MMActualContent = m.Content = revokemsg.replacemsg.replace(/"/g,"") + } + WechatyBro.emit('message', m) + } + } + } + function connectSocket() { log('connectSocket()') /*global socket*/ // WechatyBro global variable: socket