Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
de20b5a3
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,体验更适合开发者的 AI 搜索 >>
提交
de20b5a3
编写于
10月 13, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#44 overload methods for better doc
上级
1f31f49b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
11 deletion
+29
-11
README.md
README.md
+3
-3
src/message.ts
src/message.ts
+26
-8
未找到文件。
README.md
浏览文件 @
de20b5a3
...
...
@@ -472,15 +472,15 @@ wechaty.reply(message, 'roger')
All wechat messages will be encaped as a Message.
### Message.from(contact?: Contact): Contact
### Message.from(contact?: Contact
|string
): Contact
get the sender from message, or set it.
### Message.to(contact?: Contact|Room): Contact|Room
### Message.to(contact?: Contact|Room
|string
): Contact|Room
get the receiver from a message, or set it.
### Message.room(room?: Room): Room
### Message.room(room?: Room
|string
): Room
get the room from a message, or set it.
...
...
src/message.ts
浏览文件 @
de20b5a3
...
...
@@ -49,6 +49,7 @@ type MessageType = {
class
Message
{
public
static
counter
=
0
private
_counter
:
number
public
static
TYPE
:
MessageType
=
{
TEXT
:
1
,
...
...
@@ -80,7 +81,7 @@ class Message {
}
constructor
(
public
rawObj
?:
MessageRawObj
)
{
Message
.
counter
++
this
.
_counter
=
Message
.
counter
++
if
(
typeof
rawObj
===
'
string
'
)
{
this
.
rawObj
=
JSON
.
parse
(
rawObj
)
...
...
@@ -128,7 +129,7 @@ class Message {
}
public
toStringEx
()
{
let
s
=
`
${
this
.
constructor
.
name
}
#
${
Message
.
counter
}
`
let
s
=
`
${
this
.
constructor
.
name
}
#
${
this
.
_
counter
}
`
s
+=
'
(
'
+
this
.
getSenderString
()
s
+=
'
:
'
+
this
.
getContentString
()
+
'
)
'
return
s
...
...
@@ -144,6 +145,8 @@ class Message {
return
'
{
'
+
this
.
type
()
+
'
}
'
+
content
}
public
from
(
contact
?:
Contact
):
Contact
public
from
(
id
?:
string
):
Contact
public
from
(
contact
?:
Contact
|
string
):
Contact
{
if
(
contact
)
{
if
(
contact
instanceof
Contact
)
{
...
...
@@ -157,7 +160,10 @@ class Message {
return
this
.
obj
.
from
?
Contact
.
load
(
this
.
obj
.
from
)
:
null
}
public
to
(
contact
?:
Contact
|
Room
|
string
):
Contact
{
public
to
(
contact
?:
Contact
):
Contact
public
to
(
room
?:
Room
):
Room
public
to
(
id
?:
string
):
Contact
|
Room
public
to
(
contact
?:
Contact
|
Room
|
string
):
Contact
|
Room
{
if
(
contact
)
{
if
(
contact
instanceof
Contact
||
contact
instanceof
Room
)
{
this
.
obj
.
to
=
contact
.
id
...
...
@@ -167,9 +173,18 @@ class Message {
throw
new
Error
(
'
unsupport to param
'
+
typeof
contact
)
}
}
return
this
.
obj
.
to
?
Contact
.
load
(
this
.
obj
.
to
)
:
null
if
(
!
this
.
obj
.
to
)
{
return
null
}
// FIXME: better to identify a room id?
return
/^@@/
.
test
(
this
.
obj
.
to
)
?
Room
.
load
(
this
.
obj
.
to
)
:
Contact
.
load
(
this
.
obj
.
to
)
}
public
room
(
room
?:
Room
):
Room
public
room
(
id
?:
string
):
Room
public
room
(
room
?:
Room
|
string
):
Room
{
if
(
room
)
{
if
(
room
instanceof
Room
)
{
...
...
@@ -183,7 +198,7 @@ class Message {
return
this
.
obj
.
room
?
Room
.
load
(
this
.
obj
.
room
)
:
null
}
public
content
(
content
?)
{
public
content
(
content
?
:
string
)
{
if
(
content
)
{
this
.
obj
.
content
=
content
}
...
...
@@ -192,7 +207,7 @@ class Message {
public
type
()
{
return
this
.
obj
.
type
}
public
typeEx
()
{
return
Message
.
TYPE
[
this
.
obj
.
type
]
}
public
count
()
{
return
Message
.
counter
}
public
count
()
{
return
this
.
_
counter
}
public
async
ready
():
Promise
<
this
>
{
log
.
silly
(
'
Message
'
,
'
ready()
'
)
...
...
@@ -218,7 +233,7 @@ class Message {
}
}
public
get
(
prop
):
string
{
public
get
(
prop
:
string
):
string
{
if
(
!
prop
||
!
(
prop
in
this
.
obj
))
{
const
s
=
'
[
'
+
Object
.
keys
(
this
.
obj
).
join
(
'
,
'
)
+
'
]
'
throw
new
Error
(
`Message.get(
${
prop
}
) must be in:
${
s
}
`
)
...
...
@@ -226,7 +241,10 @@ class Message {
return
this
.
obj
[
prop
]
}
public
set
(
prop
,
value
)
{
public
set
(
prop
:
string
,
value
:
string
):
this
{
if
(
typeof
value
!==
'
string
'
)
{
throw
new
Error
(
'
value must be string, we got:
'
+
typeof
value
)
}
this
.
obj
[
prop
]
=
value
return
this
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录