Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
1b889120
W
wechaty
项目概览
weixin_46011646
/
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,体验更适合开发者的 AI 搜索 >>
提交
1b889120
编写于
2月 06, 2017
作者:
ruiruibupt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#217
上级
c0a69986
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
15 addition
and
19 deletion
+15
-19
src/contact.ts
src/contact.ts
+10
-12
src/room.ts
src/room.ts
+3
-5
test/room.spec.ts
test/room.spec.ts
+2
-2
未找到文件。
src/contact.ts
浏览文件 @
1b889120
...
...
@@ -56,8 +56,6 @@ export enum Gender {
export
type
ContactQueryFilter
=
{
name
?:
string
|
RegExp
// remark should be deprecated
remark
?:
string
|
RegExp
alias
?:
string
|
RegExp
}
...
...
@@ -226,18 +224,19 @@ export class Contact implements Sayable {
/**
* find contact by `name` or `alias`
*/
public
static
async
findAll
(
queryArg
?:
ContactQueryFilter
):
Promise
<
Contact
[]
>
{
public
static
async
findAll
(
queryArg
?:
ContactQueryFilter
|
{
remark
:
string
|
RegExp
}
):
Promise
<
Contact
[]
>
{
let
query
:
ContactQueryFilter
if
(
queryArg
)
{
if
(
queryArg
[
0
]
===
'
remark
'
)
{
log
.
warn
(
'
Contact
'
,
'
Contact.findAll(remark:%s) DEPRECATED, use Contact.findAll(alias:%s) instead.
'
)
query
=
{
alias
:
queryArg
[
1
]}
}
else
{
query
=
queryArg
}
}
else
{
query
=
{
name
:
/.*/
}
}
if
(
query
[
0
]
===
'
remark
'
)
{
log
.
warn
(
'
Contact
'
,
'
findAll(remark:%s) DEPRECATED, use findAll(alias:%s) instead.
'
)
}
// log.verbose('Cotnact', 'findAll({ name: %s })', query.name)
log
.
verbose
(
'
Cotnact
'
,
'
findAll({ %s })
'
,
Object
.
keys
(
query
)
...
...
@@ -254,8 +253,6 @@ export class Contact implements Sayable {
const
keyMap
=
{
name
:
'
NickName
'
,
// should be deprecated
remark
:
'
RemarkName
'
,
alias
:
'
RemarkName
'
,
}
...
...
@@ -335,6 +332,7 @@ export class Contact implements Sayable {
})
}
// function should be deprecated
public
remark
(
newRemark
?:
string
|
null
):
Promise
<
boolean
>
|
string
|
null
{
log
.
warn
(
'
Contact
'
,
'
remark(%s) DEPRECATED, use alias(%s) instead.
'
)
log
.
silly
(
'
Contact
'
,
'
remark(%s)
'
,
newRemark
||
''
)
...
...
@@ -349,8 +347,8 @@ export class Contact implements Sayable {
/**
* try to find a contact by filter: {name: string | RegExp}
*/
public
static
async
find
(
query
:
ContactQueryFilter
):
Promise
<
Contact
>
{
log
.
verbose
(
'
Contact
'
,
'
find(%s)
'
,
query
.
name
)
public
static
async
find
(
query
:
ContactQueryFilter
|
{
remark
:
string
|
RegExp
}
):
Promise
<
Contact
>
{
log
.
verbose
(
'
Contact
'
,
'
find(%s)
'
,
query
)
const
contactList
=
await
Contact
.
findAll
(
query
)
if
(
!
contactList
||
!
contactList
.
length
)
{
...
...
src/room.ts
浏览文件 @
1b889120
...
...
@@ -252,6 +252,7 @@ export class Room extends EventEmitter implements Sayable {
/**
* ISSUE #64 emoji need to be striped
* ISSUE #104 never use remark name because sys group message will never use that
* @rui: Wrong for 'never use remark name because sys group message will never use that', see more in the latest comment in #104
* @rui: cannot use argument NickName because it mix real name and alias
*/
mapList
[
member
.
UserName
]
=
UtilLib
.
stripEmoji
(
tmpName
)
...
...
@@ -353,13 +354,10 @@ export class Room extends EventEmitter implements Sayable {
// should be deprecated
public
nick
(
contact
:
Contact
):
string
{
log
.
warn
(
'
Room
'
,
'
nick(Contact) DEPRECATED, use name(Contact) instead.
'
)
if
(
!
this
.
obj
||
!
this
.
obj
.
nameMap
)
{
return
''
}
return
this
.
obj
.
roomAliasMap
[
contact
.
id
]
||
this
.
obj
.
nameMap
[
contact
.
id
]
return
this
.
alias
(
contact
)
}
public
name
(
contact
:
Contact
):
string
{
public
alias
(
contact
:
Contact
):
string
{
if
(
!
this
.
obj
||
!
this
.
obj
.
nameMap
)
{
return
''
}
...
...
test/room.spec.ts
浏览文件 @
1b889120
...
...
@@ -111,14 +111,14 @@ test('Room smoking test', async t => {
const
nick1
=
r
.
nick
(
contact1
)
t
.
is
(
nick1
,
EXPECTED
.
memberNick1
,
'
should get nick1 from roomAlias
'
)
const
name1
=
r
.
name
(
contact1
)
const
name1
=
r
.
alias
(
contact1
)
t
.
is
(
name1
,
EXPECTED
.
memberNick1
,
'
should get name1 from roomAlias
'
)
const
contact2
=
new
Contact
(
EXPECTED
.
memberId2
)
const
nick2
=
r
.
nick
(
contact2
)
t
.
is
(
nick2
,
EXPECTED
.
memberNick2
,
'
should get nick2 from name because there is no roomAlias,
'
)
const
name2
=
r
.
name
(
contact2
)
const
name2
=
r
.
alias
(
contact2
)
t
.
is
(
name2
,
EXPECTED
.
memberNick2
,
'
should get nick2 from name because there is no roomAlias,
'
)
t
.
truthy
(
r
.
has
(
contact1
),
'
should has contact1
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录