Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
fca7781f
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,发现更多精彩内容 >>
提交
fca7781f
编写于
10月 05, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#32
add Room.nick()
上级
edce2e10
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
25 deletion
+41
-25
README.md
README.md
+2
-0
src/contact.js
src/contact.js
+9
-6
src/room.js
src/room.js
+30
-19
未找到文件。
README.md
浏览文件 @
fca7781f
...
...
@@ -525,6 +525,8 @@ wechaty.on('friend', (contact: Contact, request: FriendRequest) => {
})
```
Talk is cheap, show me the code:
[
Example/Friend-Bot
](
https://github.com/wechaty/wechaty/blob/master/example/friend-bot.js
)
### FriendRequest.hello: string
verify message
...
...
src/contact.js
浏览文件 @
fca7781f
...
...
@@ -42,11 +42,12 @@ class Contact {
}
}
name
()
{
return
UtilLib
.
plainText
(
this
.
obj
.
name
)
}
remark
()
{
return
this
.
obj
.
remark
}
stranger
()
{
return
this
.
obj
.
stranger
}
star
()
{
return
this
.
obj
.
star
}
get
(
prop
)
{
return
this
.
obj
[
prop
]
}
name
()
{
return
UtilLib
.
plainText
(
this
.
obj
.
name
)
}
remark
()
{
return
this
.
obj
.
remark
}
stranger
()
{
return
this
.
obj
.
stranger
}
star
()
{
return
this
.
obj
.
star
}
get
(
prop
)
{
return
this
.
obj
[
prop
]
}
ready
(
contactGetter
)
{
log
.
silly
(
'
Contact
'
,
'
ready(
'
+
(
contactGetter
?
typeof
contactGetter
:
''
)
+
'
)
'
)
...
...
@@ -103,7 +104,9 @@ Contact.init = function() { Contact.pool = {} }
Contact
.
init
()
Contact
.
load
=
function
(
id
)
{
if
(
!
id
)
{
return
null
}
if
(
!
id
||
typeof
id
!==
'
string
'
)
{
throw
new
Error
(
'
id must be string
'
)
}
if
(
!
(
id
in
Contact
.
pool
))
{
Contact
.
pool
[
id
]
=
new
Contact
(
id
)
...
...
src/room.js
浏览文件 @
fca7781f
...
...
@@ -29,7 +29,7 @@ class Room {
// @private
isReady
()
{
return
this
.
obj
.
memberList
&&
this
.
obj
.
member
List
.
length
return
this
.
obj
.
contactList
&&
this
.
obj
.
contact
List
.
length
}
refresh
()
{
...
...
@@ -47,7 +47,7 @@ class Room {
}
else
if
(
this
.
isReady
())
{
return
Promise
.
resolve
(
this
)
}
else
if
(
this
.
obj
.
id
)
{
log
.
warn
(
'
Room
'
,
'
ready() has obj.id but
member
List empty in room %s. reloading
'
,
this
.
obj
.
topic
)
log
.
warn
(
'
Room
'
,
'
ready() has obj.id but
contact
List empty in room %s. reloading
'
,
this
.
obj
.
topic
)
}
contactGetter
=
contactGetter
||
Config
.
puppetInstance
()
...
...
@@ -75,20 +75,24 @@ class Room {
id
:
rawObj
.
UserName
,
encryId
:
rawObj
.
EncryChatRoomId
// ???
,
topic
:
rawObj
.
NickName
,
memberList
:
this
.
parseMemberList
(
rawObj
.
MemberList
)
,
contactList
:
this
.
parseContactList
(
rawObj
.
MemberList
)
,
nickMap
:
this
.
parseNickMap
(
rawObj
.
MemberList
)
}
}
parse
Member
List
(
memberList
)
{
parse
Contact
List
(
memberList
)
{
if
(
!
memberList
||
!
memberList
.
map
)
{
return
[]
}
return
memberList
.
map
(
m
=>
{
return
{
id
:
m
.
UserName
,
name
:
m
.
DisplayName
// nick name for this room?
}
})
return
memberList
.
map
(
m
=>
m
.
UserName
)
}
parseNickMap
(
memberList
)
{
const
nickMap
=
{}
if
(
memberList
&&
memberList
.
map
)
{
memberList
.
forEach
(
m
=>
nickMap
[
m
.
UserName
]
=
m
.
DisplayName
)
}
return
nickMap
}
dumpRaw
()
{
...
...
@@ -114,28 +118,28 @@ class Room {
delLocal
(
contact
)
{
log
.
verbose
(
'
Room
'
,
'
delLocal(%s)
'
,
contact
)
const
memberList
=
this
.
obj
.
member
List
if
(
!
memberList
||
member
List
.
length
===
0
)
{
const
contactList
=
this
.
obj
.
contact
List
if
(
!
contactList
||
contact
List
.
length
===
0
)
{
return
true
// already in refreshing
}
let
i
for
(
i
=
0
;
i
<
member
List
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
contact
List
.
length
;
i
++
)
{
// XXX
// console.log('########################')
// console.log(i)
// console.log(
member
List[i].id)
// console.log(
contact
List[i].id)
// console.log(contact.get('id'))
// console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!')
if
(
member
List
[
i
].
id
===
contact
.
get
(
'
id
'
))
{
if
(
contact
List
[
i
].
id
===
contact
.
get
(
'
id
'
))
{
break
}
}
// console.log('found i=' + i)
if
(
i
<
member
List
.
length
)
{
// console.log('splicing before: ' +
member
List.length)
member
List
.
splice
(
i
,
1
)
// console.log('splicing after: ' +
member
List.length)
if
(
i
<
contact
List
.
length
)
{
// console.log('splicing before: ' +
contact
List.length)
contact
List
.
splice
(
i
,
1
)
// console.log('splicing after: ' +
contact
List.length)
return
true
}
return
false
...
...
@@ -166,6 +170,13 @@ class Room {
return
this
.
get
(
'
topic
'
)
}
nick
(
contactId
)
{
if
(
!
this
.
obj
.
nickMap
)
{
return
''
}
return
this
.
obj
.
nickMap
[
contactId
]
}
static
create
(
contactList
)
{
log
.
verbose
(
'
Room
'
,
'
create(%s)
'
,
contactList
.
join
(
'
,
'
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录