提交 43e0ca84 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

message type use raw number. typeEx() return string

上级 e27182b4
......@@ -7,12 +7,33 @@
*
*/
const log = require('./npmlog-env')
const co = require('co')
const Message = require('./message')
class ImageMessage extends Message {
constructor(rawObj) {
super(rawObj)
this.bridge = Message.puppet.bridge
}
ready() {
const parentReady = super.ready.bind(this)
return co.call(this, function* () {
yield parentReady()
const url = yield this.getMsgImg(this.id)
this.obj.url = url
})
.catch(e => {
log.warn('ImageMessage', 'ready() exception: %s', e.message)
throw e
})
}
getMsgImg(id) {
return this.bridge.getMsgImg(id)
.catch(e => {
log.warn('ImageMessage', 'getMsgImg(%d) exception: %s', id, e.message)
throw e
})
}
}
......
......@@ -83,8 +83,9 @@ class Message {
content() { return this.obj.content }
room() { return this.obj.room }
type() { return Message.Type[this.obj.type] }
count() { return Message.counter }
type() { return this.obj.type }
typeEx() { return Message.Type[this.obj.type] }
count() { return Message.counter }
self() {
if (!this.obj.self) {
......@@ -173,4 +174,6 @@ Object.keys(Message.Type).forEach(k => {
Message.Type[v] = k // Message.Type[1] = 'TEXT'
})
Message.attach = function(puppet) { Message.puppet = puppet }
module.exports = Message
......@@ -78,8 +78,20 @@ class Bridge {
throw e
})
}
getContact(id) {
getMsgImg(id) {
return this.proxyWechaty('getMsgImg', id)
.catch(e => {
log.silly('PuppetWebBridge', 'proxyWechaty(getMsgImg, %d) exception: %s', id, e.message)
throw e
})
}
getContact(id) {
if (id!==id) { // NaN
const err = new Error('NaN! where does it come from?')
log.error('PuppetWebBridge', 'getContact(NaN): %s', err)
return Promise.reject(err)
}
const max = 35
const backoff = 500
......@@ -184,6 +196,25 @@ Object.keys(ac).filter(function(k) { return /李/.test(ac[k].NickName) }).map(fu
Object.keys(window._chatContent).filter(function (k) { return window._chatContent[k].length > 0 }).map(function (k) { return window._chatContent[k].map(function (v) {return v.MMDigestTime}) })
.web_wechat_tab_add
.web_wechat_tab_launch-chat
*
.web_wechat_tab_launch-chat
contentChatController
e.getMsgImg = function(e, t, o) {
return o && "undefined" != typeof o.MMStatus && o.MMStatus != u.MSG_SEND_STATUS_SUCC ? void 0 : u.API_webwxgetmsgimg + "?&MsgID=" + e + "&skey=" + encodeURIComponent(c.getSkey()) + (t ? "&type=" + t : "")
}
,
e.getMsgVideo = function(e) {
return u.API_webwxgetvideo + "?msgid=" + e + "&skey=" + encodeURIComponent(c.getSkey())
}
<div class="picture"
ng-init="imageInit(message,message.MMPreviewSrc || message.MMThumbSrc || getMsgImg(message.MsgId,'slave'))">
<img class="msg-img" ng-style="message.MMImgStyle" ng-click="previewImg(message)"
ng-src="/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&amp;MsgID=6944236226252183282&amp;skey=%40crypt_c117402d_2b2a8c58340c8f4b0a4570cb8f11a1e8&amp;type=slave"
src="/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&amp;MsgID=6944236226252183282&amp;skey=%40crypt_c117402d_2b2a8c58340c8f4b0a4570cb8f11a1e8&amp;type=slave"
style="height: 100px; width: 75px;">
*
*/
......@@ -54,6 +54,7 @@ return (function(port) {
, getContact: getContact
, getUserName: getUserName
, getMsgImg: getMsgImg
}
window.Wechaty = Wechaty
......@@ -141,6 +142,17 @@ return (function(port) {
var appScope = angular.element('[ng-controller="appController"]').scope()
var loginScope = angular.element('[ng-controller="loginController"]').scope()
/**
* generate $scope with a contoller (as it is not assigned in html staticly)
* https://github.com/angular/angular.js/blob/a4e60cb6970d8b6fa9e0af4b9f881ee3ba7fdc99/test/ng/controllerSpec.js#L24
*/
var contentChatScope = rootScope.$new()
injector.get('$controller')('contentChatController', {$scope: contentChatScope })
/*
s =
*/
// get all we need from wx in browser(angularjs)
Wechaty.glue = {
injector: injector
......@@ -154,6 +166,8 @@ return (function(port) {
, rootScope: rootScope
, appScope: appScope
, loginScope: loginScope
, contentChatScope: contentChatScope
}
}
......@@ -277,17 +291,19 @@ return (function(port) {
clog('Wechaty.vars.socket not ready')
return setTimeout(emit, 1000) // resent eventsBuf after 1000ms
}
if (Wechaty.vars.eventsBuf.length) {
clog('Wechaty.vars.eventsBuf has ' + Wechaty.vars.eventsBuf.length + ' unsend events')
var bufLen = Wechaty.vars.eventsBuf.length
if (bufLen) {
if (bufLen > 1) { clog('Wechaty.vars.eventsBuf has ' + bufLen + ' unsend events') }
while (Wechaty.vars.eventsBuf.length) {
var eventData = Wechaty.vars.eventsBuf.pop()
if (eventData && eventData.map && eventData.length===2) {
clog('emiting ' + eventData[0])
Wechaty.vars.socket.emit(eventData[0], eventData[1])
} else {
log('Wechaty.emit() got invalid eventData: ' + eventData[0] + ', ' + eventData[1] + ', length: ' + eventData.length)
}
} else { clog('Wechaty.emit() got invalid eventData: ' + eventData[0] + ', ' + eventData[1] + ', length: ' + eventData.length) }
}
clog('Wechaty.vars.eventsBuf all sent')
if (bufLen > 1) { clog('Wechaty.vars.eventsBuf all sent') }
}
}
......@@ -334,4 +350,9 @@ return (function(port) {
i.parentNode.removeChild(i)
}
function getMsgImg(id) {
var location = window.location.href.replace(/\/$/, '')
var path = Wechaty.glue.contentChatScope.getMsgImg(id)
return location + path
}
}.apply(window, arguments))
......@@ -23,10 +23,12 @@ const co = require('co')
const log = require('./npmlog-env')
const Puppet = require('./puppet')
const Message = require('./message')
const Contact = require('./contact')
const Room = require('./room')
const Message = require('./message')
const ImageMessage = require('./message-image')
const Server = require('./puppet-web-server')
const Browser = require('./puppet-web-browser')
const Bridge = require('./puppet-web-bridge')
......@@ -110,6 +112,7 @@ class PuppetWeb extends Puppet {
log.verbose('PuppetWeb', 'initAttach()')
Contact.attach(puppet)
Room.attach(puppet)
Message.attach(puppet)
return Promise.resolve(!!puppet)
}
initBrowser() {
......@@ -389,7 +392,21 @@ class PuppetWeb extends Puppet {
}
}
onServerMessage(data) {
const m = new Message(data)
let m
log.warn('PuppetWeb', 'MsgType: %s', data.MsgType)
switch (data.MsgType) {
case Message.Type.IMAGE:
log.warn('PuppetWeb', 'onServerMessage() IMAGE message found!')
m = new ImageMessage(data)
log.warn('PuppetWeb', 'onServerMessage() IMAGE url: %s', m.get('url'))
break;
default:
case 'TEXT':
m = new Message(data)
break;
}
if (this.user) {
m.set('self', this.user.id)
} else {
......@@ -399,6 +416,10 @@ class PuppetWeb extends Puppet {
.then(() => this.emit('message', m))
.catch(e => {
log.error('PuppetWeb', 'onServerMessage() message ready exception: %s', e)
/**
* FIXME: add retry here...
* setTimeout(onServerMessage.bind(this, data, ++attempt), 1000)
*/
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册