Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
feb80397
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,发现更多精彩内容 >>
提交
feb80397
编写于
5月 20, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add image message class
上级
5ae7e2dc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
25 deletion
+48
-25
src/message.js
src/message.js
+48
-25
未找到文件。
src/message.js
浏览文件 @
feb80397
...
...
@@ -13,7 +13,7 @@ const log = require('npmlog')
class
Message
{
constructor
(
rawObj
)
{
Message
.
counter
++
;
Message
.
counter
++
this
.
rawObj
=
rawObj
=
rawObj
||
{}
this
.
obj
=
this
.
parse
(
rawObj
)
...
...
@@ -35,25 +35,24 @@ class Message {
}
}
toString
()
{
const
name
=
html2str
(
this
.
obj
.
from
.
get
(
'
name
'
))
toString
()
{
return
`Message#
${
Message
.
counter
}
(`
+
this
.
getFromString
()
+
`:
${
content
}
)`
}
getFromString
()
{
const
name
=
this
.
obj
.
from
.
get
(
'
name
'
)
const
group
=
this
.
obj
.
group
let
content
=
html2str
(
this
.
obj
.
content
)
if
(
content
.
length
>
20
)
content
=
content
.
substring
(
0
,
17
)
+
'
...
'
;
let
groupStr
=
group
?
html2str
(
group
)
:
''
let
fromStr
=
'
<
'
+
name
+
(
groupStr
?
`@[
${
groupStr
}
]`
:
''
)
+
'
>
'
return
`Message#
${
Message
.
counter
}
(
${
fromStr
}
:
${
content
}
)`
function
html2str
(
html
)
{
return
String
(
html
)
.
replace
(
/
(
<
([^
>
]
+
)
>
)
/ig
,
''
)
.
replace
(
/'/g
,
"
'
"
)
.
replace
(
/"/g
,
'
"
'
)
.
replace
(
/>/g
,
'
>
'
)
.
replace
(
/</g
,
'
<
'
)
.
replace
(
/&/g
,
'
&
'
)
}
}
let
content
=
this
.
unescapeHtml
(
this
.
stripHtml
(
this
.
obj
.
content
))
if
(
content
.
length
>
20
)
{
content
=
content
.
substring
(
0
,
17
)
+
'
...
'
}
return
'
<
'
+
name
+
(
group
?
`@[
${
group
}
]`
:
''
)
+
'
>
'
}
stripHtml
(
str
)
{
return
String
(
str
).
replace
(
/
(
<
([^
>
]
+
)
>
)
/ig
,
''
)
}
unescapeHtml
(
str
)
{
return
String
(
str
)
.
replace
(
/'/g
,
"
'
"
)
.
replace
(
/"/g
,
'
"
'
)
.
replace
(
/>/g
,
'
>
'
)
.
replace
(
/</g
,
'
<
'
)
.
replace
(
/&/g
,
'
&
'
)
}
ready
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -80,16 +79,16 @@ class Message {
return
this
}
dump
()
{
console
.
error
(
'
======= dump message =======
'
)
Object
.
keys
(
this
.
obj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
obj
[
k
]}
`
))
dump
()
{
console
.
error
(
'
======= dump message =======
'
)
Object
.
keys
(
this
.
obj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
obj
[
k
]}
`
))
}
dumpRaw
()
{
dumpRaw
()
{
console
.
error
(
'
======= dump raw message =======
'
)
Object
.
keys
(
this
.
rawObj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
rawObj
[
k
]}
`
))
Object
.
keys
(
this
.
rawObj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
rawObj
[
k
]}
`
))
}
getC
ount
()
{
return
Message
.
counter
}
c
ount
()
{
return
Message
.
counter
}
static
find
(
selector
,
option
)
{
return
new
Message
({
MsgId
:
'
-1
'
})
...
...
@@ -104,5 +103,29 @@ class Message {
}
Message
.
counter
=
0
Message
.
Type
=
{
TEXT
:
1
,
IMAGE
:
3
,
VOICE
:
34
,
VIDEO
:
43
,
MICROVIDEO
:
62
,
EMOTICON
:
47
,
APP
:
49
,
VOIPMSG
:
50
,
VOIPNOTIFY
:
52
,
VOIPINVITE
:
53
,
LOCATION
:
48
,
STATUSNOTIFY
:
51
,
SYSNOTICE
:
9999
,
POSSIBLEFRIEND_MSG
:
40
,
VERIFYMSG
:
37
,
SHARECARD
:
42
,
SYS
:
1
e4
,
RECALLED
:
10002
}
Object
.
keys
(
Message
.
Type
).
forEach
(
k
=>
{
const
v
=
Message
.
Type
[
k
]
Message
.
Type
[
v
]
=
k
// Message.Type[1] = 'TEXT'
})
module
.
exports
=
Message
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录