wechaty-puppet-matrix 0.0.23 → 0.0.26
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 +8 -3
- package/dist/cjs/src/matrix/service/request.d.ts.map +1 -1
- package/dist/cjs/src/matrix/service/request.js +110 -50
- 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 +107 -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 +8 -3
- package/dist/esm/src/matrix/service/request.d.ts.map +1 -1
- package/dist/esm/src/matrix/service/request.js +110 -50
- 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 +107 -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 +124 -62
- package/src/puppet-matrix.ts +169 -69
- package/src/puppet-matrix.ts~ +0 -1674
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) {
|
|
@@ -188,7 +207,12 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
188
207
|
} as any)
|
|
189
208
|
}, 5000)
|
|
190
209
|
}
|
|
191
|
-
|
|
210
|
+
}))
|
|
211
|
+
this._client.on('expired', this.wrapAsync(async (expired: boolean) => {
|
|
212
|
+
if (expired) {
|
|
213
|
+
log.info(PRE, 'Token has expired')
|
|
214
|
+
void this.onStop()
|
|
215
|
+
}
|
|
192
216
|
}))
|
|
193
217
|
}
|
|
194
218
|
addRunningPuppet(this)
|
|
@@ -230,7 +254,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
230
254
|
}
|
|
231
255
|
}
|
|
232
256
|
|
|
233
|
-
private getQrcodeTicket (authurl: string):string {
|
|
257
|
+
private getQrcodeTicket (authurl: string): string {
|
|
234
258
|
if (!authurl || !authurl.startsWith('http')) return ''
|
|
235
259
|
const url = new URL(authurl)
|
|
236
260
|
const searchParams = new URLSearchParams(url.search.slice(1))
|
|
@@ -286,7 +310,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
286
310
|
await this.onQrCodeEvent(scanStatus.status, qrcode.qrcodeUrl)
|
|
287
311
|
}
|
|
288
312
|
|
|
289
|
-
},
|
|
313
|
+
}, 8000)
|
|
290
314
|
} else {
|
|
291
315
|
if (this._getQrcodeTimes && this._getQrcodeTimes > 5) {
|
|
292
316
|
log.info(PRE, '由于多次请求二维码失败,已停止请求,请检查你的网络环境,重启容器后再试。')
|
|
@@ -341,7 +365,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
341
365
|
}
|
|
342
366
|
log.silly(
|
|
343
367
|
PRE,
|
|
344
|
-
|
|
368
|
+
`scan event, status: ${ScanStatusName[scanStatus]}${url ? ', with qrcode: ' + url : ''}`,
|
|
345
369
|
)
|
|
346
370
|
|
|
347
371
|
this.emit('scan', {
|
|
@@ -355,7 +379,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
355
379
|
}
|
|
356
380
|
|
|
357
381
|
// 登录
|
|
358
|
-
private async onLogin (user: ContactPayload):Promise<void> {
|
|
382
|
+
private async onLogin (user: ContactPayload): Promise<void> {
|
|
359
383
|
try {
|
|
360
384
|
// create cache manager firstly
|
|
361
385
|
if (!this._client) {
|
|
@@ -415,6 +439,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
415
439
|
private async _stopClient (): Promise<void> {
|
|
416
440
|
this.__currentUserId = undefined
|
|
417
441
|
this.__currentUserId = undefined
|
|
442
|
+
this._client?.destroy()
|
|
443
|
+
this._client = undefined
|
|
418
444
|
if (this._cacheMgr) {
|
|
419
445
|
log.info(PRE, 'colse cache')
|
|
420
446
|
await this._cacheMgr.close()
|
|
@@ -476,7 +502,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
476
502
|
|
|
477
503
|
// 获取自己的二维码
|
|
478
504
|
override async contactSelfQRCode (): Promise<string> {
|
|
479
|
-
return this._client?.getUserQrcode()
|
|
505
|
+
return this._client?.getUserQrcode() || ''
|
|
480
506
|
}
|
|
481
507
|
|
|
482
508
|
// 设置自己的签名 暂不支持
|
|
@@ -490,10 +516,10 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
490
516
|
}
|
|
491
517
|
|
|
492
518
|
// 查询或设置用户备注
|
|
493
|
-
override contactAlias
|
|
494
|
-
override contactAlias
|
|
519
|
+
override contactAlias(contactId: string): Promise<string>
|
|
520
|
+
override contactAlias(contactId: string, alias: string | null): Promise<void>
|
|
495
521
|
|
|
496
|
-
override async contactAlias (contactId
|
|
522
|
+
override async contactAlias (contactId: string, alias?: string | null): Promise<string | void> {
|
|
497
523
|
const contact = await this.contactRawPayload(contactId)
|
|
498
524
|
if (alias) {
|
|
499
525
|
// contact is stranger, set alias in cache, to update after user is added
|
|
@@ -521,10 +547,10 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
521
547
|
}
|
|
522
548
|
|
|
523
549
|
// 获取用户头像
|
|
524
|
-
override async contactAvatar
|
|
525
|
-
override async contactAvatar
|
|
550
|
+
override async contactAvatar(contactId: string): Promise<FileBoxInterface>
|
|
551
|
+
override async contactAvatar(contactId: string, file: FileBoxInterface): Promise<void>
|
|
526
552
|
|
|
527
|
-
override async contactAvatar (contactId: string, file?: FileBoxInterface)
|
|
553
|
+
override async contactAvatar (contactId: string, file?: FileBoxInterface): Promise<void | FileBoxInterface> {
|
|
528
554
|
if (file) {
|
|
529
555
|
return PUPPET.throwUnsupportedError('set avatar is not unsupported')
|
|
530
556
|
}
|
|
@@ -571,12 +597,12 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
571
597
|
}
|
|
572
598
|
|
|
573
599
|
// 删除标签
|
|
574
|
-
override async tagTagDelete (tagIdList: string[])
|
|
600
|
+
override async tagTagDelete (tagIdList: string[]): Promise<void> {
|
|
575
601
|
return PUPPET.throwUnsupportedError(tagIdList)
|
|
576
602
|
}
|
|
577
603
|
|
|
578
604
|
// 获取用户标签
|
|
579
|
-
override async tagTagContactList (contactId?: string)
|
|
605
|
+
override async tagTagContactList (contactId?: string): Promise<string[]> {
|
|
580
606
|
return PUPPET.throwUnsupportedError(contactId)
|
|
581
607
|
}
|
|
582
608
|
|
|
@@ -587,7 +613,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
587
613
|
* 通过好友请求
|
|
588
614
|
* @param friendshipId
|
|
589
615
|
*/
|
|
590
|
-
override async friendshipAccept (friendshipId
|
|
616
|
+
override async friendshipAccept (friendshipId: string): Promise<void> {
|
|
591
617
|
const friendship: PUPPET.payloads.FriendshipReceive = (await this.friendshipRawPayload(
|
|
592
618
|
friendshipId,
|
|
593
619
|
)) as PUPPET.payloads.FriendshipReceive
|
|
@@ -650,7 +676,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
650
676
|
hello = (option as any).hello
|
|
651
677
|
}
|
|
652
678
|
}
|
|
653
|
-
await this._client?.addFriendByWxid({ content: hello, ticket,
|
|
679
|
+
await this._client?.addFriendByWxid({ content: hello, ticket, scene: addContactScene, wxid: contactId })
|
|
654
680
|
}
|
|
655
681
|
|
|
656
682
|
/**
|
|
@@ -675,7 +701,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
675
701
|
* @param scene 场景值 1=qq 3=微信号 6=单向添加 10和13=通讯录 14=群聊 15=手机号 17=名片 30=扫一扫
|
|
676
702
|
* @private
|
|
677
703
|
*/
|
|
678
|
-
private async _friendshipSearch (id: string, scene?:string): Promise<null | string> {
|
|
704
|
+
private async _friendshipSearch (id: string, scene?: string): Promise<null | string> {
|
|
679
705
|
const cachedContactSearch = await this._cacheMgr!.getContactSearch(id)
|
|
680
706
|
if (cachedContactSearch) {
|
|
681
707
|
return id
|
|
@@ -815,7 +841,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
815
841
|
* 解析h5链接
|
|
816
842
|
* @param messageId
|
|
817
843
|
*/
|
|
818
|
-
override async messageUrl (messageId: string)
|
|
844
|
+
override async messageUrl (messageId: string): Promise<PUPPET.payloads.UrlLink> {
|
|
819
845
|
const rawPayload = await this.messageRawPayload(messageId)
|
|
820
846
|
const payload = await this.messageRawPayloadParser(rawPayload)
|
|
821
847
|
|
|
@@ -837,7 +863,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
837
863
|
* 解析h5链接
|
|
838
864
|
* @param messageId
|
|
839
865
|
*/
|
|
840
|
-
override async messageLocation (messageId: string)
|
|
866
|
+
override async messageLocation (messageId: string): Promise<PUPPET.payloads.Location> {
|
|
841
867
|
const rawPayload = await this.messageRawPayload(messageId)
|
|
842
868
|
const payload = await this.messageRawPayloadParser(rawPayload)
|
|
843
869
|
|
|
@@ -888,9 +914,9 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
888
914
|
const metadata: FileBoxMetadataMessage = fileBox.metadata as FileBoxMetadataMessage
|
|
889
915
|
|
|
890
916
|
const fileType
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
917
|
+
= fileBox.mediaType && fileBox.mediaType !== 'application/octet-stream'
|
|
918
|
+
? fileBox.mediaType
|
|
919
|
+
: path.extname(fileBox.name)
|
|
894
920
|
|
|
895
921
|
// @ts-ignore
|
|
896
922
|
const fileUrl = fileBox.remoteUrl || ''
|
|
@@ -908,7 +934,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
908
934
|
}
|
|
909
935
|
} else if (fileBox.mediaType === 'audio/silk') {
|
|
910
936
|
PUPPET.throwUnsupportedError(conversationId, fileBox)
|
|
911
|
-
} else if (fileType.includes('video/mp4') ||
|
|
937
|
+
} else if (fileType.includes('video/mp4') || fileType.includes('.mp4')) {
|
|
912
938
|
const msgInfo = await this._client?.sendVideo(conversationId, fileUrl, this._self?.wxid)
|
|
913
939
|
if (msgInfo) {
|
|
914
940
|
await this._cacheMgr?.setMessage(msgInfo.id, msgInfo)
|
|
@@ -1054,8 +1080,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1054
1080
|
***************************************************************************/
|
|
1055
1081
|
|
|
1056
1082
|
// 拉人进群
|
|
1057
|
-
override async roomAdd (roomId
|
|
1058
|
-
let type:number = 1 // 1 直接拉 2 发送邀请链接 人数超过40需要对方同意
|
|
1083
|
+
override async roomAdd (roomId: string, contactId: string): Promise<void> {
|
|
1084
|
+
let type: number = 1 // 1 直接拉 2 发送邀请链接 人数超过40需要对方同意
|
|
1059
1085
|
if (roomId) {
|
|
1060
1086
|
const ret = await this.roomRawPayload(roomId)
|
|
1061
1087
|
if (ret && ret.memberNum && ret.memberNum > 38) {
|
|
@@ -1078,16 +1104,16 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1078
1104
|
|
|
1079
1105
|
// 创建群聊
|
|
1080
1106
|
override async roomCreate (
|
|
1081
|
-
contactIdList
|
|
1082
|
-
topic
|
|
1107
|
+
contactIdList: string[],
|
|
1108
|
+
topic: string,
|
|
1083
1109
|
): Promise<string> {
|
|
1084
1110
|
return this._client?.creatRoom(contactIdList, topic) || ''
|
|
1085
1111
|
}
|
|
1086
1112
|
|
|
1087
1113
|
// 删除群聊 暂不支持
|
|
1088
1114
|
override async roomDel (
|
|
1089
|
-
roomId
|
|
1090
|
-
contactId
|
|
1115
|
+
roomId: string,
|
|
1116
|
+
contactId: string,
|
|
1091
1117
|
): Promise<void> {
|
|
1092
1118
|
return PUPPET.throwUnsupportedError(roomId, contactId)
|
|
1093
1119
|
}
|
|
@@ -1107,22 +1133,22 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1107
1133
|
return this._client?.roomQuit(roomId)
|
|
1108
1134
|
}
|
|
1109
1135
|
|
|
1110
|
-
override async roomTopic
|
|
1111
|
-
override async roomTopic
|
|
1136
|
+
override async roomTopic(roomId: string): Promise<string>
|
|
1137
|
+
override async roomTopic(roomId: string, topic: string): Promise<void>
|
|
1112
1138
|
|
|
1113
1139
|
// 修改群名称
|
|
1114
1140
|
override async roomTopic (
|
|
1115
|
-
roomId
|
|
1116
|
-
topic
|
|
1141
|
+
roomId: string,
|
|
1142
|
+
topic?: string,
|
|
1117
1143
|
): Promise<void | string> {
|
|
1118
1144
|
await this._client?.setGroupName(roomId, topic)
|
|
1119
1145
|
}
|
|
1120
1146
|
|
|
1121
|
-
override async roomAnnounce
|
|
1122
|
-
override async roomAnnounce
|
|
1147
|
+
override async roomAnnounce(roomId: string): Promise<string>
|
|
1148
|
+
override async roomAnnounce(roomId: string, text: string): Promise<void>
|
|
1123
1149
|
|
|
1124
1150
|
// 修改群公告
|
|
1125
|
-
override async roomAnnounce (roomId: string, text?: string)
|
|
1151
|
+
override async roomAnnounce (roomId: string, text?: string): Promise<void | string> {
|
|
1126
1152
|
if (text !== undefined) {
|
|
1127
1153
|
await this._client?.sendAnnouncement(roomId, text)
|
|
1128
1154
|
}
|
|
@@ -1130,7 +1156,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1130
1156
|
}
|
|
1131
1157
|
|
|
1132
1158
|
// 获取群成员列表
|
|
1133
|
-
override async roomMemberList (roomId: string)
|
|
1159
|
+
override async roomMemberList (roomId: string): Promise<string[]> {
|
|
1134
1160
|
const roomMemberMap = await this._getRoomMemberList(roomId)
|
|
1135
1161
|
return Object.values(roomMemberMap).map((m) => m.wxid)
|
|
1136
1162
|
}
|
|
@@ -1201,7 +1227,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1201
1227
|
* 查找群基础信息
|
|
1202
1228
|
* @param id
|
|
1203
1229
|
*/
|
|
1204
|
-
override async roomRawPayload (id: string): Promise<ContactPayload|undefined> {
|
|
1230
|
+
override async roomRawPayload (id: string): Promise<ContactPayload | undefined> {
|
|
1205
1231
|
let ret = await this._cacheMgr!.getRoom(id)
|
|
1206
1232
|
if (!ret) {
|
|
1207
1233
|
const contact = await this._refreshContact(id)
|
|
@@ -1215,21 +1241,28 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1215
1241
|
* @param roomId
|
|
1216
1242
|
* @param contactId
|
|
1217
1243
|
*/
|
|
1218
|
-
override async roomMemberRawPayload (roomId: string, contactId: string): Promise<ContactPayload>
|
|
1244
|
+
override async roomMemberRawPayload (roomId: string, contactId: string): Promise<ContactPayload> {
|
|
1219
1245
|
const roomMemberMap = await this._getRoomMemberList(roomId)
|
|
1220
1246
|
if (roomMemberMap[contactId]) {
|
|
1221
1247
|
return roomMemberMap[contactId]!
|
|
1222
1248
|
}
|
|
1223
|
-
const
|
|
1249
|
+
const memberInfo = await this._updateRoomMemberMap(roomId, contactId)
|
|
1250
|
+
|
|
1251
|
+
const ret = await this._cacheMgr!.getRoomMember(roomId)
|
|
1252
|
+
if (ret) {
|
|
1253
|
+
const newMap = await this._getRoomMemberList(roomId, true)
|
|
1224
1254
|
|
|
1225
|
-
|
|
1255
|
+
return newMap[contactId] || memberInfo
|
|
1256
|
+
} else {
|
|
1257
|
+
return memberInfo
|
|
1258
|
+
}
|
|
1226
1259
|
}
|
|
1227
1260
|
|
|
1228
1261
|
/**
|
|
1229
1262
|
* 解析群成员信息
|
|
1230
1263
|
* @param rawPayload
|
|
1231
1264
|
*/
|
|
1232
|
-
override async roomMemberRawPayloadParser (rawPayload: ContactPayload): Promise<PUPPET.payloads.RoomMember>
|
|
1265
|
+
override async roomMemberRawPayloadParser (rawPayload: ContactPayload): Promise<PUPPET.payloads.RoomMember> {
|
|
1233
1266
|
return engineRoomMemberToWechaty(rawPayload)
|
|
1234
1267
|
}
|
|
1235
1268
|
|
|
@@ -1283,7 +1316,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1283
1316
|
if (!PUPPET.payloads.isPostClient(payload)) {
|
|
1284
1317
|
throw new Error('can only publish client post now')
|
|
1285
1318
|
}
|
|
1286
|
-
const momentInfo:any = {
|
|
1319
|
+
const momentInfo: any = {
|
|
1287
1320
|
content: '',
|
|
1288
1321
|
mentionIdList: [],
|
|
1289
1322
|
visibledList: [],
|
|
@@ -1310,7 +1343,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1310
1343
|
const fileUrl = fileBox.remoteUrl || ''
|
|
1311
1344
|
if (fileBox.mediaType.startsWith('image/')) {
|
|
1312
1345
|
momentInfo.imageUrls.push(fileUrl)
|
|
1313
|
-
} else if (fileType.includes('video/mp4') ||
|
|
1346
|
+
} else if (fileType.includes('video/mp4') || fileType.includes('.mp4')) {
|
|
1314
1347
|
momentInfo.videoUrl = fileUrl
|
|
1315
1348
|
}
|
|
1316
1349
|
}
|
|
@@ -1360,8 +1393,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1360
1393
|
}
|
|
1361
1394
|
|
|
1362
1395
|
override async postRawPayloadParser (payload: PUPPET.payloads.Post): Promise<PUPPET.payloads.Post> {
|
|
1363
|
-
|
|
1364
|
-
|
|
1396
|
+
// log.silly('PuppetService', 'postRawPayloadParser({id:%s})', payload.id)
|
|
1397
|
+
// passthrough
|
|
1365
1398
|
return payload
|
|
1366
1399
|
}
|
|
1367
1400
|
|
|
@@ -1421,6 +1454,62 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1421
1454
|
return ret
|
|
1422
1455
|
}
|
|
1423
1456
|
|
|
1457
|
+
// 更新群成员列表,新增
|
|
1458
|
+
private async _updateRoomMemberMap (roomId: string, contactId: string): Promise<ContactPayload> {
|
|
1459
|
+
if (!this._cacheMgr) {
|
|
1460
|
+
return {
|
|
1461
|
+
avatar: '',
|
|
1462
|
+
city: '',
|
|
1463
|
+
country: '',
|
|
1464
|
+
name: '',
|
|
1465
|
+
alias: '',
|
|
1466
|
+
province: '',
|
|
1467
|
+
wxid: contactId,
|
|
1468
|
+
sex: 0,
|
|
1469
|
+
wxNum: '',
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
const ret = await this._cacheMgr!.getRoomMember(roomId)
|
|
1474
|
+
if (ret) {
|
|
1475
|
+
const existContact = await this._cacheMgr!.getContact(contactId)
|
|
1476
|
+
if (existContact) {
|
|
1477
|
+
ret[contactId] = existContact as ContactPayload
|
|
1478
|
+
await this._updateRoomMember(roomId, ret)
|
|
1479
|
+
return existContact
|
|
1480
|
+
} else {
|
|
1481
|
+
const contact = await this._client?.searchContact([ contactId ])
|
|
1482
|
+
if (!Array.isArray(contact)) {
|
|
1483
|
+
ret[contactId] = contact as ContactPayload
|
|
1484
|
+
await this._updateRoomMember(roomId, ret)
|
|
1485
|
+
return contact as ContactPayload
|
|
1486
|
+
}
|
|
1487
|
+
return {
|
|
1488
|
+
avatar: '',
|
|
1489
|
+
city: '',
|
|
1490
|
+
country: '',
|
|
1491
|
+
name: '',
|
|
1492
|
+
alias: '',
|
|
1493
|
+
province: '',
|
|
1494
|
+
wxid: contactId,
|
|
1495
|
+
sex: 0,
|
|
1496
|
+
wxNum: '',
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
return {
|
|
1501
|
+
avatar: '',
|
|
1502
|
+
city: '',
|
|
1503
|
+
country: '',
|
|
1504
|
+
name: '',
|
|
1505
|
+
alias: '',
|
|
1506
|
+
province: '',
|
|
1507
|
+
wxid: contactId,
|
|
1508
|
+
sex: 0,
|
|
1509
|
+
wxNum: '',
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1424
1513
|
// 更新联系人缓存
|
|
1425
1514
|
private async _updateContactCache (contact: ContactPayload): Promise<void> {
|
|
1426
1515
|
if (!contact.wxid) {
|
|
@@ -1434,7 +1523,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1434
1523
|
const roomId = contact.wxid
|
|
1435
1524
|
let finalPayload: ContactPayload = contact
|
|
1436
1525
|
if (oldRoomPayload) {
|
|
1437
|
-
finalPayload =
|
|
1526
|
+
finalPayload = { ...oldRoomPayload, ...contact }
|
|
1438
1527
|
}
|
|
1439
1528
|
await this._cacheMgr!.setRoom(roomId, finalPayload)
|
|
1440
1529
|
|
|
@@ -1446,7 +1535,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1446
1535
|
} else {
|
|
1447
1536
|
const oldContactPaylod = await this._cacheMgr!.getContact(contact.wxid)
|
|
1448
1537
|
if (oldContactPaylod) {
|
|
1449
|
-
await this._cacheMgr!.setContact(contact.wxid,
|
|
1538
|
+
await this._cacheMgr!.setContact(contact.wxid, { ...oldContactPaylod, ...contact })
|
|
1450
1539
|
} else {
|
|
1451
1540
|
await this._cacheMgr!.setContact(contact.wxid, contact)
|
|
1452
1541
|
}
|
|
@@ -1466,7 +1555,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1466
1555
|
* 更新群成员信息
|
|
1467
1556
|
* @param roomId
|
|
1468
1557
|
*/
|
|
1469
|
-
public async _updateRoom (roomId:string) {
|
|
1558
|
+
public async _updateRoom (roomId: string) {
|
|
1470
1559
|
if (!roomId) {
|
|
1471
1560
|
log.warn(PRE, 'roomid is required for updateRoom')
|
|
1472
1561
|
return
|
|
@@ -1539,9 +1628,20 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1539
1628
|
break
|
|
1540
1629
|
}
|
|
1541
1630
|
case EventType.RoomJoin: {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1631
|
+
const roomJoin: PUPPET.payloads.EventRoomJoin = event.payload
|
|
1632
|
+
await this._updateRoomMember(roomJoin.roomId)
|
|
1633
|
+
for (const joinId of roomJoin.inviteeIdList) {
|
|
1634
|
+
if (this._roomJoinTemp[`${roomJoin.roomId}-${joinId}`]) {
|
|
1635
|
+
roomJoin.inviteeIdList = roomJoin.inviteeIdList.filter(id => id !== joinId)
|
|
1636
|
+
} else {
|
|
1637
|
+
this._roomJoinTemp[`${roomJoin.roomId}-${joinId}`] = joinId
|
|
1638
|
+
const temTimer = setTimeout(() => {
|
|
1639
|
+
delete this._roomJoinTemp[`${roomJoin.roomId}-${joinId}`]
|
|
1640
|
+
clearTimeout(temTimer)
|
|
1641
|
+
}, 50000)
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
this.emit('room-join', roomJoin)
|
|
1545
1645
|
break
|
|
1546
1646
|
}
|
|
1547
1647
|
case EventType.RoomLeave: {
|
|
@@ -1552,8 +1652,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1552
1652
|
break
|
|
1553
1653
|
}
|
|
1554
1654
|
case EventType.RoomTopic: {
|
|
1555
|
-
|
|
1556
|
-
|
|
1655
|
+
const roomTopic: PUPPET.payloads.EventRoomTopic = event.payload
|
|
1656
|
+
this.emit('room-topic', roomTopic)
|
|
1557
1657
|
break
|
|
1558
1658
|
}
|
|
1559
1659
|
}
|
|
@@ -1602,7 +1702,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1602
1702
|
* @param messagePayload
|
|
1603
1703
|
* @private
|
|
1604
1704
|
*/
|
|
1605
|
-
private async _getMessageImageFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1705
|
+
private async _getMessageImageFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1606
1706
|
const imageInfo: ImageMessagePayload = await parseImageMessagePayload(messagePayload)
|
|
1607
1707
|
if (!imageInfo.file_id) {
|
|
1608
1708
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1611,7 +1711,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1611
1711
|
return FileBox.fromUrl(url)
|
|
1612
1712
|
}
|
|
1613
1713
|
|
|
1614
|
-
private async _getMessageAudioFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1714
|
+
private async _getMessageAudioFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1615
1715
|
const audioInfo: AudioMessagePayload = await parseAudioMessagePayload(messagePayload)
|
|
1616
1716
|
if (!audioInfo.length) {
|
|
1617
1717
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1620,7 +1720,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1620
1720
|
return FileBox.fromUrl(url)
|
|
1621
1721
|
}
|
|
1622
1722
|
|
|
1623
|
-
private async _getMessageVideoFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1723
|
+
private async _getMessageVideoFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1624
1724
|
const videoInfo: VideoMessagePayload = await parseVideoMessagePayload(messagePayload)
|
|
1625
1725
|
if (!videoInfo.file_id) {
|
|
1626
1726
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1636,7 +1736,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1636
1736
|
* @param messagePayload
|
|
1637
1737
|
* @private
|
|
1638
1738
|
*/
|
|
1639
|
-
private async _getMessageFileFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1739
|
+
private async _getMessageFileFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1640
1740
|
const appPayload: AppMessagePayload = await parseAppmsgMessagePayload(messagePayload.msg)
|
|
1641
1741
|
if (!appPayload.appattach?.attachid) {
|
|
1642
1742
|
log.error(`Can not get file for message: ${messageId}`)
|