Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
b41af29e
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 接近 3 年
通知
299
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,体验更适合开发者的 AI 搜索 >>
提交
b41af29e
编写于
6月 08, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow the refactor changes and fix all unit tests
上级
e6794dd5
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
135 addition
and
95 deletion
+135
-95
src/config.ts
src/config.ts
+5
-0
src/contact.ts
src/contact.ts
+3
-0
src/friend-request.ts
src/friend-request.ts
+4
-0
src/message.ts
src/message.ts
+4
-0
src/puppet-padchat/padchat-schemas.ts
src/puppet-padchat/padchat-schemas.ts
+24
-20
src/puppet-padchat/pure-function-helper.spec.ts
src/puppet-padchat/pure-function-helper.spec.ts
+35
-33
src/puppet-puppeteer/puppeteer-friend-request.spec.ts
src/puppet-puppeteer/puppeteer-friend-request.spec.ts
+7
-2
src/puppet-puppeteer/puppeteer-message.spec.ts
src/puppet-puppeteer/puppeteer-message.spec.ts
+19
-7
src/puppet-puppeteer/puppeteer-room.spec.ts
src/puppet-puppeteer/puppeteer-room.spec.ts
+27
-30
src/room.ts
src/room.ts
+7
-3
未找到文件。
src/config.ts
浏览文件 @
b41af29e
...
...
@@ -33,6 +33,11 @@ import {
PuppetName
,
}
from
'
./puppet-config
'
// https://github.com/Microsoft/TypeScript/issues/14151#issuecomment-280812617
if
(
!
Symbol
.
asyncIterator
)
{
(
<
any
>
Symbol
).
asyncIterator
=
Symbol
.
for
(
'
Symbol.asyncIterator
'
)
}
const
pkg
=
readPkgUp
.
sync
({
cwd
:
__dirname
}).
pkg
export
const
VERSION
=
pkg
.
version
...
...
src/contact.ts
浏览文件 @
b41af29e
...
...
@@ -192,6 +192,9 @@ export class Contact extends Accessory implements Sayable {
*
*/
protected
get
payload
():
undefined
|
ContactPayload
{
if
(
!
this
.
id
)
{
return
undefined
}
return
this
.
puppet
.
contactPayloadCache
(
this
.
id
)
}
...
...
src/friend-request.ts
浏览文件 @
b41af29e
...
...
@@ -124,6 +124,10 @@ export class FriendRequest extends Accessory {
*/
protected
get
payload
():
undefined
|
FriendRequestPayload
{
if
(
!
this
.
id
)
{
return
undefined
}
return
this
.
puppet
.
friendRequestPayloadCache
(
this
.
id
)
}
...
...
src/message.ts
浏览文件 @
b41af29e
...
...
@@ -115,6 +115,10 @@ export class Message extends Accessory implements Sayable {
*
*/
private
get
payload
():
undefined
|
MessagePayload
{
if
(
!
this
.
id
)
{
return
undefined
}
return
this
.
puppet
.
messagePayloadCache
(
this
.
id
)
}
...
...
src/puppet-padchat/padchat-schemas.ts
浏览文件 @
b41af29e
...
...
@@ -110,28 +110,32 @@ export interface PadchatContactPayload {
* message: string, // '',
* ticket: string, // '',
*/
msg_type
:
PadchatContactMsgType
,
continue
:
PadchatContinue
,
ticket
?
:
string
,
big_head
:
string
,
// "http://wx.qlogo.cn/mmhead/ver_1/xfCMmibHH74xGLoyeDFJadrZXX3eOEznPefiaCa3iczxZGMwPtDuSbRQKx3Xdm18un303mf0NFia3USY2nO2VEYILw/0",
city
:
string
,
// 'Haidian'
country
:
string
,
// "CN"
intro
:
string
,
// '',
label
:
string
,
// '1', if no label, it is '', but not really sure
nick_name
:
string
,
// "梦君君", Contact:用户昵称, Room: 群昵称
provincia
:
string
,
// "Beijing",
py_initial
:
string
,
// 'LJR',
remark
:
string
,
// "女儿",
remark_py_initial
:
string
,
// 'lijiaruibeizhu',
remark_quan_pin
:
string
,
// 'LJRBZ',
msg_type
?
:
PadchatContactMsgType
,
continue
?
:
PadchatContinue
,
ticket
?
:
string
,
big_head
:
string
,
// "http://wx.qlogo.cn/mmhead/ver_1/xfCMmibHH74xGLoyeDFJadrZXX3eOEznPefiaCa3iczxZGMwPtDuSbRQKx3Xdm18un303mf0NFia3USY2nO2VEYILw/0",
city
:
string
,
// 'Haidian'
country
:
string
,
// "CN"
intro
:
string
,
// '',
label
:
string
,
// '1', if no label, it is '', but not really sure
nick_name
:
string
,
// "梦君君", Contact:用户昵称, Room: 群昵称
provincia
:
string
,
// "Beijing",
py_initial
:
string
,
// 'LJR',
remark
:
string
,
// "女儿",
remark_py_initial
:
string
,
// 'lijiaruibeizhu',
remark_quan_pin
:
string
,
// 'LJRBZ',
sex
:
ContactGender
,
signature
:
string
,
// "且行且珍惜",
small_head
:
string
,
// "http://wx.qlogo.cn/mmhead/ver_1/xfCMmibHH74xGLoyeDFJadrZXX3eOEznPefiaCa3iczxZGMwPtDuSbRQKx3Xdm18un303mf0NFia3USY2nO2VEYILw/132",
status
:
PadchatContactRoomStatus
,
// 1 when use WXSyncContact, 0 when use WXGetContact
stranger
:
string
,
// "v1_0468f2cd3f0efe7ca2589d57c3f9ba952a3789e41b6e78ee00ed53d1e6096b88@stranger",
user_name
:
string
,
// "mengjunjun001" | "qq512436430" Unique name
signature
:
string
,
// "且行且珍惜",
// "http://wx.qlogo.cn/mmhead/ver_1/xfCMmibHH74xGLoyeDFJadrZXX3eOEznPefiaCa3iczxZGMwPtDuSbRQKx3Xdm18un303mf0NFia3USY2nO2VEYILw/132",
small_head
:
string
,
status
:
PadchatContactRoomStatus
,
// 1 when use WXSyncContact, 0 when use WXGetContact
stranger
:
string
,
// "v1_0468f2cd3f0efe7ca2589d57c3f9ba952a3789e41b6e78ee00ed53d1e6096b88@stranger",
user_name
:
string
,
// "mengjunjun001" | "qq512436430" Unique name
message
?
:
string
,
quan_pin
?
:
string
,
/**
* Differenc with web: No stranger, starFriend, intro, weixinid, tag...
*/
...
...
src/puppet-padchat/pure-function-helper.spec.ts
浏览文件 @
b41af29e
...
...
@@ -58,20 +58,20 @@ test('isStrangerV1()', async t => {
const
STRANGER_V1
=
'
v1_999999
'
const
NOT_STRANGER_V1
=
'
9999991
'
t
.
ok
(
pfHelper
.
isContactOfficialId
(
STRANGER_V1
),
'
should return true for STRANGER_V1
'
)
t
.
notOk
(
pfHelper
.
isContactOfficialId
(
NOT_STRANGER_V1
),
'
should return false for NOT_STRANGER_V1
'
)
t
.
equal
(
pfHelper
.
isStrangerV1
(
STRANGER_V1
),
true
,
'
should return true for STRANGER_V1
'
)
t
.
equal
(
pfHelper
.
isStrangerV1
(
NOT_STRANGER_V1
),
false
,
'
should return false for NOT_STRANGER_V1
'
)
})
test
(
'
isStrangerV2()
'
,
async
t
=>
{
const
STRANGER_V2
=
'
v2_999999
'
const
NOT_STRANGER_V2
=
'
999999v2
'
t
.
ok
(
pfHelper
.
isContactOfficialId
(
STRANGER_V2
)
,
'
should return true for STRANGER_V2
'
)
t
.
notOk
(
pfHelper
.
isContactOfficialId
(
NOT_STRANGER_V2
)
,
'
should return false for NOT_STRANGER_V2
'
)
t
.
equal
(
pfHelper
.
isStrangerV2
(
STRANGER_V2
),
true
,
'
should return true for STRANGER_V2
'
)
t
.
equal
(
pfHelper
.
isStrangerV2
(
NOT_STRANGER_V2
),
false
,
'
should return false for NOT_STRANGER_V2
'
)
})
test
(
'
contactRawPayloadParser
'
,
async
t
=>
{
const
PADCHAT_CONTACT_PAYLOAD
:
PadchatContactPayload
=
{
const
PADCHAT_CONTACT_PAYLOAD
_PERSONAL
:
PadchatContactPayload
=
{
msg_type
:
PadchatContactMsgType
.
Contact
,
continue
:
PadchatContinue
.
Done
,
ticket
:
''
,
...
...
@@ -95,29 +95,29 @@ test('contactRawPayloadParser', async t => {
}
const
PADCHAT_CONTACT_PAYLOAD_OFFICIAL
:
PadchatContactPayload
=
{
msg_type
:
PadchatContactMsgType
.
Contact
,
continue
:
PadchatContinue
.
Done
,
ticket
:
''
,
big_head
:
'
http://wx.qlogo.cn/mmhead/ver_1/xfCMmibHH74xGLoyeDFJadrZXX3eOEznPefiaCa3iczxZGMwPtDuSbRQKx3Xdm18un303mf0NFia3USY2nO2VEYILw/0
'
,
big_head
:
'
http://wx.qlogo.cn/mmhead/ver_1/TR8EDh3MgMsu20pxjrDPBpaGySuEAGf3MUuoeUOV2LiaqvZxeMqb1U7hgiciaQZBC8LYN0boVLCKOIYg71pxdl1fQabiaxsn7CnNeGWVrK3jSIY/0
'
,
city
:
'
Haidian
'
,
country
:
'
CN
'
,
intro
:
''
,
label
:
'
1
'
,
nick_name
:
'
梦君君
'
,
intro
:
'
CARPE+DIEM+-+if+not+us,+who?+if+not+now,+when?
'
,
label
:
''
,
message
:
''
,
nick_name
:
'
李卓桓
'
,
provincia
:
'
Beijing
'
,
py_initial
:
'
LJR
'
,
remark
:
'
女儿
'
,
remark_py_initial
:
'
lijiaruibeizhu
'
,
remark_quan_pin
:
'
LJRBZ
'
,
sex
:
ContactGender
.
Female
,
signature
:
'
且行且珍惜
'
,
small_head
:
'
http://wx.qlogo.cn/mmhead/ver_1/xfCMmibHH74xGLoyeDFJadrZXX3eOEznPefiaCa3iczxZGMwPtDuSbRQKx3Xdm18un303mf0NFia3USY2nO2VEYILw/132
'
,
status
:
PadchatContactRoomStatus
.
Get
,
stranger
:
'
v1_0468f2cd3f0efe7ca2589d57c3f9ba952a3789e41b6e78ee00ed53d1e6096b88@stranger
'
,
user_name
:
'
gh_672f4fa64015
'
,
py_initial
:
'
LZH
'
,
quan_pin
:
'
lizhuohuan
'
,
remark
:
''
,
remark_py_initial
:
''
,
remark_quan_pin
:
''
,
sex
:
0
,
signature
:
'
CARPE+DIEM+-+if+not+us,+who?+if+not+now,+when?
'
,
small_head
:
'
http://wx.qlogo.cn/mmhead/ver_1/TR8EDh3MgMsu20pxjrDPBpaGySuEAGf3MUuoeUOV2LiaqvZxeMqb1U7hgiciaQZBC8LYN0boVLCKOIYg71pxdl1fQabiaxsn7CnNeGWVrK3jSIY/132
'
,
status
:
0
,
stranger
:
'
v1_cd6656d42f505e5ffbb7eab65fed448fc8f02eade29a873ec3e758c7553db424@stranger
'
,
ticket
:
''
,
user_name
:
'
gh_59d7c8ad720c
'
,
}
const
CONTACT_PAYLOAD
:
ContactPayload
=
{
const
EXPECTED_CONTACT_PAYLOAD_PERSONAL
:
ContactPayload
=
{
id
:
'
mengjunjun001
'
,
gender
:
ContactGender
.
Female
,
type
:
ContactType
.
Personal
,
...
...
@@ -129,22 +129,24 @@ test('contactRawPayloadParser', async t => {
signature
:
'
Stay Foolish
'
,
}
const
CONTACT_PAYLOAD_OFFICIAL
:
ContactPayload
=
{
id
:
'
mengjunjun001
'
,
gender
:
ContactGender
.
Female
,
const
EXPECTED_
CONTACT_PAYLOAD_OFFICIAL
:
ContactPayload
=
{
id
:
'
gh_59d7c8ad720c
'
,
gender
:
ContactGender
.
Unknown
,
type
:
ContactType
.
Official
,
alias
:
'
女儿
'
,
avatar
:
'
http://wx.qlogo.cn/mmhead/ver_1/
xfCMmibHH74xGLoyeDFJadrZXX3eOEznPefiaCa3iczxZGMwPtDuSbRQKx3Xdm18un303mf0NFia3USY2nO2VEYILw
/0
'
,
alias
:
''
,
avatar
:
'
http://wx.qlogo.cn/mmhead/ver_1/
TR8EDh3MgMsu20pxjrDPBpaGySuEAGf3MUuoeUOV2LiaqvZxeMqb1U7hgiciaQZBC8LYN0boVLCKOIYg71pxdl1fQabiaxsn7CnNeGWVrK3jSIY
/0
'
,
city
:
'
Haidian
'
,
name
:
'
梦君君
'
,
name
:
'
李卓桓
'
,
province
:
'
Beijing
'
,
signature
:
'
且行且珍惜
'
,
signature
:
'
CARPE DIEM+-+if+not+us,+who?+if+not+now,+when?
'
,
}
const
result
=
pfHelper
.
contactRawPayloadParser
(
PADCHAT_CONTACT_PAYLOAD
)
t
.
deepEqual
(
result
,
CONTACT_PAYLOAD
,
'
should parse ContactPayload result
'
)
const
resultPersonal
=
pfHelper
.
contactRawPayloadParser
(
PADCHAT_CONTACT_PAYLOAD_PERSONAL
)
t
.
deepEqual
(
resultPersonal
,
EXPECTED_CONTACT_PAYLOAD_PERSONAL
,
'
should parse ContactPayload for personal account payload
'
)
const
resultOfficial
=
pfHelper
.
contactRawPayloadParser
(
PADCHAT_CONTACT_PAYLOAD_OFFICIAL
)
t
.
deepEqual
(
resultOfficial
,
CONTACT_PAYLOAD_OFFICIAL
,
'
should parse ContactPayload result when test official account
'
)
t
.
deepEqual
(
resultOfficial
,
EXPECTED_CONTACT_PAYLOAD_OFFICIAL
,
'
should parse ContactPayload for official account payload
'
)
t
.
throws
(()
=>
pfHelper
.
contactRawPayloadParser
({}
as
any
),
'
should throw exception for invalid object
'
)
t
.
throws
(()
=>
pfHelper
.
contactRawPayloadParser
(
undefined
as
any
),
'
should throw exception for undifined
'
)
})
...
...
src/puppet-puppeteer/puppeteer-friend-request.spec.ts
浏览文件 @
b41af29e
...
...
@@ -75,7 +75,6 @@ test('PuppetPuppeteerFriendRequest.receive smoke testing', async t => {
const
info
=
rawMessagePayload
.
RecommendInfo
!
// FIXME: use wechaty.Contact.load
const
contact
=
wechaty
.
Contact
.
load
(
info
.
UserName
)
const
hello
=
info
.
Content
const
ticket
=
info
.
Ticket
...
...
@@ -92,6 +91,7 @@ test('PuppetPuppeteerFriendRequest.receive smoke testing', async t => {
const
sandbox
=
sinon
.
createSandbox
()
sandbox
.
stub
(
puppet
,
'
friendRequestPayload
'
).
resolves
(
payload
)
sandbox
.
stub
(
puppet
,
'
friendRequestPayloadCache
'
).
returns
(
payload
)
const
fr
=
wechaty
.
FriendRequest
.
load
(
id
)
await
fr
.
ready
()
...
...
@@ -121,9 +121,14 @@ test('PuppetPuppeteerFriendRequest.confirm smoke testing', async t => {
}
const
sandbox
=
sinon
.
createSandbox
()
sandbox
.
stub
(
puppet
,
'
messageRawPayload
'
)
.
resolves
(
rawMessagePayload
)
sandbox
.
stub
(
puppet
,
'
contactPayload
'
)
.
resolves
({})
sandbox
.
stub
(
puppet
,
'
friendRequestPayload
'
).
resolves
(
friendRequestPayload
)
sandbox
.
stub
(
puppet
,
'
contactPayloadCache
'
)
.
returns
({})
sandbox
.
stub
(
puppet
,
'
friendRequestPayload
'
)
.
resolves
(
friendRequestPayload
)
sandbox
.
stub
(
puppet
,
'
friendRequestPayloadCache
'
)
.
returns
(
friendRequestPayload
)
const
msg
=
wechaty
.
Message
.
create
(
rawMessagePayload
.
MsgId
)
await
msg
.
ready
()
...
...
src/puppet-puppeteer/puppeteer-message.spec.ts
浏览文件 @
b41af29e
...
...
@@ -83,7 +83,7 @@ test('constructor()', async t => {
const
msg
=
wechaty
.
Message
.
create
(
rawPayload
.
MsgId
)
const
sandbox
=
sinon
.
createSandbox
()
sandbox
.
stub
(
puppet
,
'
messagePayload
'
).
callsFake
(
(
_
:
string
)
=>
{
const
mockMessagePayload
=
(
_
:
string
)
=>
{
const
payload
:
MessagePayload
=
{
id
:
'
id
'
,
type
:
Message
.
Type
.
Text
,
...
...
@@ -92,9 +92,16 @@ test('constructor()', async t => {
toId
:
'
toId
'
,
}
return
payload
})
}
sandbox
.
stub
(
puppet
,
'
contactPayload
'
).
returns
({})
sandbox
.
stub
(
puppet
,
'
contactPayloadCache
'
).
returns
({})
sandbox
.
stub
(
puppet
,
'
roomPayload
'
).
returns
({})
sandbox
.
stub
(
puppet
,
'
roomPayloadCache
'
).
returns
({})
sandbox
.
stub
(
puppet
,
'
messagePayload
'
).
callsFake
(
mockMessagePayload
)
sandbox
.
stub
(
puppet
,
'
messagePayloadCache
'
).
callsFake
(
mockMessagePayload
)
puppet
.
login
(
MOCK_USER_ID
)
...
...
@@ -200,6 +207,7 @@ test('find()', async t => {
const
sandbox
=
sinon
.
createSandbox
()
sandbox
.
stub
(
puppet
,
'
contactPayload
'
).
resolves
({})
sandbox
.
stub
(
puppet
,
'
contactPayloadCache
'
).
returns
({})
const
MOCK_USER_ID
=
'
TEST-USER-ID
'
puppet
.
login
(
MOCK_USER_ID
)
...
...
@@ -220,7 +228,9 @@ test('findAll()', async t => {
wechaty
.
initPuppetAccessory
(
puppet
)
const
sandbox
=
sinon
.
createSandbox
()
sandbox
.
stub
(
puppet
,
'
contactPayload
'
).
resolves
({})
sandbox
.
stub
(
puppet
,
'
contactPayloadCache
'
).
returns
({})
const
MOCK_USER_ID
=
'
TEST-USER-ID
'
puppet
.
login
(
MOCK_USER_ID
)
...
...
@@ -257,15 +267,17 @@ test('self()', async t => {
}
sandbox
.
stub
(
puppet
,
'
messagePayload
'
).
callsFake
(
mockMessagePayload
)
sandbox
.
stub
(
puppet
,
'
messagePayloadCache
'
).
callsFake
(
mockMessagePayload
)
sandbox
.
stub
(
puppet
,
'
messageRawPayload
'
).
resolves
({})
sandbox
.
stub
(
puppet
,
'
roomPayload
'
).
resolves
({})
sandbox
.
stub
(
puppet
,
'
roomPayloadCache
'
).
returns
({})
sandbox
.
stub
(
puppet
,
'
contactPayload
'
).
resolves
({})
const
selfIdStub
=
sandbox
.
stub
(
puppet
,
'
selfId
'
).
returns
(
MOCK_CONTACT
.
id
)
sandbox
.
stub
(
puppet
,
'
contactPayloadCache
'
).
returns
({}
)
// XXX
// function isNonExistentOwnProperty(object, property) {
// return object && typeof property !== "undefined" && !(property in object);
// }
const
selfIdStub
=
sandbox
.
stub
(
puppet
,
'
selfId
'
).
returns
(
MOCK_CONTACT
.
id
)
puppet
.
login
(
MOCK_USER_ID
)
...
...
src/puppet-puppeteer/puppeteer-room.spec.ts
浏览文件 @
b41af29e
...
...
@@ -42,6 +42,12 @@ import {
WebRoomRawPayload
,
}
from
'
./web-schemas
'
class
WechatyTest
extends
Wechaty
{
public
initPuppetAccessory
(
puppet
:
PuppetPuppeteer
)
{
super
.
initPuppetAccessory
(
puppet
)
}
}
// tslint:disable:max-line-length
const
ROOM_RAW_PAYLOAD
:
WebRoomRawPayload
=
JSON
.
parse
(
`{"RemarkPYQuanPin":"","RemarkPYInitial":"","PYInitial":"TZZGQNTSHGFJ","PYQuanPin":"tongzhizhongguoqingniantianshihuiguanfangjia","Uin":0,"UserName":"@@e2355db381dc46a77c0b95516d05e7486135cb6370d8a6af66925d89d50ec278","NickName":"(通知)中国青年天使会官方家","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgetheadimg?seq=670397504&username=@@e2355db381dc46a77c0b95516d05e7486135cb6370d8a6af66925d89d50ec278&skey=","ContactFlag":2,"MemberCount":146,"MemberList":[{"Uin":0,"UserName":"@ecff4a7a86f23455dc42317269aa36ab","NickName":"童玮亮","AttrStatus":103423,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"dap","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@ecff4a7a86f23455dc42317269aa36ab&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@eac4377ecfd59e4321262f892177169f","NickName":"麦刚","AttrStatus":33674247,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"mai","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@eac4377ecfd59e4321262f892177169f&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@ad85207730aa94e006ddce28f74e6878","NickName":"田美坤Maggie","AttrStatus":112679,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"田美坤","KeyWord":"tia","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@ad85207730aa94e006ddce28f74e6878&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":2351423900,"UserName":"@33cc239d22b20d56395bbbd0967b28b9","NickName":"周宏光","AttrStatus":327869,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"周宏光","KeyWord":"acc","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@33cc239d22b20d56395bbbd0967b28b9&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@5e77381e1e3b5641ddcee44670b6e83a","NickName":"牛文文","AttrStatus":100349,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"niu","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@5e77381e1e3b5641ddcee44670b6e83a&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@56941ef97f3e9c70af88667fdd613b44","NickName":"羊东 东方红酒窖","AttrStatus":33675367,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"Yan","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@56941ef97f3e9c70af88667fdd613b44&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@72c4767ce32db488871fdd1c27173b81","NickName":"李竹~英诺天使(此号已满)","AttrStatus":235261,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"liz","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@72c4767ce32db488871fdd1c27173b81&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@0b0e2eb9501ab2d84f9f800f6a0b4216","NickName":"周静彤 杨宁助理","AttrStatus":230885,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"zlo","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@0b0e2eb9501ab2d84f9f800f6a0b4216&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@4bfa767be0cd3fb78409b9735d1dcc57","NickName":"周哲 Jeremy","AttrStatus":33791995,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"zho","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@4bfa767be0cd3fb78409b9735d1dcc57&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"},{"Uin":0,"UserName":"@ad954bf2159a572b7743a5bc134739f4","NickName":"vicky张","AttrStatus":100477,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"","KeyWord":"hua","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@ad954bf2159a572b7743a5bc134739f4&skey=@crypt_f9cec94b_f23a307a23231cfb5098faf91ff759ca&chatroomid=@4b8baa99bdfc354443711412126d2aaf"}],"RemarkName":"","HideInputBarFlag":0,"Sex":0,"Signature":"","VerifyFlag":0,"OwnerUin":2351423900,"StarFriend":0,"AppAccountFlag":0,"Statues":0,"AttrStatus":0,"Province":"","City":"","Alias":"","SnsFlag":0,"UniFriend":0,"DisplayName":"","ChatRoomId":0,"KeyWord":"","EncryChatRoomId":"@4b8baa99bdfc354443711412126d2aaf","MMFromBatchGet":true,"MMOrderSymbol":"TONGZHIZHONGGUOQINGNIANTIANSHIHUIGUANFANGJIA","MMFromBatchget":true,"MMInChatroom":true}`
)
const
CONTACT_RAW_PAYLOAD_DICT
=
JSON
.
parse
(
`{"@ad85207730aa94e006ddce28f74e6878":{ "UserName": "@ad85207730aa94e006ddce28f74e6878","NickName": "田美坤Maggie","RemarkName": "" },"@72c4767ce32db488871fdd1c27173b81":{ "UserName": "@72c4767ce32db488871fdd1c27173b81","NickName": "李竹~英诺天使(此号已满)","RemarkName": "" },"@ecff4a7a86f23455dc42317269aa36ab":{ "UserName": "@ecff4a7a86f23455dc42317269aa36ab","NickName": "童玮亮","RemarkName": "童玮亮备注" }}`
)
...
...
@@ -103,22 +109,22 @@ test('Room smok testing', async t => {
t
.
is
(
room
.
topic
(),
ROOM_EXPECTED
.
topic
,
'
should set topic/NickName
'
)
const
contact1
=
new
wechaty
.
Contact
(
ROOM_EXPECTED
.
memberId1
)
const
alias1
=
room
.
alias
(
contact1
)
const
alias1
=
await
room
.
alias
(
contact1
)
t
.
is
(
alias1
,
ROOM_EXPECTED
.
memberNick1
,
'
should get roomAlias
'
)
// const name1 = r.alias(contact1)
// t.is(name1, EXPECTED.memberNick1, 'should get roomAlias')
const
contact2
=
wechaty
.
Contact
.
load
(
ROOM_EXPECTED
.
memberId2
)
const
alias2
=
room
.
alias
(
contact2
)
const
alias2
=
await
room
.
alias
(
contact2
)
t
.
is
(
alias2
,
null
,
'
should return null if not set roomAlias
'
)
// const name2 = r.alias(contact2)
// t.is(name2, null, 'should return null if not set roomAlias')
t
.
ok
(
room
.
has
(
contact1
)
,
'
should has contact1
'
)
t
.
equal
(
await
room
.
has
(
contact1
),
true
,
'
should has contact1
'
)
const
noSuchContact
=
wechaty
.
Contact
.
load
(
'
not exist id
'
)
t
.
false
(
room
.
has
(
noSuchContact
)
,
'
should has no this member
'
)
t
.
equal
(
await
room
.
has
(
noSuchContact
),
false
,
'
should has no this member
'
)
const
owner
=
room
.
owner
()
t
.
true
(
owner
===
null
||
owner
instanceof
wechaty
.
Contact
,
'
should get Contact instance for owner, or null
'
)
...
...
@@ -154,31 +160,27 @@ test('Room smok testing', async t => {
sandbox
.
restore
()
})
test
(
'
Room static method
'
,
async
t
=>
{
// MyRoom.puppet = new PuppetPuppeteer({
// profile: new Profile(),
// wechaty: new Wechaty(),
// })
// test('Room static method', async t => {
const
puppet
=
new
PuppetPuppeteer
({
memory
:
new
MemoryCard
(),
// wechaty,
})
const
wechaty
=
new
Wechaty
({
puppet
}
)
//
const puppet = new PuppetPuppeteer({
//
memory: new MemoryCard(),
// })
// const wechaty = new WechatyTest({ puppet
})
// wechaty.initPuppetAccessory(puppet
)
try
{
const
result
=
await
wechaty
.
Room
.
find
({
topic
:
'
xxx
'
})
t
.
is
(
result
,
null
,
`should return null if cannot find the room`
)
}
catch
(
e
)
{
t
.
pass
(
'
should throw before login or not found
'
)
}
//
try {
//
const result = await wechaty.Room.find({ topic: 'xxx' })
//
t.is(result, null, `should return null if cannot find the room`)
//
} catch (e) {
//
t.pass('should throw before login or not found')
//
}
const
roomList
=
await
wechaty
.
Room
.
findAll
({
topic
:
'
yyy
'
,
})
//
const roomList = await wechaty.Room.findAll({
//
topic: 'yyy',
//
})
t
.
is
(
roomList
.
length
,
0
,
'
should return empty array before login
'
)
})
//
t.is(roomList.length, 0, 'should return empty array before login')
//
})
test
(
'
Room iterator for contact in it
'
,
async
t
=>
{
// Mock
...
...
@@ -202,11 +204,6 @@ test('Room iterator for contact in it', async t => {
memory
:
new
MemoryCard
(),
})
class
WechatyTest
extends
Wechaty
{
public
initPuppetAccessory
(
puppet
:
PuppetPuppeteer
)
{
super
.
initPuppetAccessory
(
puppet
)
}
}
const
wechaty
=
new
WechatyTest
({
puppet
})
wechaty
.
initPuppetAccessory
(
puppet
)
...
...
src/room.ts
浏览文件 @
b41af29e
...
...
@@ -189,6 +189,10 @@ export class Room extends Accessory implements Sayable {
*
*/
protected
get
payload
():
undefined
|
RoomPayload
{
if
(
!
this
.
id
)
{
return
undefined
}
const
readyPayload
=
this
.
puppet
.
roomPayloadCache
(
this
.
id
)
return
readyPayload
}
...
...
@@ -537,7 +541,7 @@ export class Room extends Accessory implements Sayable {
* }
* })
*/
public
a
lias
(
contact
:
Contact
):
null
|
string
{
public
a
sync
alias
(
contact
:
Contact
):
Promise
<
null
|
string
>
{
return
this
.
roomAlias
(
contact
)
}
...
...
@@ -546,9 +550,9 @@ export class Room extends Accessory implements Sayable {
* @param {Contact} contact
* @returns {(string | null)}
*/
public
roomAlias
(
contact
:
Contact
):
null
|
string
{
public
async
roomAlias
(
contact
:
Contact
):
Promise
<
null
|
string
>
{
const
memberPayload
=
this
.
puppet
.
roomMemberPayloadCache
(
this
.
id
,
contact
.
id
)
const
memberPayload
=
await
this
.
puppet
.
roomMemberPayload
(
this
.
id
,
contact
.
id
)
if
(
memberPayload
&&
memberPayload
.
roomAlias
)
{
return
memberPayload
.
roomAlias
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录