Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
b36c6f63
W
wechaty
项目概览
weixin_46011646
/
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,发现更多精彩内容 >>
提交
b36c6f63
编写于
11月 12, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BREAKING CHANGE: message.to() will not work with Room. use message.room() instead. #88
上级
f38fac07
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
39 deletion
+38
-39
src/message.ts
src/message.ts
+25
-23
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+13
-15
src/room.ts
src/room.ts
+0
-1
未找到文件。
src/message.ts
浏览文件 @
b36c6f63
...
...
@@ -119,7 +119,7 @@ export type MessageObj = {
id
:
string
type
:
number
from
:
string
to
:
string
to
?:
string
// if to is not set, then room must be set
room
?:
string
content
:
string
status
:
string
...
...
@@ -235,7 +235,7 @@ export class Message implements Sayable {
// Transform rawObj to local m
private
parse
(
rawObj
):
MessageObj
{
const
obj
:
MessageObj
=
{
id
:
rawObj
.
MsgId
,
id
:
rawObj
.
MsgId
,
type
:
rawObj
.
MsgType
,
from
:
rawObj
.
MMActualSender
,
// MMPeerUserName
to
:
rawObj
.
ToUserName
,
...
...
@@ -256,8 +256,9 @@ export class Message implements Sayable {
log
.
error
(
'
Message
'
,
'
parse found a room message, but neither FromUserName nor ToUserName is a room(/^@@/)
'
)
// obj.room = undefined // bug compatible
}
// } else {
// obj.room = undefined
if
(
obj
.
to
&&
/^@@/
.
test
(
obj
.
to
))
{
// if a message in room without any specific receiver, then it will set to be `undefined`
obj
.
to
=
undefined
}
}
return
obj
...
...
@@ -311,13 +312,16 @@ export class Message implements Sayable {
return
loadedContact
}
// public to(room: Room): void
// public to(): Contact|Room
// public to(contact?: Contact|Room|string): Contact|Room|void {
public
to
(
contact
:
Contact
):
void
public
to
(
room
:
Room
):
void
public
to
(
id
:
string
):
void
public
to
():
Contact
|
Room
public
to
(
contact
?:
Contact
|
Room
|
string
):
Contact
|
Room
|
void
{
public
to
():
Contact
|
null
// if to is not set, then room must had set
public
to
(
contact
?:
Contact
|
string
):
Contact
|
Room
|
null
|
void
{
if
(
contact
)
{
if
(
contact
instanceof
Contact
||
contact
instanceof
Room
)
{
if
(
contact
instanceof
Contact
)
{
this
.
obj
.
to
=
contact
.
id
}
else
if
(
typeof
contact
===
'
string
'
)
{
this
.
obj
.
to
=
contact
...
...
@@ -327,14 +331,10 @@ export class Message implements Sayable {
return
}
// FIXME: better to identify a room id?
const
loadedInstance
=
/^@@/
.
test
(
this
.
obj
.
to
)
?
Room
.
load
(
this
.
obj
.
to
)
:
Contact
.
load
(
this
.
obj
.
to
)
if
(
!
loadedInstance
)
{
throw
new
Error
(
'
no to
'
)
if
(
!
this
.
obj
.
to
)
{
return
null
}
return
loadedInstance
return
Contact
.
load
(
this
.
obj
.
to
)
}
public
room
(
room
:
Room
):
void
...
...
@@ -402,17 +402,19 @@ export class Message implements Sayable {
try
{
const
from
=
Contact
.
load
(
this
.
obj
.
from
)
const
to
=
Contact
.
load
(
this
.
obj
.
to
)
const
room
=
this
.
obj
.
room
?
Room
.
load
(
this
.
obj
.
room
)
:
null
await
from
.
ready
()
// Contact from
if
(
!
from
||
!
to
)
{
throw
new
Error
(
'
no `from` or no `to`
'
)
if
(
this
.
obj
.
to
)
{
const
to
=
Contact
.
load
(
this
.
obj
.
to
)
await
to
.
ready
()
}
await
from
.
ready
()
// Contact from
await
to
.
ready
()
// Contact to
if
(
room
)
{
await
room
.
ready
()
}
// Room member list
// return this // return this for chain
if
(
this
.
obj
.
room
)
{
const
room
=
Room
.
load
(
this
.
obj
.
room
)
if
(
room
)
{
await
room
.
ready
()
// Room member list
}
}
}
catch
(
e
)
{
log
.
error
(
'
Message
'
,
'
ready() exception: %s
'
,
e
.
stack
)
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
b36c6f63
...
...
@@ -296,27 +296,25 @@ export class PuppetWeb extends Puppet {
const
to
=
message
.
to
()
const
room
=
message
.
room
()
let
content
=
message
.
content
()
const
content
=
message
.
content
()
let
destinationId
if
(
to
)
{
destinationId
=
to
.
id
}
let
destination
:
Contact
|
Room
=
to
if
(
room
)
{
destination
=
room
// TODO use the right @
// if (to && to!==room) {
// content = `@[${to}] ${content}`
// }
if
(
!
to
)
{
message
.
to
(
room
)
}
destinationId
=
room
.
id
}
log
.
silly
(
'
PuppetWeb
'
,
'
send() destination: %s, content: %s)
'
,
room
?
room
.
topic
()
:
(
to
as
Contact
).
name
()
,
content
log
.
silly
(
'
PuppetWeb
'
,
'
send() destination: %s, content: %s)
'
,
// , room ? room.topic() : (to as Contact).name()
destinationId
,
content
,
)
try
{
await
this
.
bridge
.
send
(
destination
.
i
d
,
content
)
await
this
.
bridge
.
send
(
destination
I
d
,
content
)
}
catch
(
e
)
{
log
.
error
(
'
PuppetWeb
'
,
'
send() exception: %s
'
,
e
.
message
)
throw
e
...
...
src/room.ts
浏览文件 @
b36c6f63
...
...
@@ -153,7 +153,6 @@ export class Room extends EventEmitter implements Sayable {
if
(
!
replyTo
)
{
m
.
content
(
content
)
m
.
to
(
this
)
return
Config
.
puppetInstance
()
.
send
(
m
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录