Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
5cab9dbd
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
304
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5cab9dbd
编写于
10月 09, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#40 Typescript transition step 12: fix contact.ts & tslint
上级
26da6ba6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
32 deletion
+64
-32
src/contact.ts
src/contact.ts
+64
-32
未找到文件。
src/contact.ts
浏览文件 @
5cab9dbd
...
...
@@ -11,20 +11,54 @@ import UtilLib from './util-lib'
import
log
from
'
./brolog-env
'
type
ContactObj
=
{
id
:
string
uin
:
string
name
:
string
remark
:
string
weixin
:
string
sex
:
string
province
:
string
city
:
string
signature
:
string
address
:
string
stranger
:
boolean
star
:
boolean
}
type
ContactRawObj
=
{
UserName
:
string
Uin
:
string
Alias
:
string
RemarkName
:
string
Sex
:
string
Province
:
string
City
:
string
NickName
:
string
StarFriend
:
string
stranger
:
string
Signature
:
string
}
class
Contact
{
constructor
(
id
)
{
private
static
pool
=
new
Map
<
string
,
Contact
>
()
private
obj
:
ContactObj
private
rawObj
:
ContactRawObj
constructor
(
public
readonly
id
:
string
)
{
log
.
silly
(
'
Contact
'
,
`constructor(
${
id
}
)`
)
if
(
id
&&
typeof
id
!==
'
string
'
)
{
throw
new
Error
(
'
id must be string if provided. we got:
'
+
typeof
id
)
}
this
.
id
=
id
this
.
obj
=
{
}
if
(
typeof
id
!==
'
string
'
)
{
throw
new
Error
(
'
id must be string. found:
'
+
typeof
id
)
}
}
toString
()
{
return
this
.
id
}
toStringEx
()
{
return
`Contact(
${
this
.
obj
.
name
}
[
${
this
.
id
}
])`
}
public
toString
()
{
return
this
.
id
}
public
toStringEx
()
{
return
`Contact(
${
this
.
obj
&&
this
.
obj
.
name
}
[
${
this
.
id
}
])`
}
p
arse
(
rawObj
)
{
return
!
rawObj
?
{}
:
{
p
rivate
parse
(
rawObj
:
ContactRawObj
):
ContactObj
{
return
!
rawObj
?
null
:
{
id
:
rawObj
.
UserName
,
uin
:
rawObj
.
Uin
// stable id: 4763975 || getCookie("wxuin")
,
weixin
:
rawObj
.
Alias
// Wechat ID
...
...
@@ -42,14 +76,14 @@ class Contact {
}
}
name
()
{
return
UtilLib
.
plainText
(
this
.
obj
.
name
)
}
remark
()
{
return
this
.
obj
.
remark
}
stranger
()
{
return
this
.
obj
.
stranger
}
star
()
{
return
this
.
obj
.
star
}
public
name
()
{
return
UtilLib
.
plainText
(
this
.
obj
&&
this
.
obj
.
name
)
}
public
remark
()
{
return
this
.
obj
&&
this
.
obj
.
remark
}
public
stranger
()
{
return
this
.
obj
&&
this
.
obj
.
stranger
}
public
star
()
{
return
this
.
obj
&&
this
.
obj
.
star
}
get
(
prop
)
{
return
this
.
obj
[
prop
]
}
public
get
(
prop
)
{
return
this
.
obj
&&
this
.
obj
[
prop
]
}
ready
(
contactGetter
)
{
public
ready
(
contactGetter
?:
(
id
:
string
)
=>
Promise
<
ContactRawObj
>
):
Promise
<
Contact
>
{
log
.
silly
(
'
Contact
'
,
'
ready(
'
+
(
contactGetter
?
typeof
contactGetter
:
''
)
+
'
)
'
)
if
(
!
this
.
id
)
{
log
.
warn
(
'
Contact
'
,
'
ready() call on an un-inited contact
'
)
...
...
@@ -79,17 +113,17 @@ class Contact {
})
}
dumpRaw
()
{
public
dumpRaw
()
{
console
.
error
(
'
======= dump raw contact =======
'
)
Object
.
keys
(
this
.
rawObj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
rawObj
[
k
]}
`
))
}
dump
()
{
public
dump
()
{
console
.
error
(
'
======= dump contact =======
'
)
Object
.
keys
(
this
.
obj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
obj
[
k
]}
`
))
}
// private
static
_find
({
private
static
_find
({
name
})
{
log
.
silly
(
'
Cotnact
'
,
'
_find(%s)
'
,
name
)
...
...
@@ -118,14 +152,14 @@ class Contact {
})
}
static
find
({
public
static
find
({
name
})
{
log
.
verbose
(
'
Contact
'
,
'
find(%s)
'
,
name
)
return
Contact
.
_find
({
name
})
.
then
(
idList
=>
{
if
(
!
idList
||
!
Array
.
isArray
(
idList
)){
if
(
!
idList
||
!
Array
.
isArray
(
idList
))
{
throw
new
Error
(
'
_find return error
'
)
}
if
(
idList
.
length
<
1
)
{
...
...
@@ -140,7 +174,7 @@ class Contact {
})
}
static
findAll
({
public
static
findAll
({
name
})
{
log
.
verbose
(
'
Contact
'
,
'
findAll(%s)
'
,
name
)
...
...
@@ -148,7 +182,7 @@ class Contact {
return
Contact
.
_find
({
name
})
.
then
(
idList
=>
{
// console.log(idList)
if
(
!
idList
||
!
Array
.
isArray
(
idList
)){
if
(
!
idList
||
!
Array
.
isArray
(
idList
))
{
throw
new
Error
(
'
_find return error
'
)
}
if
(
idList
.
length
<
1
)
{
...
...
@@ -162,21 +196,19 @@ class Contact {
})
}
}
Contact
.
init
=
function
()
{
Contact
.
pool
=
{}
}
Contact
.
init
()
public
static
load
(
id
:
string
)
{
if
(
!
id
||
typeof
id
!==
'
string
'
)
{
return
null
}
Contact
.
load
=
function
(
id
)
{
if
(
!
id
||
typeof
id
!==
'
string
'
)
{
return
null
if
(
!
(
id
in
Contact
.
pool
))
{
Contact
.
pool
[
id
]
=
new
Contact
(
id
)
}
return
Contact
.
pool
[
id
]
}
if
(
!
(
id
in
Contact
.
pool
))
{
Contact
.
pool
[
id
]
=
new
Contact
(
id
)
}
return
Contact
.
pool
[
id
]
}
// Contact.search = function(options) {
// if (options.name) {
// const regex = new RegExp(options.name)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录