Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
a9a9b193
W
wechaty
项目概览
.Veneno.
/
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,发现更多精彩内容 >>
提交
a9a9b193
编写于
10月 05, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#32 Room Event: `join` & `leave`
上级
edce2e10
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
108 addition
and
34 deletion
+108
-34
src/puppet-web/event.js
src/puppet-web/event.js
+108
-34
未找到文件。
src/puppet-web/event.js
浏览文件 @
a9a9b193
...
...
@@ -332,50 +332,35 @@ function onServerLogout(data) {
}
function
onServerMessage
(
data
)
{
let
m
// log.warn('PuppetWebEvent', 'MsgType: %s', data.MsgType)
switch
(
data
.
MsgType
)
{
/**
* Message.Type.VERIFYMSG: Received Friend Request
*/
case
Message
.
Type
.
VERIFYMSG
:
log
.
silly
(
'
PuppetWebEvent
'
,
'
onServerMessage() received VERIFYMSG
'
)
m
=
new
Message
(
data
)
let
m
=
new
Message
(
data
)
const
request
=
new
FriendRequest
()
request
.
receive
(
data
.
RecommendInfo
)
const
contact
=
Contact
.
load
(
request
.
contactId
)
this
.
emit
(
'
friend
'
,
contact
,
request
)
/**
* Fire Events if match message type & content
*/
switch
(
m
.
type
())
{
// data.MsgType
case
Message
.
Type
.
VERIFYMSG
:
fireFriendRequest
(
m
)
break
case
Message
.
Type
.
SYS
:
log
.
silly
(
'
PuppetWebEvent
'
,
'
onServerMessage() received SYSMSG
'
)
m
=
new
Message
(
data
)
/**
* try to find FriendRequest Confirmation Message
*/
if
(
/^You have added
(
.+
)
as your WeChat contact. Start chatting!$/
.
test
(
m
.
get
(
'
content
'
)))
{
const
request
=
new
FriendRequest
()
const
contact
=
Contact
.
load
(
m
.
get
(
'
from
'
))
request
.
confirm
(
contact
)
this
.
emit
(
'
friend
'
,
contact
)
if
(
m
.
room
())
{
fireRoomJoin
(
m
)
fireRoomLeave
(
m
)
}
else
{
fireFriendConfirm
(
m
.
content
())
}
break
}
/**
* Check Type for special Message
* reload if needed
*/
switch
(
m
.
type
())
{
case
Message
.
Type
.
IMAGE
:
// log.verbose('PuppetWebEvent', 'onServerMessage() IMAGE message')
m
=
new
MediaMessage
(
data
)
break
case
'
TEXT
'
:
default
:
m
=
new
Message
(
data
)
break
}
// To Be Deleted: set self...
...
...
@@ -386,7 +371,7 @@ function onServerMessage(data) {
}
m
.
ready
()
// TODO: EventEmitter2 for video/audio/app/sys....
.
then
(
()
=>
this
.
emit
(
'
message
'
,
m
))
.
then
(
_
=>
this
.
emit
(
'
message
'
,
m
))
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebEvent
'
,
'
onServerMessage() message ready exception: %s
'
,
e
)
// console.log(e)
...
...
@@ -397,4 +382,93 @@ function onServerMessage(data) {
})
}
function
fireFriendRequest
(
m
)
{
const
info
=
m
.
rawObj
.
RecommendInfo
log
.
verbose
(
'
PuppetWebEvent
'
,
'
fireFriendRequest(%s)
'
,
info
)
const
request
=
new
FriendRequest
()
request
.
receive
(
info
)
this
.
emit
(
'
friend
'
,
request
.
contact
,
request
)
}
function
fireFriendConfirm
(
m
)
{
const
content
=
m
.
content
()
log
.
silly
(
'
PuppetWebEvent
'
,
'
fireFriendConfirm(%s)
'
,
content
)
/**
* try to find FriendRequest Confirmation Message
*/
if
(
!
/^You have added
(
.+
)
as your WeChat contact. Start chatting!$/
.
test
(
content
))
{
return
}
const
request
=
new
FriendRequest
()
const
contact
=
Contact
.
load
(
m
.
get
(
'
from
'
))
request
.
confirm
(
contact
)
this
.
emit
(
'
friend
'
,
contact
)
}
/**
* try to find 'join' event for Room
*
1.
You've invited "李卓桓" to the group chat
You've invited "李卓桓.PreAngel、Bruce LEE" to the group chat
2.
"李卓桓.PreAngel" invited "Bruce LEE" to the group chat
*/
function
fireRoomJoin
(
m
)
{
const
room
=
m
.
room
()
const
content
=
m
.
content
()
const
inviteRe
=
/^
(
.+
)
invited "
(
.+
)
" to the group chat$/
const
found
=
content
.
match
(
inviteRe
)
if
(
!
found
)
{
return
}
const
[
_
,
inviter
,
invitee
]
=
found
let
inviterContact
,
inviteeContact
if
(
inviter
===
"
You've
"
)
{
inviterContact
=
Contact
.
load
(
this
.
userId
)
}
else
{
inviterContact
=
m
.
member
(
inviter
)
}
inviteeContact
=
m
.
room
().
member
(
invitee
)
if
(
!
inviterContact
||
!
inviteeContact
)
{
log
.
error
(
'
PuppetWebEvent
'
,
'
inivter or invitee not found for %s, %s
'
,
inviter
,
invitee
)
return
}
room
.
emit
(
'
join
'
,
inviteeContact
,
inviterContact
)
}
/**
* You removed "Bruce LEE" from the group chat
*/
function
fireRoomLeave
(
m
)
{
const
room
=
m
.
room
()
const
content
=
m
.
content
()
const
removeRe
=
/^You removed "
(
.+
)
" from the group chat$/
const
found
=
content
.
match
(
removeRe
)
if
(
!
found
)
{
return
}
let
[
_
,
leaver
]
=
found
leaverContact
=
m
.
room
().
member
(
leaver
)
if
(
!
leaverContact
)
{
log
.
err
(
'
PuppetWebEvent
'
,
'
leaver not found for %s
'
,
leaver
)
return
}
room
.
emit
(
'
leave
'
,
leaverContact
)
}
module
.
exports
=
PuppetWebEvent
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录