Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
dc1f6792
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,发现更多精彩内容 >>
提交
dc1f6792
编写于
6月 16, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor contactValidate() & roomValidate()
上级
8d3ca9aa
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
51 addition
and
41 deletion
+51
-41
src/contact.ts
src/contact.ts
+29
-3
src/puppet-mock/puppet-mock.ts
src/puppet-mock/puppet-mock.ts
+0
-10
src/puppet-padchat/puppet-padchat.ts
src/puppet-padchat/puppet-padchat.ts
+2
-2
src/puppet-puppeteer/puppet-puppeteer.ts
src/puppet-puppeteer/puppet-puppeteer.ts
+0
-10
src/puppet-wechat4u/puppet-wechat4u.ts
src/puppet-wechat4u/puppet-wechat4u.ts
+0
-10
src/puppet/puppet.spec.ts
src/puppet/puppet.spec.ts
+0
-2
src/puppet/puppet.ts
src/puppet/puppet.ts
+18
-2
src/room.ts
src/room.ts
+2
-2
未找到文件。
src/contact.ts
浏览文件 @
dc1f6792
...
...
@@ -131,14 +131,40 @@ export class Contact extends Accessory implements Sayable {
log
.
verbose
(
'
Contact
'
,
'
find(%s)
'
,
JSON
.
stringify
(
query
))
const
contactList
=
await
this
.
findAll
(
query
)
if
(
!
contactList
||
!
contactList
.
length
)
{
if
(
!
contactList
)
{
return
null
}
if
(
contactList
.
length
<
1
)
{
return
null
}
if
(
contactList
.
length
>
1
)
{
log
.
warn
(
'
Contact
'
,
'
function find(%s) get %d contacts, use the first one by default
'
,
JSON
.
stringify
(
query
),
contactList
.
length
)
log
.
warn
(
'
Contact
'
,
'
find() got more than one(%d) result
'
,
contactList
.
length
)
}
let
n
=
0
for
(
n
=
0
;
n
<
contactList
.
length
;
n
++
)
{
const
contact
=
contactList
[
n
]
// use puppet.contactValidate() to confirm double confirm that this contactId is valid.
// https://github.com/lijiarui/wechaty-puppet-padchat/issues/64
// https://github.com/Chatie/wechaty/issues/1345
const
valid
=
await
this
.
puppet
.
contactValidate
(
contact
.
id
)
if
(
valid
)
{
log
.
verbose
(
'
Contact
'
,
'
find() confirm contact[#%d] with id=%d is vlaid result, return it.
'
,
n
,
contact
.
id
,
)
return
contact
}
else
{
log
.
verbose
(
'
Contact
'
,
'
find() confirm contact[#%d] with id=%d is INVALID result, try next
'
,
n
,
contact
.
id
,
)
}
}
return
contactList
[
0
]
log
.
warn
(
'
Contact
'
,
'
find() got %d contacts but no one is valid.
'
,
contactList
.
length
)
return
null
}
/**
...
...
src/puppet-mock/puppet-mock.ts
浏览文件 @
dc1f6792
...
...
@@ -145,11 +145,6 @@ export class PuppetMock extends Puppet {
return
}
public
async
contactValid
(
contactId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetMock
'
,
'
contactValid(%s)
'
,
contactId
)
return
true
}
public
async
contactList
():
Promise
<
string
[]
>
{
log
.
verbose
(
'
PuppetMock
'
,
'
contactList()
'
)
...
...
@@ -303,11 +298,6 @@ export class PuppetMock extends Puppet {
return
payload
}
public
async
roomValid
(
roomId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetMock
'
,
'
roomValid(%s)
'
,
roomId
)
return
true
}
public
async
roomList
():
Promise
<
string
[]
>
{
log
.
verbose
(
'
PuppetMock
'
,
'
roomList()
'
)
...
...
src/puppet-padchat/puppet-padchat.ts
浏览文件 @
dc1f6792
...
...
@@ -558,7 +558,7 @@ export class PuppetPadchat extends Puppet {
return
}
public
async
contactValid
(
contactId
:
string
):
Promise
<
boolean
>
{
public
async
contactValid
ate
(
contactId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
contactValid(%s)
'
,
contactId
)
return
true
}
...
...
@@ -944,7 +944,7 @@ export class PuppetPadchat extends Puppet {
return
memberIdList
}
public
async
roomValid
(
roomId
:
string
):
Promise
<
boolean
>
{
public
async
roomValid
ate
(
roomId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
roomValid(%s)
'
,
roomId
)
if
(
!
this
.
padchatManager
)
{
throw
new
Error
(
'
no padchat manager
'
)
...
...
src/puppet-puppeteer/puppet-puppeteer.ts
浏览文件 @
dc1f6792
...
...
@@ -858,11 +858,6 @@ export class PuppetPuppeteer extends Puppet {
// return filterFunction
// }
public
async
contactValid
(
contactId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetPuppeteer
'
,
'
contactValid(%s)
'
,
contactId
)
return
true
}
public
async
contactList
():
Promise
<
string
[]
>
{
const
idList
=
await
this
.
bridge
.
contactList
()
return
idList
...
...
@@ -993,11 +988,6 @@ export class PuppetPuppeteer extends Puppet {
return
roomPayload
}
public
async
roomValid
(
roomId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetPuppeteer
'
,
'
roomValid(%s)
'
,
roomId
)
return
true
}
public
async
roomList
():
Promise
<
string
[]
>
{
log
.
verbose
(
'
PuppetPupppeteer
'
,
'
roomList()
'
)
...
...
src/puppet-wechat4u/puppet-wechat4u.ts
浏览文件 @
dc1f6792
...
...
@@ -305,11 +305,6 @@ export class PuppetWechat4u extends Puppet {
await
this
.
wechat4u
.
updateRemarkName
(
contactId
,
alias
)
}
public
async
contactValid
(
contactId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetWechat4u
'
,
'
contactValid(%s)
'
,
contactId
)
return
true
}
public
async
contactList
():
Promise
<
string
[]
>
{
log
.
verbose
(
'
PuppetWechat4u
'
,
'
contactList()
'
)
...
...
@@ -756,11 +751,6 @@ export class PuppetWechat4u extends Puppet {
return
roomPayload
}
public
async
roomValid
(
roomId
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
PuppetWechat4u
'
,
'
roomValid(%s)
'
,
roomId
)
return
true
}
public
async
roomList
():
Promise
<
string
[]
>
{
log
.
verbose
(
'
PuppetWechat4u
'
,
'
roomList()
'
)
...
...
src/puppet/puppet.spec.ts
浏览文件 @
dc1f6792
...
...
@@ -57,7 +57,6 @@ class PuppetTest extends Puppet {
public
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
async
contactAvatar
(
contactId
:
string
,
file
?:
FileBox
)
:
Promise
<
void
|
FileBox
>
{
return
{
contactId
,
file
}
as
any
}
public
async
contactValid
(
contactId
:
string
)
:
Promise
<
boolean
>
{
return
!!
contactId
}
public
async
contactList
()
:
Promise
<
string
[]
>
{
return
{}
as
any
}
public
async
contactQrcode
(
contactId
:
string
)
:
Promise
<
string
>
{
return
{
contactId
}
as
any
}
...
...
@@ -109,7 +108,6 @@ class PuppetTest extends Puppet {
public
async
roomTopic
(
roomId
:
string
,
topic
:
string
)
:
Promise
<
void
>
public
async
roomTopic
(
roomId
:
string
,
topic
?:
string
)
:
Promise
<
string
|
void
>
{
return
{
roomId
,
topic
}
as
any
}
public
async
roomValid
(
roomId
:
string
)
:
Promise
<
boolean
>
{
return
!!
roomId
}
public
async
roomList
()
:
Promise
<
string
[]
>
{
return
{}
as
any
}
public
async
roomMemberList
(
roomId
:
string
)
:
Promise
<
string
[]
>
{
return
{
roomId
}
as
any
}
...
...
src/puppet/puppet.ts
浏览文件 @
dc1f6792
...
...
@@ -365,7 +365,6 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
abstract
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
abstract
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
abstract
async
contactValid
(
contactId
:
string
)
:
Promise
<
boolean
>
public
abstract
async
contactList
()
:
Promise
<
string
[]
>
public
abstract
async
contactQrcode
(
contactId
:
string
)
:
Promise
<
string
>
...
...
@@ -454,6 +453,15 @@ export abstract class Puppet extends EventEmitter implements Sayable {
return
filterFunction
}
/**
* Check a Contact Id if it's still valid.
* For example: talk to the server, and see if it should be deleted in the local cache.
*/
public
async
contactValidate
(
contactId
:
string
)
:
Promise
<
boolean
>
{
log
.
silly
(
'
Puppet
'
,
'
contactValidate(%s) base class just return `true`
'
,
contactId
)
return
true
}
public
contactPayloadCache
(
contactId
:
string
):
undefined
|
ContactPayload
{
// log.silly('Puppet', 'contactPayloadCache(id=%s) @ %s', contactId, this)
if
(
!
contactId
)
{
...
...
@@ -631,7 +639,6 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
abstract
async
roomAvatar
(
roomId
:
string
)
:
Promise
<
FileBox
>
public
abstract
async
roomCreate
(
contactIdList
:
string
[],
topic
?:
string
)
:
Promise
<
string
>
public
abstract
async
roomDel
(
roomId
:
string
,
contactId
:
string
)
:
Promise
<
void
>
public
abstract
async
roomValid
(
roomId
:
string
)
:
Promise
<
boolean
>
public
abstract
async
roomQuit
(
roomId
:
string
)
:
Promise
<
void
>
public
abstract
async
roomTopic
(
roomId
:
string
)
:
Promise
<
string
>
...
...
@@ -787,6 +794,15 @@ export abstract class Puppet extends EventEmitter implements Sayable {
return
filterFunction
}
/**
* Check a Room Id if it's still valid.
* For example: talk to the server, and see if it should be deleted in the local cache.
*/
public
async
roomValidate
(
roomId
:
string
):
Promise
<
boolean
>
{
log
.
silly
(
'
Puppet
'
,
'
roomValidate(%s) base class just return `true`
'
,
roomId
)
return
true
}
public
roomPayloadCache
(
roomId
:
string
):
undefined
|
RoomPayload
{
// log.silly('Puppet', 'roomPayloadCache(id=%s) @ %s', roomId, this)
if
(
!
roomId
)
{
...
...
src/room.ts
浏览文件 @
dc1f6792
...
...
@@ -163,10 +163,10 @@ export class Room extends Accessory implements Sayable {
let
n
=
0
for
(
n
=
0
;
n
<
roomList
.
length
;
n
++
)
{
const
room
=
roomList
[
n
]
// use puppet.roomValid() to confirm double confirm that this roomId is valid.
// use puppet.roomValid
ate
() to confirm double confirm that this roomId is valid.
// https://github.com/lijiarui/wechaty-puppet-padchat/issues/64
// https://github.com/Chatie/wechaty/issues/1345
const
valid
=
await
this
.
puppet
.
roomValid
(
room
.
id
)
const
valid
=
await
this
.
puppet
.
roomValid
ate
(
room
.
id
)
if
(
valid
)
{
log
.
verbose
(
'
Room
'
,
'
find() confirm room[#%d] with id=%d is vlaid result, return it.
'
,
n
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录