Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
bd8c61fc
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,发现更多精彩内容 >>
提交
bd8c61fc
编写于
5月 25, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactoring MessagePayload to use id instead of the instance
上级
b277ecbb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
51 addition
and
29 deletion
+51
-29
src/message.ts
src/message.ts
+23
-8
src/message.type.ts
src/message.type.ts
+3
-3
src/puppet-mock/puppet-mock.ts
src/puppet-mock/puppet-mock.ts
+2
-2
src/puppet-puppeteer/puppet-puppeteer.ts
src/puppet-puppeteer/puppet-puppeteer.ts
+7
-6
src/puppet-puppeteer/puppeteer-message.spec.ts
src/puppet-puppeteer/puppeteer-message.spec.ts
+2
-2
src/puppet/puppet.ts
src/puppet/puppet.ts
+14
-8
未找到文件。
src/message.ts
浏览文件 @
bd8c61fc
...
...
@@ -110,6 +110,9 @@ export class Message extends PuppetAccessory implements Sayable {
const
date
=
new
Date
()
const
file
=
(
options
as
MessageMOOptionsFile
).
file
const
roomId
=
room
&&
room
.
id
const
toId
=
to
&&
to
.
id
if
(
text
)
{
/**
* 1. Text
...
...
@@ -117,8 +120,8 @@ export class Message extends PuppetAccessory implements Sayable {
msg
.
payload
=
{
type
:
MessageType
.
Text
,
direction
,
to
,
room
,
to
Id
,
room
Id
,
text
,
date
,
}
...
...
@@ -154,8 +157,8 @@ export class Message extends PuppetAccessory implements Sayable {
msg
.
payload
=
{
type
,
direction
,
to
,
room
,
to
Id
,
room
Id
,
file
,
date
,
}
...
...
@@ -279,11 +282,12 @@ export class Message extends PuppetAccessory implements Sayable {
// return
// }
const
from
=
this
.
payload
.
from
if
(
!
from
)
{
const
from
Id
=
this
.
payload
.
fromId
if
(
!
from
Id
)
{
throw
new
Error
(
'
no from
'
)
}
const
from
=
this
.
puppet
.
Contact
.
load
(
fromId
)
return
from
}
...
...
@@ -311,7 +315,13 @@ export class Message extends PuppetAccessory implements Sayable {
// return
// }
return
this
.
payload
.
to
||
null
const
toId
=
this
.
payload
.
toId
if
(
!
toId
)
{
return
null
}
const
to
=
this
.
puppet
.
Contact
.
load
(
toId
)
return
to
}
// /**
...
...
@@ -338,8 +348,13 @@ export class Message extends PuppetAccessory implements Sayable {
// this.payload.room = room
// return
// }
const
roomId
=
this
.
payload
.
roomId
if
(
!
roomId
)
{
return
null
}
return
this
.
payload
.
room
||
null
const
room
=
this
.
puppet
.
Room
.
load
(
roomId
)
return
room
}
// /**
...
...
src/message.type.ts
浏览文件 @
bd8c61fc
...
...
@@ -65,8 +65,8 @@ export interface MessagePayload {
text
?
:
string
,
file
?
:
FileBox
,
direction
:
MessageDirection
,
from
?
:
Contact
,
from
Id
?
:
string
,
date
:
Date
,
to
?
:
null
|
Contact
,
// if to is not set, then room must be set
room
?
:
null
|
Room
,
to
Id
?
:
null
|
string
,
// if to is not set, then room must be set
room
Id
?
:
null
|
string
,
}
src/puppet-mock/puppet-mock.ts
浏览文件 @
bd8c61fc
...
...
@@ -198,9 +198,9 @@ export class PuppetMock extends Puppet {
const
payload
:
MessagePayload
=
{
date
:
new
Date
(),
direction
:
this
.
Message
.
Direction
.
MT
,
from
:
this
.
Contact
.
load
(
'
xxx
'
)
,
from
Id
:
'
xxx
'
,
text
:
'
mock message text
'
,
to
:
this
.
userSelf
()
,
to
Id
:
this
.
userSelf
().
id
,
type
:
this
.
Message
.
Type
.
Text
,
}
return
payload
...
...
src/puppet-puppeteer/puppet-puppeteer.ts
浏览文件 @
bd8c61fc
...
...
@@ -348,18 +348,19 @@ export class PuppetPuppeteer extends Puppet {
const
type
:
MessageType
=
this
.
messageTypeFromWeb
(
rawPayload
.
MsgType
)
const
fromId
=
from
&&
from
.
id
const
roomId
=
room
&&
room
.
id
const
toId
=
to
&&
to
.
id
const
payload
:
MessagePayload
=
{
direction
:
MessageDirection
.
MT
,
type
,
from
,
to
,
room
,
from
Id
,
to
Id
,
room
Id
,
text
,
// status: rawPayload.Status,
// digest: rawPayload.MMDigest,
date
,
file
,
// url: rawPayload.Url || rawObj.MMAppMsgDownloadUrl || rawObj.MMLocationUrl,
}
// TODO: parse the url to FileBox
...
...
src/puppet-puppeteer/puppeteer-message.spec.ts
浏览文件 @
bd8c61fc
...
...
@@ -253,8 +253,8 @@ test('self()', async t => {
function
mockMessagePayload
()
{
const
payload
:
MessagePayload
=
{
from
:
MOCK_CONTACT
,
to
:
{}
as
any
,
from
Id
:
MOCK_CONTACT
.
id
,
to
Id
:
'
to_id
'
,
type
:
{}
as
any
,
direction
:
{}
as
any
,
date
:
{}
as
any
,
...
...
src/puppet/puppet.ts
浏览文件 @
bd8c61fc
...
...
@@ -303,19 +303,25 @@ export abstract class Puppet extends EventEmitter implements Sayable {
const
rawPayload
=
await
this
.
messageRawPayload
(
id
)
const
payload
=
await
this
.
messageRawPayloadParser
(
rawPayload
)
console
.
log
(
'
this.messageRawPayloadParser().payload.from.puppet =
'
,
payload
.
from
!
.
puppet
+
''
)
/**
* Make sure all the contacts & room have already been ready
*/
if
(
payload
.
from
&&
!
payload
.
from
.
isReady
())
{
await
payload
.
from
.
ready
()
const
fromId
=
payload
.
fromId
const
roomId
=
payload
.
roomId
const
toId
=
payload
.
toId
const
from
=
fromId
&&
this
.
Contact
.
load
(
fromId
)
const
room
=
roomId
&&
this
.
Room
.
load
(
roomId
)
const
to
=
toId
&&
this
.
Contact
.
load
(
toId
)
if
(
from
&&
!
from
.
isReady
())
{
await
from
.
ready
()
}
if
(
payload
.
to
&&
!
payload
.
to
.
isReady
())
{
await
payload
.
to
.
ready
()
if
(
to
&&
!
to
.
isReady
())
{
await
to
.
ready
()
}
if
(
payload
.
room
&&
!
payload
.
room
.
isReady
())
{
await
payload
.
room
.
ready
()
if
(
room
&&
!
room
.
isReady
())
{
await
room
.
ready
()
}
return
payload
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录