Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
1674ba51
W
wechaty
项目概览
.www.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1674ba51
编写于
5月 21, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
half work to enhance message processing...
上级
54770643
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
14 deletion
+24
-14
src/message.js
src/message.js
+5
-6
src/puppet-web.js
src/puppet-web.js
+19
-8
未找到文件。
src/message.js
浏览文件 @
1674ba51
...
...
@@ -30,17 +30,16 @@ class Message {
,
content
:
rawObj
.
MMActualContent
// Content has @id prefix added by wx
,
status
:
rawObj
.
Status
,
digest
:
rawObj
.
MMDigest
,
date
:
new
Date
(
rawObj
.
MMDisplayTime
*
1000
)
,
date
:
new
Date
(
rawObj
.
MMDisplayTime
*
1000
)
,
fromContact
:
Contact
.
load
(
rawObj
.
MMActualSender
)
,
toContact
:
Contact
.
load
(
rawObj
.
ToUserName
)
,
inGroup
:
rawObj
.
MMIsChatRoom
?
Group
.
load
(
rawObj
.
FromUserName
)
:
null
,
fromGroup
:
rawObj
.
MMIsChatRoom
?
Group
.
load
(
rawObj
.
FromUserName
)
:
null
}
}
toString
()
{
const
name
=
html2str
(
this
.
obj
.
from
.
get
(
'
name
'
))
const
group
=
this
.
obj
.
in
Group
const
group
=
this
.
obj
.
from
Group
let
content
=
html2str
(
this
.
obj
.
content
)
if
(
content
.
length
>
20
)
content
=
content
.
substring
(
0
,
17
)
+
'
...
'
;
let
groupStr
=
group
?
html2str
(
group
)
:
''
...
...
@@ -62,7 +61,7 @@ class Message {
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
obj
.
fromContact
.
ready
()
// Contact from
.
then
(
r
=>
this
.
obj
.
toContact
.
ready
())
// Contact to
.
then
(
r
=>
this
.
obj
.
inGroup
&&
this
.
obj
.
in
Group
.
ready
())
// Group member list
.
then
(
r
=>
this
.
obj
.
fromGroup
&&
this
.
obj
.
from
Group
.
ready
())
// Group member list
.
then
(
r
=>
resolve
(
this
))
// RESOLVE
.
catch
(
e
=>
{
// REJECT
log
.
error
(
'
Message
'
,
'
ready() rejected:
'
+
e
)
...
...
@@ -71,7 +70,7 @@ class Message {
})
}
inGroup
()
{
return
!!
(
this
.
obj
.
g
roup
)
}
fromGroup
()
{
return
!!
(
this
.
obj
.
fromG
roup
)
}
get
(
prop
)
{
if
(
!
prop
||
!
(
prop
in
this
.
obj
))
{
...
...
src/puppet-web.js
浏览文件 @
1674ba51
...
...
@@ -29,14 +29,19 @@ class PuppetWeb extends Puppet {
options
=
options
||
{}
this
.
port
=
options
.
port
||
8788
// W(87) X(88), ascii char code ;-]
this
.
head
=
options
.
head
this
.
logined
=
false
this
.
user
=
null
}
toString
()
{
return
`Class PuppetWeb({browser:
${
this
.
browser
}
,port:
${
this
.
port
}
})`
}
init
()
{
this
.
logined
=
false
this
.
on
(
'
login
'
,
()
=>
this
.
logined
=
true
)
this
.
on
(
'
logout
'
,
()
=>
this
.
logined
=
false
)
this
.
on
(
'
login
'
,
e
=>
{
this
.
logined
=
true
// TODO: save currentUser to this.user as a Contact
})
this
.
on
(
'
logout
'
,
e
=>
this
.
logined
=
false
)
this
.
userId
=
null
...
...
@@ -55,7 +60,7 @@ class PuppetWeb extends Puppet {
].
map
(
event
=>
this
.
server
.
on
(
event
,
data
=>
this
.
emit
(
event
,
data
))
)
this
.
server
.
on
(
'
message
'
,
data
=>
this
.
forward
Message
(
data
))
this
.
server
.
on
(
'
message
'
,
data
=>
this
.
recv
Message
(
data
))
/**
* `unload` event is sent from js@browser to webserver via socketio
* after received `unload`, we re-inject the Wechaty js code into browser.
...
...
@@ -81,10 +86,16 @@ class PuppetWeb extends Puppet {
return
this
.
browser
.
init
()
}
forward
Message
(
data
)
{
recv
Message
(
data
)
{
const
m
=
new
Message
(
data
)
if
(
!
this
.
user
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
recvMessage() without this.user
'
)
return
}
const
fromId
=
m
.
get
(
'
from
'
)
if
(
this
.
userId
)
if
(
fromId
==
this
.
user
.
id
)
{
return
}
this
.
emit
(
'
message
'
,
m
)
}
send
(
message
)
{
...
...
@@ -146,9 +157,9 @@ class PuppetWeb extends Puppet {
* Public Methods
*
*/
getLoginQrImgUrl
()
{
getLoginQrImgUrl
()
{
log
.
silly
(
'
PuppetWeb
'
,
'
getLoginQrImgUrl()
'
)
return
this
.
proxyWechaty
(
'
getLoginQrImgUrl
'
)
return
this
.
proxyWechaty
(
'
getLoginQrImgUrl
'
)
}
getLoginStatusCode
()
{
return
this
.
proxyWechaty
(
'
getLoginStatusCode
'
)
}
getContact
(
id
)
{
return
this
.
proxyWechaty
(
'
getContact
'
,
id
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录