Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
39e1955a
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,发现更多精彩内容 >>
提交
39e1955a
编写于
2月 06, 2017
作者:
ruiruibupt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename the nick/remark/display for contact/room #217
上级
ee51219b
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
76 addition
and
48 deletion
+76
-48
src/contact.ts
src/contact.ts
+39
-20
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+1
-1
src/puppet.ts
src/puppet.ts
+1
-1
src/room.ts
src/room.ts
+35
-26
未找到文件。
src/contact.ts
浏览文件 @
39e1955a
...
...
@@ -22,7 +22,7 @@ type ContactObj = {
id
:
string
name
:
string
province
:
string
remark
:
string
|
null
alias
:
string
|
null
sex
:
Gender
signature
:
string
star
:
boolean
...
...
@@ -56,7 +56,9 @@ export enum Gender {
export
type
ContactQueryFilter
=
{
name
?:
string
|
RegExp
// remark should be deprecated
remark
?:
string
|
RegExp
alias
?:
string
|
RegExp
}
export
class
Contact
implements
Sayable
{
...
...
@@ -78,7 +80,7 @@ export class Contact implements Sayable {
if
(
!
this
.
obj
)
{
return
this
.
id
}
return
this
.
obj
.
remark
||
this
.
obj
.
name
||
this
.
id
return
this
.
obj
.
alias
||
this
.
obj
.
name
||
this
.
id
}
public
toStringEx
()
{
return
`Contact(
${
this
.
obj
&&
this
.
obj
.
name
}
[
${
this
.
id
}
])`
}
...
...
@@ -93,7 +95,7 @@ export class Contact implements Sayable {
,
uin
:
rawObj
.
Uin
// stable id: 4763975 || getCookie("wxuin")
,
weixin
:
rawObj
.
Alias
// Wechat ID
,
name
:
rawObj
.
NickName
,
remark
:
rawObj
.
RemarkName
,
alias
:
rawObj
.
RemarkName
,
sex
:
rawObj
.
Sex
,
province
:
rawObj
.
Province
,
city
:
rawObj
.
City
...
...
@@ -222,7 +224,7 @@ export class Contact implements Sayable {
}
/**
* find contact by `name`
(NickName) or `remark`(RemarkName)
* find contact by `name`
or `alias`
*/
public
static
async
findAll
(
queryArg
?:
ContactQueryFilter
):
Promise
<
Contact
[]
>
{
let
query
:
ContactQueryFilter
...
...
@@ -232,6 +234,10 @@ export class Contact implements Sayable {
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
)
...
...
@@ -248,7 +254,9 @@ export class Contact implements Sayable {
const
keyMap
=
{
name
:
'
NickName
'
,
// should be deprecated
remark
:
'
RemarkName
'
,
alias
:
'
RemarkName
'
,
}
filterKey
=
keyMap
[
filterKey
]
...
...
@@ -287,46 +295,57 @@ export class Contact implements Sayable {
}
/**
* get the
remark
for contact
* get the
alias
for contact
*/
public
remark
():
string
|
null
public
alias
():
string
|
null
/**
* set the
remark
for contact
* set the
alias
for contact
* @return {Promise<boolean>} A promise to the result. true for success, false for failure
*/
public
remark
(
newRemark
:
string
):
Promise
<
boolean
>
public
alias
(
newAlias
:
string
):
Promise
<
boolean
>
/**
* delete the
remark
for a contact
* delete the
alias
for a contact
*/
public
remark
(
empty
:
null
):
Promise
<
boolean
>
public
alias
(
empty
:
null
):
Promise
<
boolean
>
public
remark
(
newRemark
?:
string
|
null
):
Promise
<
boolean
>
|
string
|
null
{
log
.
silly
(
'
Contact
'
,
'
remark(%s)
'
,
newRemark
||
''
)
public
alias
(
newAlias
?:
string
|
null
):
Promise
<
boolean
>
|
string
|
null
{
log
.
silly
(
'
Contact
'
,
'
alias(%s)
'
,
newAlias
||
''
)
if
(
new
Remark
===
undefined
)
{
return
this
.
obj
&&
this
.
obj
.
remark
||
null
if
(
new
Alias
===
undefined
)
{
return
this
.
obj
&&
this
.
obj
.
alias
||
null
}
return
Config
.
puppetInstance
()
.
contact
Remark
(
this
,
newRemark
)
.
contact
Alias
(
this
,
newAlias
)
.
then
(
ret
=>
{
if
(
ret
)
{
if
(
this
.
obj
)
{
this
.
obj
.
remark
=
newRemark
this
.
obj
.
alias
=
newAlias
}
else
{
log
.
error
(
'
Contact
'
,
'
remark
() without this.obj?
'
)
log
.
error
(
'
Contact
'
,
'
alias
() without this.obj?
'
)
}
}
else
{
log
.
warn
(
'
Contact
'
,
'
remark(%s) fail
'
,
newRemark
)
log
.
warn
(
'
Contact
'
,
'
alias(%s) fail
'
,
newAlias
)
}
return
ret
})
.
catch
(
e
=>
{
log
.
error
(
'
Contact
'
,
'
remark(%s) rejected: %s
'
,
newRemark
,
e
.
message
)
log
.
error
(
'
Contact
'
,
'
alias(%s) rejected: %s
'
,
newAlias
,
e
.
message
)
return
false
// fail safe
})
}
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
||
''
)
if
(
newRemark
)
{
return
this
.
alias
(
newRemark
)
}
else
{
return
this
.
alias
()
}
}
/**
* try to find a contact by filter: {name: string | RegExp}
*/
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
39e1955a
...
...
@@ -374,7 +374,7 @@ export class PuppetWeb extends Puppet {
}
}
public
async
contact
Remark
(
contact
:
Contact
,
remark
:
string
|
null
):
Promise
<
boolean
>
{
public
async
contact
Alias
(
contact
:
Contact
,
remark
:
string
|
null
):
Promise
<
boolean
>
{
try
{
const
ret
=
await
this
.
bridge
.
contactRemark
(
contact
.
id
,
remark
)
if
(
!
ret
)
{
...
...
src/puppet.ts
浏览文件 @
39e1955a
...
...
@@ -67,5 +67,5 @@ export abstract class Puppet extends EventEmitter implements Sayable {
* Contact
*/
public
abstract
contactFind
(
filterFunc
:
string
):
Promise
<
Contact
[]
>
public
abstract
contact
Remark
(
contact
:
Contact
,
remark
:
string
|
null
):
Promise
<
boolean
>
public
abstract
contact
Alias
(
contact
:
Contact
,
alias
:
string
|
null
):
Promise
<
boolean
>
}
src/room.ts
浏览文件 @
39e1955a
...
...
@@ -25,12 +25,12 @@ type RoomObj = {
topic
:
string
ownerUin
:
number
memberList
:
Contact
[]
n
ickMap
:
Map
<
string
,
string
>
remarkMap
:
Map
<
string
,
string
>
display
Map
:
Map
<
string
,
string
>
n
ameMap
:
Map
<
string
,
string
>
aliasMap
:
Map
<
string
,
string
>
roomAlias
Map
:
Map
<
string
,
string
>
}
type
NameType
=
'
n
ick
'
|
'
display
'
|
'
remark
'
type
NameType
=
'
n
ame
'
|
'
alias
'
|
'
roomAlias
'
export
type
RoomRawMember
=
{
UserName
:
string
...
...
@@ -57,9 +57,9 @@ export type RoomQueryFilter = {
}
export
type
MemberQueryFilter
=
{
n
ick
?:
string
remark
?:
string
display
?:
string
n
ame
?:
string
alias
?:
string
roomAlias
?:
string
}
export
class
Room
extends
EventEmitter
implements
Sayable
{
...
...
@@ -207,9 +207,9 @@ export class Room extends EventEmitter implements Sayable {
}
const
memberList
=
this
.
parseMemberList
(
rawObj
.
MemberList
)
const
n
ickMap
=
this
.
parseMap
(
rawObj
.
MemberList
,
'
nick
'
)
const
remarkMap
=
this
.
parseMap
(
rawObj
.
MemberList
,
'
remark
'
)
const
displayMap
=
this
.
parseMap
(
rawObj
.
MemberList
,
'
display
'
)
const
n
ameMap
=
this
.
parseMap
(
rawObj
.
MemberList
,
'
name
'
)
const
aliasMap
=
this
.
parseMap
(
rawObj
.
MemberList
,
'
alias
'
)
const
roomAliasMap
=
this
.
parseMap
(
rawObj
.
MemberList
,
'
roomAlias
'
)
return
{
id
:
rawObj
.
UserName
,
...
...
@@ -218,9 +218,9 @@ export class Room extends EventEmitter implements Sayable {
ownerUin
:
rawObj
.
OwnerUin
,
memberList
,
n
ick
Map
,
remark
Map
,
display
Map
,
n
ame
Map
,
alias
Map
,
roomAlias
Map
,
}
}
...
...
@@ -237,13 +237,13 @@ export class Room extends EventEmitter implements Sayable {
let
tmpName
:
string
let
contact
=
Contact
.
load
(
member
.
UserName
)
switch
(
parseContent
)
{
case
'
n
ick
'
:
case
'
n
ame
'
:
tmpName
=
contact
.
name
()
break
case
'
remark
'
:
tmpName
=
contact
.
remark
()
||
''
case
'
alias
'
:
tmpName
=
contact
.
alias
()
||
''
break
case
'
display
'
:
case
'
roomAlias
'
:
tmpName
=
member
.
DisplayName
break
default
:
...
...
@@ -252,7 +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: cannot use argument NickName because it mix real n
ick and remark
* @rui: cannot use argument NickName because it mix real n
ame and alias
*/
mapList
[
member
.
UserName
]
=
UtilLib
.
stripEmoji
(
tmpName
)
})
...
...
@@ -350,11 +350,20 @@ export class Room extends EventEmitter implements Sayable {
return
UtilLib
.
plainText
(
this
.
obj
?
this
.
obj
.
topic
:
''
)
}
// should be deprecated
public
nick
(
contact
:
Contact
):
string
{
if
(
!
this
.
obj
||
!
this
.
obj
.
nickMap
)
{
log
.
warn
(
'
Room
'
,
'
nick(Contact) DEPRECATED, use name(Contact) instead.
'
)
if
(
!
this
.
obj
||
!
this
.
obj
.
nameMap
)
{
return
''
}
return
this
.
obj
.
displayMap
[
contact
.
id
]
||
this
.
obj
.
nickMap
[
contact
.
id
]
return
this
.
obj
.
roomAliasMap
[
contact
.
id
]
||
this
.
obj
.
nameMap
[
contact
.
id
]
}
public
name
(
contact
:
Contact
):
string
{
if
(
!
this
.
obj
||
!
this
.
obj
.
nameMap
)
{
return
''
}
return
this
.
obj
.
roomAliasMap
[
contact
.
id
]
||
this
.
obj
.
nameMap
[
contact
.
id
]
}
public
has
(
contact
:
Contact
):
boolean
{
...
...
@@ -390,7 +399,7 @@ export class Room extends EventEmitter implements Sayable {
}
/**
* find member by `n
ick`(NickName) / `display`(DisplayName) / `remark`(RemarkName)
* find member by `n
ame` / `roomAlias` / `alias`
* when use member(name:string), find all name by default
*/
...
...
@@ -399,7 +408,7 @@ export class Room extends EventEmitter implements Sayable {
public
member
(
queryArg
:
MemberQueryFilter
|
string
):
Contact
|
null
{
if
(
typeof
queryArg
===
'
string
'
)
{
return
this
.
member
({
remark
:
queryArg
})
||
this
.
member
({
display
:
queryArg
})
||
this
.
member
({
nick
:
queryArg
})
return
this
.
member
({
alias
:
queryArg
})
||
this
.
member
({
roomAlias
:
queryArg
})
||
this
.
member
({
name
:
queryArg
})
}
log
.
silly
(
'
Room
'
,
'
member({ %s })
'
...
...
@@ -423,9 +432,9 @@ export class Room extends EventEmitter implements Sayable {
let
filterValue
:
string
=
UtilLib
.
stripEmoji
(
queryArg
[
filterKey
])
const
keyMap
=
{
n
ick
:
'
nick
Map
'
,
remark
:
'
remark
Map
'
,
display
:
'
display
Map
'
n
ame
:
'
name
Map
'
,
alias
:
'
alias
Map
'
,
roomAlias
:
'
roomAlias
Map
'
}
filterKey
=
keyMap
[
filterKey
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录