wechaty-puppet-matrix 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/matrix/events/event-friendship.d.ts.map +1 -1
- package/dist/cjs/src/matrix/events/event-message.d.ts.map +1 -1
- package/dist/cjs/src/matrix/events/event-room-invite.d.ts.map +1 -1
- package/dist/cjs/src/matrix/events/event-room-join.d.ts.map +1 -1
- package/dist/cjs/src/matrix/events/event-room-leave.d.ts.map +1 -1
- package/dist/cjs/src/matrix/events/event-room-topic.d.ts.map +1 -1
- package/dist/cjs/src/matrix/service/request.d.ts +3 -0
- package/dist/cjs/src/matrix/service/request.d.ts.map +1 -1
- package/dist/cjs/src/matrix/service/request.js +91 -6
- package/dist/cjs/src/matrix/utils/string.d.ts.map +1 -1
- package/dist/cjs/src/puppet-matrix.d.ts +2 -0
- package/dist/cjs/src/puppet-matrix.d.ts.map +1 -1
- package/dist/cjs/src/puppet-matrix.js +99 -5
- package/dist/cjs/src/utils/normalize-filebox.d.ts.map +1 -1
- package/dist/cjs/src/utils/sns-xml-generator.d.ts.map +1 -1
- package/dist/esm/src/matrix/events/event-friendship.d.ts.map +1 -1
- package/dist/esm/src/matrix/events/event-message.d.ts.map +1 -1
- package/dist/esm/src/matrix/events/event-room-invite.d.ts.map +1 -1
- package/dist/esm/src/matrix/events/event-room-join.d.ts.map +1 -1
- package/dist/esm/src/matrix/events/event-room-leave.d.ts.map +1 -1
- package/dist/esm/src/matrix/events/event-room-topic.d.ts.map +1 -1
- package/dist/esm/src/matrix/service/request.d.ts +3 -0
- package/dist/esm/src/matrix/service/request.d.ts.map +1 -1
- package/dist/esm/src/matrix/service/request.js +91 -6
- package/dist/esm/src/matrix/utils/string.d.ts.map +1 -1
- package/dist/esm/src/puppet-matrix.d.ts +2 -0
- package/dist/esm/src/puppet-matrix.d.ts.map +1 -1
- package/dist/esm/src/puppet-matrix.js +99 -5
- package/dist/esm/src/utils/normalize-filebox.d.ts.map +1 -1
- package/dist/esm/src/utils/sns-xml-generator.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/matrix/service/request.ts +112 -6
- package/src/puppet-matrix.ts +161 -68
package/src/puppet-matrix.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { log }
|
|
2
|
-
import * as PUPPET
|
|
1
|
+
import { log } from '@juzi/wechaty-puppet'
|
|
2
|
+
import * as PUPPET from '@juzi/wechaty-puppet'
|
|
3
3
|
import type { FileBoxInterface } from 'file-box'
|
|
4
4
|
import {
|
|
5
5
|
FileBox,
|
|
6
6
|
FileBoxType,
|
|
7
|
-
}
|
|
7
|
+
} from 'file-box'
|
|
8
8
|
import type { ContactPayload, MessagePayload } from './engine-schema.js'
|
|
9
9
|
import type { FileBoxMetadataMessage } from './matrix/types.js'
|
|
10
10
|
import Client from './matrix/service/request.js'
|
|
@@ -59,7 +59,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
59
59
|
private _verifyInterval?: ReturnType<typeof setInterval> | null
|
|
60
60
|
private _qrcodeStatuasInterval?: ReturnType<typeof setInterval> | null
|
|
61
61
|
private _getQrcodeTimes: number
|
|
62
|
-
|
|
62
|
+
private _roomJoinTemp: Record<string, string> = {}
|
|
63
|
+
public static override readonly VERSION = VERSION
|
|
63
64
|
/**
|
|
64
65
|
* UUIDify:
|
|
65
66
|
* We need to clone a FileBox
|
|
@@ -70,6 +71,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
70
71
|
super(options)
|
|
71
72
|
|
|
72
73
|
this.options.engine = Client
|
|
74
|
+
this._roomJoinTemp = {}
|
|
73
75
|
this._getQrcodeTimes = 0
|
|
74
76
|
this.options.maxGetQrcoderTimes = 20
|
|
75
77
|
|
|
@@ -108,14 +110,14 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
108
110
|
|
|
109
111
|
await this._startPuppetHeart(true)
|
|
110
112
|
if (this._client) {
|
|
111
|
-
this._client.on('login', this.wrapAsync(async ({ robotInfo }
|
|
113
|
+
this._client.on('login', this.wrapAsync(async ({ robotInfo }: { robotInfo: ContactPayload }) => {
|
|
112
114
|
log.info(PRE, `login success: ${robotInfo.name}`)
|
|
113
115
|
await this.onLogin(robotInfo)
|
|
114
116
|
}))
|
|
115
|
-
this._client.on('message', this.wrapAsync(async (message:MessagePayload) => {
|
|
117
|
+
this._client.on('message', this.wrapAsync(async (message: MessagePayload) => {
|
|
116
118
|
await this._onPushMessage(message)
|
|
117
119
|
}))
|
|
118
|
-
this._client.on('contact', this.wrapAsync(async ({ contactInfo }:{ friendShip:PUPPET.payloads.FriendshipReceive, contactInfo: ContactPayload, type: PUPPET.types.Friendship }) => {
|
|
120
|
+
this._client.on('contact', this.wrapAsync(async ({ contactInfo }: { friendShip: PUPPET.payloads.FriendshipReceive, contactInfo: ContactPayload, type: PUPPET.types.Friendship }) => {
|
|
119
121
|
await this._cacheMgr!.setContact(contactInfo.wxid, contactInfo)
|
|
120
122
|
await this._cacheMgr?.setFriendshipRawPayload(contactInfo.wxid, {
|
|
121
123
|
id: contactInfo.wxid,
|
|
@@ -154,12 +156,26 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
154
156
|
this.emit('room-leave', payload)
|
|
155
157
|
}))
|
|
156
158
|
this._client.on('room-join', this.wrapAsync(async ({ roomId, inviterId, joinIds, joinUsers }: { roomId: string, inviterId: string, joinIds: string[], joinUsers: ContactPayload[] }) => {
|
|
159
|
+
|
|
160
|
+
for (const joinId of joinIds) {
|
|
161
|
+
if (this._roomJoinTemp[`${roomId}-${joinId}`]) {
|
|
162
|
+
joinIds = joinIds.filter(id => id !== joinId)
|
|
163
|
+
} else {
|
|
164
|
+
this._roomJoinTemp[`${roomId}-${joinId}`] = joinId
|
|
165
|
+
const temTimer = setTimeout(() => {
|
|
166
|
+
delete this._roomJoinTemp[`${roomId}-${joinId}`]
|
|
167
|
+
clearTimeout(temTimer)
|
|
168
|
+
}, 50000)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
157
172
|
const payload = {
|
|
158
|
-
inviteeIdList
|
|
173
|
+
inviteeIdList: joinIds,
|
|
159
174
|
inviterId,
|
|
160
175
|
roomId,
|
|
161
|
-
timestamp
|
|
176
|
+
timestamp: getUnixTime(Date.now()),
|
|
162
177
|
}
|
|
178
|
+
|
|
163
179
|
for (const joinUser of joinUsers) {
|
|
164
180
|
await this._cacheMgr?.updateSingleRoomMember(roomId, joinUser)
|
|
165
181
|
const roomInfo = await this._cacheMgr?.getRoom(roomId)
|
|
@@ -168,14 +184,17 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
168
184
|
await this._cacheMgr?.setRoom(roomId, roomInfo)
|
|
169
185
|
}
|
|
170
186
|
}
|
|
171
|
-
|
|
187
|
+
|
|
188
|
+
if (joinIds.length) {
|
|
189
|
+
this.emit('room-join', payload)
|
|
190
|
+
}
|
|
172
191
|
}))
|
|
173
192
|
this._client.on('logout', this.wrapAsync(async (message: string) => {
|
|
174
193
|
log.info(PRE, 'Logout event: %s', message)
|
|
175
194
|
await this.logout(message)
|
|
176
195
|
}))
|
|
177
196
|
|
|
178
|
-
this._client.on('verify-code', this.wrapAsync(async ({ ticket, uuid }
|
|
197
|
+
this._client.on('verify-code', this.wrapAsync(async ({ ticket, uuid }: { ticket: string, uuid: string, status: number }) => {
|
|
179
198
|
log.info(PRE, 'verify-code: %s, %s', ticket, uuid)
|
|
180
199
|
this._qrcodeTicket = ticket
|
|
181
200
|
if (!this._verifyInterval) {
|
|
@@ -230,7 +249,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
230
249
|
}
|
|
231
250
|
}
|
|
232
251
|
|
|
233
|
-
private getQrcodeTicket (authurl: string):string {
|
|
252
|
+
private getQrcodeTicket (authurl: string): string {
|
|
234
253
|
if (!authurl || !authurl.startsWith('http')) return ''
|
|
235
254
|
const url = new URL(authurl)
|
|
236
255
|
const searchParams = new URLSearchParams(url.search.slice(1))
|
|
@@ -286,7 +305,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
286
305
|
await this.onQrCodeEvent(scanStatus.status, qrcode.qrcodeUrl)
|
|
287
306
|
}
|
|
288
307
|
|
|
289
|
-
},
|
|
308
|
+
}, 8000)
|
|
290
309
|
} else {
|
|
291
310
|
if (this._getQrcodeTimes && this._getQrcodeTimes > 5) {
|
|
292
311
|
log.info(PRE, '由于多次请求二维码失败,已停止请求,请检查你的网络环境,重启容器后再试。')
|
|
@@ -341,7 +360,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
341
360
|
}
|
|
342
361
|
log.silly(
|
|
343
362
|
PRE,
|
|
344
|
-
|
|
363
|
+
`scan event, status: ${ScanStatusName[scanStatus]}${url ? ', with qrcode: ' + url : ''}`,
|
|
345
364
|
)
|
|
346
365
|
|
|
347
366
|
this.emit('scan', {
|
|
@@ -355,7 +374,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
355
374
|
}
|
|
356
375
|
|
|
357
376
|
// 登录
|
|
358
|
-
private async onLogin (user: ContactPayload):Promise<void> {
|
|
377
|
+
private async onLogin (user: ContactPayload): Promise<void> {
|
|
359
378
|
try {
|
|
360
379
|
// create cache manager firstly
|
|
361
380
|
if (!this._client) {
|
|
@@ -476,7 +495,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
476
495
|
|
|
477
496
|
// 获取自己的二维码
|
|
478
497
|
override async contactSelfQRCode (): Promise<string> {
|
|
479
|
-
return this._client?.getUserQrcode()
|
|
498
|
+
return this._client?.getUserQrcode() || ''
|
|
480
499
|
}
|
|
481
500
|
|
|
482
501
|
// 设置自己的签名 暂不支持
|
|
@@ -490,10 +509,10 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
490
509
|
}
|
|
491
510
|
|
|
492
511
|
// 查询或设置用户备注
|
|
493
|
-
override contactAlias
|
|
494
|
-
override contactAlias
|
|
512
|
+
override contactAlias(contactId: string): Promise<string>
|
|
513
|
+
override contactAlias(contactId: string, alias: string | null): Promise<void>
|
|
495
514
|
|
|
496
|
-
override async contactAlias (contactId
|
|
515
|
+
override async contactAlias (contactId: string, alias?: string | null): Promise<string | void> {
|
|
497
516
|
const contact = await this.contactRawPayload(contactId)
|
|
498
517
|
if (alias) {
|
|
499
518
|
// contact is stranger, set alias in cache, to update after user is added
|
|
@@ -521,10 +540,10 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
521
540
|
}
|
|
522
541
|
|
|
523
542
|
// 获取用户头像
|
|
524
|
-
override async contactAvatar
|
|
525
|
-
override async contactAvatar
|
|
543
|
+
override async contactAvatar(contactId: string): Promise<FileBoxInterface>
|
|
544
|
+
override async contactAvatar(contactId: string, file: FileBoxInterface): Promise<void>
|
|
526
545
|
|
|
527
|
-
override async contactAvatar (contactId: string, file?: FileBoxInterface)
|
|
546
|
+
override async contactAvatar (contactId: string, file?: FileBoxInterface): Promise<void | FileBoxInterface> {
|
|
528
547
|
if (file) {
|
|
529
548
|
return PUPPET.throwUnsupportedError('set avatar is not unsupported')
|
|
530
549
|
}
|
|
@@ -571,12 +590,12 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
571
590
|
}
|
|
572
591
|
|
|
573
592
|
// 删除标签
|
|
574
|
-
override async tagTagDelete (tagIdList: string[])
|
|
593
|
+
override async tagTagDelete (tagIdList: string[]): Promise<void> {
|
|
575
594
|
return PUPPET.throwUnsupportedError(tagIdList)
|
|
576
595
|
}
|
|
577
596
|
|
|
578
597
|
// 获取用户标签
|
|
579
|
-
override async tagTagContactList (contactId?: string)
|
|
598
|
+
override async tagTagContactList (contactId?: string): Promise<string[]> {
|
|
580
599
|
return PUPPET.throwUnsupportedError(contactId)
|
|
581
600
|
}
|
|
582
601
|
|
|
@@ -587,7 +606,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
587
606
|
* 通过好友请求
|
|
588
607
|
* @param friendshipId
|
|
589
608
|
*/
|
|
590
|
-
override async friendshipAccept (friendshipId
|
|
609
|
+
override async friendshipAccept (friendshipId: string): Promise<void> {
|
|
591
610
|
const friendship: PUPPET.payloads.FriendshipReceive = (await this.friendshipRawPayload(
|
|
592
611
|
friendshipId,
|
|
593
612
|
)) as PUPPET.payloads.FriendshipReceive
|
|
@@ -650,7 +669,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
650
669
|
hello = (option as any).hello
|
|
651
670
|
}
|
|
652
671
|
}
|
|
653
|
-
await this._client?.addFriendByWxid({ content: hello, ticket,
|
|
672
|
+
await this._client?.addFriendByWxid({ content: hello, ticket, scene: addContactScene, wxid: contactId })
|
|
654
673
|
}
|
|
655
674
|
|
|
656
675
|
/**
|
|
@@ -675,7 +694,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
675
694
|
* @param scene 场景值 1=qq 3=微信号 6=单向添加 10和13=通讯录 14=群聊 15=手机号 17=名片 30=扫一扫
|
|
676
695
|
* @private
|
|
677
696
|
*/
|
|
678
|
-
private async _friendshipSearch (id: string, scene?:string): Promise<null | string> {
|
|
697
|
+
private async _friendshipSearch (id: string, scene?: string): Promise<null | string> {
|
|
679
698
|
const cachedContactSearch = await this._cacheMgr!.getContactSearch(id)
|
|
680
699
|
if (cachedContactSearch) {
|
|
681
700
|
return id
|
|
@@ -815,7 +834,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
815
834
|
* 解析h5链接
|
|
816
835
|
* @param messageId
|
|
817
836
|
*/
|
|
818
|
-
override async messageUrl (messageId: string)
|
|
837
|
+
override async messageUrl (messageId: string): Promise<PUPPET.payloads.UrlLink> {
|
|
819
838
|
const rawPayload = await this.messageRawPayload(messageId)
|
|
820
839
|
const payload = await this.messageRawPayloadParser(rawPayload)
|
|
821
840
|
|
|
@@ -837,7 +856,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
837
856
|
* 解析h5链接
|
|
838
857
|
* @param messageId
|
|
839
858
|
*/
|
|
840
|
-
override async messageLocation (messageId: string)
|
|
859
|
+
override async messageLocation (messageId: string): Promise<PUPPET.payloads.Location> {
|
|
841
860
|
const rawPayload = await this.messageRawPayload(messageId)
|
|
842
861
|
const payload = await this.messageRawPayloadParser(rawPayload)
|
|
843
862
|
|
|
@@ -888,9 +907,9 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
888
907
|
const metadata: FileBoxMetadataMessage = fileBox.metadata as FileBoxMetadataMessage
|
|
889
908
|
|
|
890
909
|
const fileType
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
910
|
+
= fileBox.mediaType && fileBox.mediaType !== 'application/octet-stream'
|
|
911
|
+
? fileBox.mediaType
|
|
912
|
+
: path.extname(fileBox.name)
|
|
894
913
|
|
|
895
914
|
// @ts-ignore
|
|
896
915
|
const fileUrl = fileBox.remoteUrl || ''
|
|
@@ -908,7 +927,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
908
927
|
}
|
|
909
928
|
} else if (fileBox.mediaType === 'audio/silk') {
|
|
910
929
|
PUPPET.throwUnsupportedError(conversationId, fileBox)
|
|
911
|
-
} else if (fileType.includes('video/mp4') ||
|
|
930
|
+
} else if (fileType.includes('video/mp4') || fileType.includes('.mp4')) {
|
|
912
931
|
const msgInfo = await this._client?.sendVideo(conversationId, fileUrl, this._self?.wxid)
|
|
913
932
|
if (msgInfo) {
|
|
914
933
|
await this._cacheMgr?.setMessage(msgInfo.id, msgInfo)
|
|
@@ -1054,8 +1073,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1054
1073
|
***************************************************************************/
|
|
1055
1074
|
|
|
1056
1075
|
// 拉人进群
|
|
1057
|
-
override async roomAdd (roomId
|
|
1058
|
-
let type:number = 1 // 1 直接拉 2 发送邀请链接 人数超过40需要对方同意
|
|
1076
|
+
override async roomAdd (roomId: string, contactId: string): Promise<void> {
|
|
1077
|
+
let type: number = 1 // 1 直接拉 2 发送邀请链接 人数超过40需要对方同意
|
|
1059
1078
|
if (roomId) {
|
|
1060
1079
|
const ret = await this.roomRawPayload(roomId)
|
|
1061
1080
|
if (ret && ret.memberNum && ret.memberNum > 38) {
|
|
@@ -1078,16 +1097,16 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1078
1097
|
|
|
1079
1098
|
// 创建群聊
|
|
1080
1099
|
override async roomCreate (
|
|
1081
|
-
contactIdList
|
|
1082
|
-
topic
|
|
1100
|
+
contactIdList: string[],
|
|
1101
|
+
topic: string,
|
|
1083
1102
|
): Promise<string> {
|
|
1084
1103
|
return this._client?.creatRoom(contactIdList, topic) || ''
|
|
1085
1104
|
}
|
|
1086
1105
|
|
|
1087
1106
|
// 删除群聊 暂不支持
|
|
1088
1107
|
override async roomDel (
|
|
1089
|
-
roomId
|
|
1090
|
-
contactId
|
|
1108
|
+
roomId: string,
|
|
1109
|
+
contactId: string,
|
|
1091
1110
|
): Promise<void> {
|
|
1092
1111
|
return PUPPET.throwUnsupportedError(roomId, contactId)
|
|
1093
1112
|
}
|
|
@@ -1107,22 +1126,22 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1107
1126
|
return this._client?.roomQuit(roomId)
|
|
1108
1127
|
}
|
|
1109
1128
|
|
|
1110
|
-
override async roomTopic
|
|
1111
|
-
override async roomTopic
|
|
1129
|
+
override async roomTopic(roomId: string): Promise<string>
|
|
1130
|
+
override async roomTopic(roomId: string, topic: string): Promise<void>
|
|
1112
1131
|
|
|
1113
1132
|
// 修改群名称
|
|
1114
1133
|
override async roomTopic (
|
|
1115
|
-
roomId
|
|
1116
|
-
topic
|
|
1134
|
+
roomId: string,
|
|
1135
|
+
topic?: string,
|
|
1117
1136
|
): Promise<void | string> {
|
|
1118
1137
|
await this._client?.setGroupName(roomId, topic)
|
|
1119
1138
|
}
|
|
1120
1139
|
|
|
1121
|
-
override async roomAnnounce
|
|
1122
|
-
override async roomAnnounce
|
|
1140
|
+
override async roomAnnounce(roomId: string): Promise<string>
|
|
1141
|
+
override async roomAnnounce(roomId: string, text: string): Promise<void>
|
|
1123
1142
|
|
|
1124
1143
|
// 修改群公告
|
|
1125
|
-
override async roomAnnounce (roomId: string, text?: string)
|
|
1144
|
+
override async roomAnnounce (roomId: string, text?: string): Promise<void | string> {
|
|
1126
1145
|
if (text !== undefined) {
|
|
1127
1146
|
await this._client?.sendAnnouncement(roomId, text)
|
|
1128
1147
|
}
|
|
@@ -1130,7 +1149,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1130
1149
|
}
|
|
1131
1150
|
|
|
1132
1151
|
// 获取群成员列表
|
|
1133
|
-
override async roomMemberList (roomId: string)
|
|
1152
|
+
override async roomMemberList (roomId: string): Promise<string[]> {
|
|
1134
1153
|
const roomMemberMap = await this._getRoomMemberList(roomId)
|
|
1135
1154
|
return Object.values(roomMemberMap).map((m) => m.wxid)
|
|
1136
1155
|
}
|
|
@@ -1201,7 +1220,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1201
1220
|
* 查找群基础信息
|
|
1202
1221
|
* @param id
|
|
1203
1222
|
*/
|
|
1204
|
-
override async roomRawPayload (id: string): Promise<ContactPayload|undefined> {
|
|
1223
|
+
override async roomRawPayload (id: string): Promise<ContactPayload | undefined> {
|
|
1205
1224
|
let ret = await this._cacheMgr!.getRoom(id)
|
|
1206
1225
|
if (!ret) {
|
|
1207
1226
|
const contact = await this._refreshContact(id)
|
|
@@ -1215,21 +1234,28 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1215
1234
|
* @param roomId
|
|
1216
1235
|
* @param contactId
|
|
1217
1236
|
*/
|
|
1218
|
-
override async roomMemberRawPayload (roomId: string, contactId: string): Promise<ContactPayload>
|
|
1237
|
+
override async roomMemberRawPayload (roomId: string, contactId: string): Promise<ContactPayload> {
|
|
1219
1238
|
const roomMemberMap = await this._getRoomMemberList(roomId)
|
|
1220
1239
|
if (roomMemberMap[contactId]) {
|
|
1221
1240
|
return roomMemberMap[contactId]!
|
|
1222
1241
|
}
|
|
1223
|
-
const
|
|
1242
|
+
const memberInfo = await this._updateRoomMemberMap(roomId, contactId)
|
|
1243
|
+
|
|
1244
|
+
const ret = await this._cacheMgr!.getRoomMember(roomId)
|
|
1245
|
+
if (ret) {
|
|
1246
|
+
const newMap = await this._getRoomMemberList(roomId, true)
|
|
1224
1247
|
|
|
1225
|
-
|
|
1248
|
+
return newMap[contactId] || memberInfo
|
|
1249
|
+
} else {
|
|
1250
|
+
return memberInfo
|
|
1251
|
+
}
|
|
1226
1252
|
}
|
|
1227
1253
|
|
|
1228
1254
|
/**
|
|
1229
1255
|
* 解析群成员信息
|
|
1230
1256
|
* @param rawPayload
|
|
1231
1257
|
*/
|
|
1232
|
-
override async roomMemberRawPayloadParser (rawPayload: ContactPayload): Promise<PUPPET.payloads.RoomMember>
|
|
1258
|
+
override async roomMemberRawPayloadParser (rawPayload: ContactPayload): Promise<PUPPET.payloads.RoomMember> {
|
|
1233
1259
|
return engineRoomMemberToWechaty(rawPayload)
|
|
1234
1260
|
}
|
|
1235
1261
|
|
|
@@ -1283,7 +1309,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1283
1309
|
if (!PUPPET.payloads.isPostClient(payload)) {
|
|
1284
1310
|
throw new Error('can only publish client post now')
|
|
1285
1311
|
}
|
|
1286
|
-
const momentInfo:any = {
|
|
1312
|
+
const momentInfo: any = {
|
|
1287
1313
|
content: '',
|
|
1288
1314
|
mentionIdList: [],
|
|
1289
1315
|
visibledList: [],
|
|
@@ -1310,7 +1336,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1310
1336
|
const fileUrl = fileBox.remoteUrl || ''
|
|
1311
1337
|
if (fileBox.mediaType.startsWith('image/')) {
|
|
1312
1338
|
momentInfo.imageUrls.push(fileUrl)
|
|
1313
|
-
} else if (fileType.includes('video/mp4') ||
|
|
1339
|
+
} else if (fileType.includes('video/mp4') || fileType.includes('.mp4')) {
|
|
1314
1340
|
momentInfo.videoUrl = fileUrl
|
|
1315
1341
|
}
|
|
1316
1342
|
}
|
|
@@ -1360,8 +1386,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1360
1386
|
}
|
|
1361
1387
|
|
|
1362
1388
|
override async postRawPayloadParser (payload: PUPPET.payloads.Post): Promise<PUPPET.payloads.Post> {
|
|
1363
|
-
|
|
1364
|
-
|
|
1389
|
+
// log.silly('PuppetService', 'postRawPayloadParser({id:%s})', payload.id)
|
|
1390
|
+
// passthrough
|
|
1365
1391
|
return payload
|
|
1366
1392
|
}
|
|
1367
1393
|
|
|
@@ -1421,6 +1447,62 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1421
1447
|
return ret
|
|
1422
1448
|
}
|
|
1423
1449
|
|
|
1450
|
+
// 更新群成员列表,新增
|
|
1451
|
+
private async _updateRoomMemberMap (roomId: string, contactId: string): Promise<ContactPayload> {
|
|
1452
|
+
if (!this._cacheMgr) {
|
|
1453
|
+
return {
|
|
1454
|
+
avatar: '',
|
|
1455
|
+
city: '',
|
|
1456
|
+
country: '',
|
|
1457
|
+
name: '',
|
|
1458
|
+
alias: '',
|
|
1459
|
+
province: '',
|
|
1460
|
+
wxid: contactId,
|
|
1461
|
+
sex: 0,
|
|
1462
|
+
wxNum: '',
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
const ret = await this._cacheMgr!.getRoomMember(roomId)
|
|
1467
|
+
if (ret) {
|
|
1468
|
+
const existContact = await this._cacheMgr!.getContact(contactId)
|
|
1469
|
+
if (existContact) {
|
|
1470
|
+
ret[contactId] = existContact as ContactPayload
|
|
1471
|
+
await this._updateRoomMember(roomId, ret)
|
|
1472
|
+
return existContact
|
|
1473
|
+
} else {
|
|
1474
|
+
const contact = await this._client?.searchContact([ contactId ])
|
|
1475
|
+
if (!Array.isArray(contact)) {
|
|
1476
|
+
ret[contactId] = contact as ContactPayload
|
|
1477
|
+
await this._updateRoomMember(roomId, ret)
|
|
1478
|
+
return contact as ContactPayload
|
|
1479
|
+
}
|
|
1480
|
+
return {
|
|
1481
|
+
avatar: '',
|
|
1482
|
+
city: '',
|
|
1483
|
+
country: '',
|
|
1484
|
+
name: '',
|
|
1485
|
+
alias: '',
|
|
1486
|
+
province: '',
|
|
1487
|
+
wxid: contactId,
|
|
1488
|
+
sex: 0,
|
|
1489
|
+
wxNum: '',
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return {
|
|
1494
|
+
avatar: '',
|
|
1495
|
+
city: '',
|
|
1496
|
+
country: '',
|
|
1497
|
+
name: '',
|
|
1498
|
+
alias: '',
|
|
1499
|
+
province: '',
|
|
1500
|
+
wxid: contactId,
|
|
1501
|
+
sex: 0,
|
|
1502
|
+
wxNum: '',
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1424
1506
|
// 更新联系人缓存
|
|
1425
1507
|
private async _updateContactCache (contact: ContactPayload): Promise<void> {
|
|
1426
1508
|
if (!contact.wxid) {
|
|
@@ -1434,7 +1516,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1434
1516
|
const roomId = contact.wxid
|
|
1435
1517
|
let finalPayload: ContactPayload = contact
|
|
1436
1518
|
if (oldRoomPayload) {
|
|
1437
|
-
finalPayload =
|
|
1519
|
+
finalPayload = { ...oldRoomPayload, ...contact }
|
|
1438
1520
|
}
|
|
1439
1521
|
await this._cacheMgr!.setRoom(roomId, finalPayload)
|
|
1440
1522
|
|
|
@@ -1446,7 +1528,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1446
1528
|
} else {
|
|
1447
1529
|
const oldContactPaylod = await this._cacheMgr!.getContact(contact.wxid)
|
|
1448
1530
|
if (oldContactPaylod) {
|
|
1449
|
-
await this._cacheMgr!.setContact(contact.wxid,
|
|
1531
|
+
await this._cacheMgr!.setContact(contact.wxid, { ...oldContactPaylod, ...contact })
|
|
1450
1532
|
} else {
|
|
1451
1533
|
await this._cacheMgr!.setContact(contact.wxid, contact)
|
|
1452
1534
|
}
|
|
@@ -1466,7 +1548,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1466
1548
|
* 更新群成员信息
|
|
1467
1549
|
* @param roomId
|
|
1468
1550
|
*/
|
|
1469
|
-
public async _updateRoom (roomId:string) {
|
|
1551
|
+
public async _updateRoom (roomId: string) {
|
|
1470
1552
|
if (!roomId) {
|
|
1471
1553
|
log.warn(PRE, 'roomid is required for updateRoom')
|
|
1472
1554
|
return
|
|
@@ -1539,9 +1621,20 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1539
1621
|
break
|
|
1540
1622
|
}
|
|
1541
1623
|
case EventType.RoomJoin: {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1624
|
+
const roomJoin: PUPPET.payloads.EventRoomJoin = event.payload
|
|
1625
|
+
await this._updateRoomMember(roomJoin.roomId)
|
|
1626
|
+
for (const joinId of roomJoin.inviteeIdList) {
|
|
1627
|
+
if (this._roomJoinTemp[`${roomJoin.roomId}-${joinId}`]) {
|
|
1628
|
+
roomJoin.inviteeIdList = roomJoin.inviteeIdList.filter(id => id !== joinId)
|
|
1629
|
+
} else {
|
|
1630
|
+
this._roomJoinTemp[`${roomJoin.roomId}-${joinId}`] = joinId
|
|
1631
|
+
const temTimer = setTimeout(() => {
|
|
1632
|
+
delete this._roomJoinTemp[`${roomJoin.roomId}-${joinId}`]
|
|
1633
|
+
clearTimeout(temTimer)
|
|
1634
|
+
}, 50000)
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
this.emit('room-join', roomJoin)
|
|
1545
1638
|
break
|
|
1546
1639
|
}
|
|
1547
1640
|
case EventType.RoomLeave: {
|
|
@@ -1552,8 +1645,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1552
1645
|
break
|
|
1553
1646
|
}
|
|
1554
1647
|
case EventType.RoomTopic: {
|
|
1555
|
-
|
|
1556
|
-
|
|
1648
|
+
const roomTopic: PUPPET.payloads.EventRoomTopic = event.payload
|
|
1649
|
+
this.emit('room-topic', roomTopic)
|
|
1557
1650
|
break
|
|
1558
1651
|
}
|
|
1559
1652
|
}
|
|
@@ -1602,7 +1695,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1602
1695
|
* @param messagePayload
|
|
1603
1696
|
* @private
|
|
1604
1697
|
*/
|
|
1605
|
-
private async _getMessageImageFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1698
|
+
private async _getMessageImageFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1606
1699
|
const imageInfo: ImageMessagePayload = await parseImageMessagePayload(messagePayload)
|
|
1607
1700
|
if (!imageInfo.file_id) {
|
|
1608
1701
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1611,7 +1704,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1611
1704
|
return FileBox.fromUrl(url)
|
|
1612
1705
|
}
|
|
1613
1706
|
|
|
1614
|
-
private async _getMessageAudioFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1707
|
+
private async _getMessageAudioFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1615
1708
|
const audioInfo: AudioMessagePayload = await parseAudioMessagePayload(messagePayload)
|
|
1616
1709
|
if (!audioInfo.length) {
|
|
1617
1710
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1620,7 +1713,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1620
1713
|
return FileBox.fromUrl(url)
|
|
1621
1714
|
}
|
|
1622
1715
|
|
|
1623
|
-
private async _getMessageVideoFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1716
|
+
private async _getMessageVideoFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1624
1717
|
const videoInfo: VideoMessagePayload = await parseVideoMessagePayload(messagePayload)
|
|
1625
1718
|
if (!videoInfo.file_id) {
|
|
1626
1719
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1636,7 +1729,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1636
1729
|
* @param messagePayload
|
|
1637
1730
|
* @private
|
|
1638
1731
|
*/
|
|
1639
|
-
private async _getMessageFileFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1732
|
+
private async _getMessageFileFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1640
1733
|
const appPayload: AppMessagePayload = await parseAppmsgMessagePayload(messagePayload.msg)
|
|
1641
1734
|
if (!appPayload.appattach?.attachid) {
|
|
1642
1735
|
log.error(`Can not get file for message: ${messageId}`)
|