Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
dabea3d9
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,发现更多精彩内容 >>
提交
dabea3d9
编写于
10月 07, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support to monitor multiple people added to room, and fire "join" event right
上级
b3145417
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
21 deletion
+50
-21
src/puppet-web/firer.js
src/puppet-web/firer.js
+40
-16
src/puppet-web/firer.spec.js
src/puppet-web/firer.spec.js
+10
-5
未找到文件。
src/puppet-web/firer.js
浏览文件 @
dabea3d9
...
...
@@ -98,19 +98,28 @@ function fireFriendConfirm(m) {
You've invited "李卓桓.PreAngel、Bruce LEE" to the group chat
2.
"李卓桓.PreAngel" invited "Bruce LEE" to the group chat
"凌" invited "庆次、小桔妹" to the group chat
*/
function
checkRoomJoin
(
content
)
{
log
.
verbose
(
'
PuppetWebFirer
'
,
'
checkRoomJoin()
'
)
const
re
=
regexConfig
.
roomJoin
const
found
=
content
.
match
(
re
)
if
(
!
found
)
{
return
false
}
const
[
_
,
inviter
,
invitee
]
=
found
return
[
invitee
,
inviter
]
// put invitee at first place
const
[
_
,
inviter
,
inviteeStr
]
=
found
// "凌" invited "庆次、小桔妹" to the group chat
const
inviteeList
=
inviteeStr
.
split
(
/、/
)
return
[
inviteeList
,
inviter
]
// put invitee at first place
}
function
fireRoomJoin
(
m
)
{
log
.
verbose
(
'
PuppetWebFirer
'
,
'
fireRoomJoin()
'
)
const
room
=
m
.
room
()
const
content
=
m
.
content
()
...
...
@@ -118,9 +127,9 @@ function fireRoomJoin(m) {
if
(
!
result
)
{
return
}
const
[
invitee
,
inviter
]
=
result
const
[
invitee
List
,
inviter
]
=
result
let
inviterContact
,
inviteeContact
let
inviterContact
,
inviteeContact
List
=
[]
co
.
call
(
this
,
function
*
()
{
if
(
inviter
===
"
You've
"
)
{
...
...
@@ -139,19 +148,32 @@ function fireRoomJoin(m) {
return
room
.
refresh
()
.
then
(
_
=>
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
inviteeContact: %s, invitorContact: %s
'
,
inviteeContact
,
inviterContact
)
log
.
silly
(
'
PuppetWebFirer
'
,
'
inviteeList: %s, inviter: %s
'
,
inviteeList
.
join
(
'
,
'
)
,
inviter
)
let
iDone
,
allDone
=
true
for
(
let
i
in
inviteeList
)
{
iDone
=
inviteeContactList
[
i
]
instanceof
Contact
if
(
!
iDone
)
{
inviteeContactList
[
i
]
=
room
.
member
(
inviteeList
[
i
])
||
(
allDone
=
false
)
}
}
inviteeContact
||
(
inviteeContact
=
room
.
member
(
invitee
))
inviterContact
||
(
inviterContact
=
room
.
member
(
inviter
))
if
(
inviteeContact
&&
inviterContact
)
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomJoin() resolve() inviteeContact: %s, invitorContact: %s
'
,
inviteeContact
if
(
allDone
&&
inviterContact
)
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomJoin() resolve() inviteeContactList: %s, inviterContact: %s
'
,
inviteeContactList
.
join
(
'
,
'
)
,
inviterContact
)
return
Promise
.
resolve
()
}
else
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomJoin() reject() inviteeContact
: %s, invito
rContact: %s
'
,
inviteeContact
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomJoin() reject() inviteeContact
List: %s, invite
rContact: %s
'
,
inviteeContact
List
.
join
(
'
,
'
)
,
inviterContact
)
return
Promise
.
reject
()
...
...
@@ -168,14 +190,16 @@ function fireRoomJoin(m) {
log
.
error
(
'
PuppetWebFirer
'
,
'
firmRoomJoin() inivter not found for %s
'
,
inviter
)
return
}
if
(
!
inviteeContact
)
{
log
.
error
(
'
PuppetWebFirer
'
,
'
firmRoomJoin() invitee
not found for %s
'
,
invitee
)
if
(
!
inviteeContact
List
.
every
(
c
=>
c
instanceof
Contact
)
)
{
log
.
error
(
'
PuppetWebFirer
'
,
'
firmRoomJoin() invitee
List not all found for %s
'
,
inviteeList
.
join
(
'
,
'
)
)
return
}
yield
inviteeContact
.
ready
(
)
yield
Promise
.
all
(
inviteeContactList
.
map
(
c
=>
c
.
ready
())
)
yield
inviterContact
.
ready
()
this
.
emit
(
'
room-join
'
,
room
,
inviteeContact
,
inviterContact
)
room
.
emit
(
'
join
'
,
inviteeContact
,
inviterContact
)
inviteeContactList
.
forEach
(
c
=>
{
this
.
emit
(
'
room-join
'
,
room
,
c
,
inviterContact
)
room
.
emit
(
'
join
'
,
c
,
inviterContact
)
})
}).
catch
(
e
=>
{
log
.
error
(
'
PuppetWebFirer
'
,
'
retryPromise() rejected: %s
'
,
e
.
stack
)
...
...
src/puppet-web/firer.spec.js
浏览文件 @
dabea3d9
...
...
@@ -39,25 +39,30 @@ test('Firer.checkRoomJoin', t => {
[
`You've invited "李卓桓" to the group chat`
,
`You've`
,
`李卓桓`
,
[
`李卓桓`
]
]
,
[
`You've invited "李卓桓.PreAngel、Bruce LEE" to the group chat`
,
`You've`
,
`李卓桓.PreAngel、Bruce LEE`
,
[
`李卓桓.PreAngel`
,
`Bruce LEE`
]
]
,
[
`"李卓桓.PreAngel" invited "Bruce LEE" to the group chat`
,
`李卓桓.PreAngel`
,
`Bruce LEE`
,
[
`Bruce LEE`
]
]
,
[
`"凌" invited "庆次、小桔妹" to the group chat`
,
`凌`
,
[
'
庆次
'
,
'
小桔妹
'
]
]
]
let
result
contentList
.
forEach
(([
content
,
inviter
,
invitee
])
=>
{
contentList
.
forEach
(([
content
,
inviter
,
invitee
List
])
=>
{
result
=
Firer
.
checkRoomJoin
(
content
)
t
.
truthy
(
result
,
'
should check room join message right for
'
+
content
)
t
.
is
(
result
[
0
],
invitee
,
'
should get invitee
right
'
)
t
.
deepEqual
(
result
[
0
],
inviteeList
,
'
should get inviteeList
right
'
)
t
.
is
(
result
[
1
],
inviter
,
'
should get inviter right
'
)
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录