Permalink
Browse files

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
  • Loading branch information...
binsee authored and zixia committed Sep 3, 2017
1 parent 4ab4f02 commit 174b6775c4e9242e5f003094b2f9e10953c978f2
Showing with 32 additions and 0 deletions.
  1. +1 −0 src/message.ts
  2. +31 −0 src/puppet-web/wechaty-bro.js
View
@@ -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}
*/
@@ -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

0 comments on commit 174b677

Please sign in to comment.