Skip to content

Commit

Permalink
fix(wechaty-bro): resolved emit RECALLED type msg (fix #8) (#744)
Browse files Browse the repository at this point in the history
* 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 huan committed Sep 3, 2017
1 parent 4ab4f02 commit 174b677
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/message.ts
Expand Up @@ -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}
*/
Expand Down
31 changes: 31 additions & 0 deletions src/puppet-web/wechaty-bro.js
Expand Up @@ -76,6 +76,7 @@
glueToAngular()
connectSocket()
hookEvents()
hookRecalledMsgProcess()

checkScan()

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -276,6 +278,7 @@
, contactFactory: contactFactory
, emojiFactory: emojiFactory
, loginFactory: loginFactory
, utilFactory: utilFactory

, rootScope: rootScope
, appScope: appScope
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 174b677

Please sign in to comment.