Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
bc6299cd
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,发现更多精彩内容 >>
提交
bc6299cd
编写于
8月 11, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Message.find() (#1534)
上级
0e6052ef
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
72 addition
and
28 deletion
+72
-28
src/user/message.ts
src/user/message.ts
+72
-28
未找到文件。
src/user/message.ts
浏览文件 @
bc6299cd
...
...
@@ -16,41 +16,40 @@
* limitations under the License.
* @ignore
*/
// import path from 'path'
// import cuid from 'cuid'
import
{
instanceToClass
,
}
from
'
clone-class
'
}
from
'
clone-class
'
import
{
FileBox
,
}
from
'
file-box
'
}
from
'
file-box
'
import
{
MessagePayload
,
MessageQueryFilter
,
MessageType
,
}
from
'
wechaty-puppet
'
import
{
Accessory
,
}
from
'
../accessory
'
}
from
'
../accessory
'
import
{
FOUR_PER_EM_SPACE
,
log
,
}
from
'
../config
'
Raven
,
}
from
'
../config
'
import
{
Sayable
,
}
from
'
../types
'
}
from
'
../types
'
import
{
Contact
,
}
from
'
./contact
'
}
from
'
./contact
'
import
{
Room
,
}
from
'
./room
'
}
from
'
./room
'
import
{
UrlLink
,
}
from
'
./url-link
'
import
{
MessagePayload
,
MessageType
,
}
from
'
wechaty-puppet
'
}
from
'
./url-link
'
/**
* All wechat messages will be encapsulated as a Message.
...
...
@@ -77,9 +76,24 @@ export class Message extends Accessory implements Sayable {
*/
public
static
async
find
<
T
extends
typeof
Message
>
(
this
:
T
,
query
:
any
,
query
:
string
|
MessageQueryFilter
,
):
Promise
<
T
[
'
prototype
'
]
|
null
>
{
return
(
await
this
.
findAll
(
query
))[
0
]
log
.
verbose
(
'
Message
'
,
'
find(%s)
'
,
JSON
.
stringify
(
query
))
if
(
typeof
query
===
'
string
'
)
{
query
=
{
text
:
query
}
}
const
messageList
=
await
this
.
findAll
(
query
)
if
(
messageList
.
length
<
1
)
{
return
null
}
if
(
messageList
.
length
>
1
)
{
log
.
warn
(
'
Message
'
,
'
findAll() got more than one(%d) result
'
,
messageList
.
length
)
}
return
messageList
[
0
]
}
/**
...
...
@@ -87,14 +101,34 @@ export class Message extends Accessory implements Sayable {
* @todo add function
*/
public
static
async
findAll
<
T
extends
typeof
Message
>
(
this
:
T
,
query
:
any
,
this
:
T
,
query
?:
MessageQueryFilter
,
):
Promise
<
Array
<
T
[
'
prototype
'
]
>>
{
log
.
verbose
(
'
Message
'
,
'
findAll(%s)
'
,
query
)
return
[
new
(
this
as
any
)({
MsgId
:
'
id1
'
}),
new
(
this
as
any
)({
MsdId
:
'
id2
'
}),
]
log
.
verbose
(
'
Message
'
,
'
findAll(%s)
'
,
JSON
.
stringify
(
query
))
try
{
const
MessageIdList
=
await
this
.
puppet
.
messageSearch
(
query
)
const
messageList
=
MessageIdList
.
map
(
id
=>
this
.
load
(
id
))
await
Promise
.
all
(
messageList
.
map
(
message
=>
{
try
{
return
message
.
ready
()
}
catch
(
e
)
{
return
{}
as
any
}
},
),
)
return
messageList
.
filter
(
message
=>
!!
message
.
id
)
}
catch
(
e
)
{
log
.
verbose
(
'
Message
'
,
'
findAll() rejected: %s
'
,
e
.
message
)
console
.
error
(
e
)
Raven
.
captureException
(
e
)
return
[]
// fail safe
}
}
/**
...
...
@@ -103,9 +137,8 @@ export class Message extends Accessory implements Sayable {
* "mobile originated" or "mobile terminated"
* https://www.tatango.com/resources/video-lessons/video-mo-mt-sms-messaging/
*/
// TODO: rename create to load ??? Huan 201806
public
static
create
(
id
:
string
):
Message
{
log
.
verbose
(
'
Message
'
,
'
static create(%s)
'
,
id
)
public
static
load
(
id
:
string
):
Message
{
log
.
verbose
(
'
Message
'
,
'
static load(%s)
'
,
id
)
/**
* Must NOT use `Message` at here
...
...
@@ -118,6 +151,17 @@ export class Message extends Accessory implements Sayable {
return
msg
}
/**
* TODO: rename create to load ??? Huan 201806
* @deprecated: use load() instead
* @private
*/
public
static
create
(
id
:
string
):
Message
{
log
.
warn
(
'
Message
'
,
'
static create(%s) DEPRECATED. Use load() instead
'
,
id
)
return
this
.
load
(
id
)
}
/**
*
* Instance Properties
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录