wechaty-puppet-matrix 0.0.22 → 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 +114 -9
- 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 +114 -9
- 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 +179 -72
- package/src/puppet-matrix.ts~ +1674 -0
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)
|
|
@@ -952,6 +971,16 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
952
971
|
// 发送文字
|
|
953
972
|
override async messageSendText (conversationId: string, text: string, mentionIdList?: string[]): Promise<string | void> {
|
|
954
973
|
if (mentionIdList && mentionIdList.length) {
|
|
974
|
+
const mentionContact = await Promise.all(mentionIdList.map(async (mentionId) => {
|
|
975
|
+
const contact = await this.contactRawPayload(mentionId)
|
|
976
|
+
if (contact) {
|
|
977
|
+
return '@' + (contact.alias || contact.name)
|
|
978
|
+
}
|
|
979
|
+
return '@' + (mentionId === '@all' ? 'all' : '')
|
|
980
|
+
}))
|
|
981
|
+
const mentionText = mentionContact.join(String.fromCharCode(0x2005))
|
|
982
|
+
|
|
983
|
+
text = text.replaceAll(mentionText, '').trim()
|
|
955
984
|
const msgInfo = await this._client?.sendAtText(conversationId, text, mentionIdList, this._self?.wxid)
|
|
956
985
|
if (msgInfo) {
|
|
957
986
|
await this._cacheMgr?.setMessage(msgInfo.id, msgInfo)
|
|
@@ -1044,8 +1073,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1044
1073
|
***************************************************************************/
|
|
1045
1074
|
|
|
1046
1075
|
// 拉人进群
|
|
1047
|
-
override async roomAdd (roomId
|
|
1048
|
-
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需要对方同意
|
|
1049
1078
|
if (roomId) {
|
|
1050
1079
|
const ret = await this.roomRawPayload(roomId)
|
|
1051
1080
|
if (ret && ret.memberNum && ret.memberNum > 38) {
|
|
@@ -1068,16 +1097,16 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1068
1097
|
|
|
1069
1098
|
// 创建群聊
|
|
1070
1099
|
override async roomCreate (
|
|
1071
|
-
contactIdList
|
|
1072
|
-
topic
|
|
1100
|
+
contactIdList: string[],
|
|
1101
|
+
topic: string,
|
|
1073
1102
|
): Promise<string> {
|
|
1074
1103
|
return this._client?.creatRoom(contactIdList, topic) || ''
|
|
1075
1104
|
}
|
|
1076
1105
|
|
|
1077
1106
|
// 删除群聊 暂不支持
|
|
1078
1107
|
override async roomDel (
|
|
1079
|
-
roomId
|
|
1080
|
-
contactId
|
|
1108
|
+
roomId: string,
|
|
1109
|
+
contactId: string,
|
|
1081
1110
|
): Promise<void> {
|
|
1082
1111
|
return PUPPET.throwUnsupportedError(roomId, contactId)
|
|
1083
1112
|
}
|
|
@@ -1097,22 +1126,22 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1097
1126
|
return this._client?.roomQuit(roomId)
|
|
1098
1127
|
}
|
|
1099
1128
|
|
|
1100
|
-
override async roomTopic
|
|
1101
|
-
override async roomTopic
|
|
1129
|
+
override async roomTopic(roomId: string): Promise<string>
|
|
1130
|
+
override async roomTopic(roomId: string, topic: string): Promise<void>
|
|
1102
1131
|
|
|
1103
1132
|
// 修改群名称
|
|
1104
1133
|
override async roomTopic (
|
|
1105
|
-
roomId
|
|
1106
|
-
topic
|
|
1134
|
+
roomId: string,
|
|
1135
|
+
topic?: string,
|
|
1107
1136
|
): Promise<void | string> {
|
|
1108
1137
|
await this._client?.setGroupName(roomId, topic)
|
|
1109
1138
|
}
|
|
1110
1139
|
|
|
1111
|
-
override async roomAnnounce
|
|
1112
|
-
override async roomAnnounce
|
|
1140
|
+
override async roomAnnounce(roomId: string): Promise<string>
|
|
1141
|
+
override async roomAnnounce(roomId: string, text: string): Promise<void>
|
|
1113
1142
|
|
|
1114
1143
|
// 修改群公告
|
|
1115
|
-
override async roomAnnounce (roomId: string, text?: string)
|
|
1144
|
+
override async roomAnnounce (roomId: string, text?: string): Promise<void | string> {
|
|
1116
1145
|
if (text !== undefined) {
|
|
1117
1146
|
await this._client?.sendAnnouncement(roomId, text)
|
|
1118
1147
|
}
|
|
@@ -1120,7 +1149,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1120
1149
|
}
|
|
1121
1150
|
|
|
1122
1151
|
// 获取群成员列表
|
|
1123
|
-
override async roomMemberList (roomId: string)
|
|
1152
|
+
override async roomMemberList (roomId: string): Promise<string[]> {
|
|
1124
1153
|
const roomMemberMap = await this._getRoomMemberList(roomId)
|
|
1125
1154
|
return Object.values(roomMemberMap).map((m) => m.wxid)
|
|
1126
1155
|
}
|
|
@@ -1191,7 +1220,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1191
1220
|
* 查找群基础信息
|
|
1192
1221
|
* @param id
|
|
1193
1222
|
*/
|
|
1194
|
-
override async roomRawPayload (id: string): Promise<ContactPayload|undefined> {
|
|
1223
|
+
override async roomRawPayload (id: string): Promise<ContactPayload | undefined> {
|
|
1195
1224
|
let ret = await this._cacheMgr!.getRoom(id)
|
|
1196
1225
|
if (!ret) {
|
|
1197
1226
|
const contact = await this._refreshContact(id)
|
|
@@ -1205,21 +1234,28 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1205
1234
|
* @param roomId
|
|
1206
1235
|
* @param contactId
|
|
1207
1236
|
*/
|
|
1208
|
-
override async roomMemberRawPayload (roomId: string, contactId: string): Promise<ContactPayload>
|
|
1237
|
+
override async roomMemberRawPayload (roomId: string, contactId: string): Promise<ContactPayload> {
|
|
1209
1238
|
const roomMemberMap = await this._getRoomMemberList(roomId)
|
|
1210
1239
|
if (roomMemberMap[contactId]) {
|
|
1211
1240
|
return roomMemberMap[contactId]!
|
|
1212
1241
|
}
|
|
1213
|
-
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)
|
|
1214
1247
|
|
|
1215
|
-
|
|
1248
|
+
return newMap[contactId] || memberInfo
|
|
1249
|
+
} else {
|
|
1250
|
+
return memberInfo
|
|
1251
|
+
}
|
|
1216
1252
|
}
|
|
1217
1253
|
|
|
1218
1254
|
/**
|
|
1219
1255
|
* 解析群成员信息
|
|
1220
1256
|
* @param rawPayload
|
|
1221
1257
|
*/
|
|
1222
|
-
override async roomMemberRawPayloadParser (rawPayload: ContactPayload): Promise<PUPPET.payloads.RoomMember>
|
|
1258
|
+
override async roomMemberRawPayloadParser (rawPayload: ContactPayload): Promise<PUPPET.payloads.RoomMember> {
|
|
1223
1259
|
return engineRoomMemberToWechaty(rawPayload)
|
|
1224
1260
|
}
|
|
1225
1261
|
|
|
@@ -1273,7 +1309,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1273
1309
|
if (!PUPPET.payloads.isPostClient(payload)) {
|
|
1274
1310
|
throw new Error('can only publish client post now')
|
|
1275
1311
|
}
|
|
1276
|
-
const momentInfo:any = {
|
|
1312
|
+
const momentInfo: any = {
|
|
1277
1313
|
content: '',
|
|
1278
1314
|
mentionIdList: [],
|
|
1279
1315
|
visibledList: [],
|
|
@@ -1300,7 +1336,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1300
1336
|
const fileUrl = fileBox.remoteUrl || ''
|
|
1301
1337
|
if (fileBox.mediaType.startsWith('image/')) {
|
|
1302
1338
|
momentInfo.imageUrls.push(fileUrl)
|
|
1303
|
-
} else if (fileType.includes('video/mp4') ||
|
|
1339
|
+
} else if (fileType.includes('video/mp4') || fileType.includes('.mp4')) {
|
|
1304
1340
|
momentInfo.videoUrl = fileUrl
|
|
1305
1341
|
}
|
|
1306
1342
|
}
|
|
@@ -1350,8 +1386,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1350
1386
|
}
|
|
1351
1387
|
|
|
1352
1388
|
override async postRawPayloadParser (payload: PUPPET.payloads.Post): Promise<PUPPET.payloads.Post> {
|
|
1353
|
-
|
|
1354
|
-
|
|
1389
|
+
// log.silly('PuppetService', 'postRawPayloadParser({id:%s})', payload.id)
|
|
1390
|
+
// passthrough
|
|
1355
1391
|
return payload
|
|
1356
1392
|
}
|
|
1357
1393
|
|
|
@@ -1411,6 +1447,62 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1411
1447
|
return ret
|
|
1412
1448
|
}
|
|
1413
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
|
+
|
|
1414
1506
|
// 更新联系人缓存
|
|
1415
1507
|
private async _updateContactCache (contact: ContactPayload): Promise<void> {
|
|
1416
1508
|
if (!contact.wxid) {
|
|
@@ -1424,7 +1516,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1424
1516
|
const roomId = contact.wxid
|
|
1425
1517
|
let finalPayload: ContactPayload = contact
|
|
1426
1518
|
if (oldRoomPayload) {
|
|
1427
|
-
finalPayload =
|
|
1519
|
+
finalPayload = { ...oldRoomPayload, ...contact }
|
|
1428
1520
|
}
|
|
1429
1521
|
await this._cacheMgr!.setRoom(roomId, finalPayload)
|
|
1430
1522
|
|
|
@@ -1436,7 +1528,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1436
1528
|
} else {
|
|
1437
1529
|
const oldContactPaylod = await this._cacheMgr!.getContact(contact.wxid)
|
|
1438
1530
|
if (oldContactPaylod) {
|
|
1439
|
-
await this._cacheMgr!.setContact(contact.wxid,
|
|
1531
|
+
await this._cacheMgr!.setContact(contact.wxid, { ...oldContactPaylod, ...contact })
|
|
1440
1532
|
} else {
|
|
1441
1533
|
await this._cacheMgr!.setContact(contact.wxid, contact)
|
|
1442
1534
|
}
|
|
@@ -1456,7 +1548,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1456
1548
|
* 更新群成员信息
|
|
1457
1549
|
* @param roomId
|
|
1458
1550
|
*/
|
|
1459
|
-
public async _updateRoom (roomId:string) {
|
|
1551
|
+
public async _updateRoom (roomId: string) {
|
|
1460
1552
|
if (!roomId) {
|
|
1461
1553
|
log.warn(PRE, 'roomid is required for updateRoom')
|
|
1462
1554
|
return
|
|
@@ -1504,10 +1596,14 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1504
1596
|
case EventType.Friendship: {
|
|
1505
1597
|
if (event.payload.type !== PUPPET.types.Friendship.Confirm && event.payload.type !== PUPPET.types.Friendship.Verify) {
|
|
1506
1598
|
await this._cacheMgr?.setFriendshipRawPayload(event.payload.contactId, event.payload)
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1599
|
+
|
|
1600
|
+
setTimeout(() => {
|
|
1601
|
+
this.emit('friendship', {
|
|
1602
|
+
friendshipId: event.payload.contactId,
|
|
1603
|
+
type: event.payload.type,
|
|
1604
|
+
})
|
|
1605
|
+
}, 1000)
|
|
1606
|
+
|
|
1511
1607
|
} else {
|
|
1512
1608
|
this.emit('message', {
|
|
1513
1609
|
messageId,
|
|
@@ -1525,9 +1621,20 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1525
1621
|
break
|
|
1526
1622
|
}
|
|
1527
1623
|
case EventType.RoomJoin: {
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
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)
|
|
1531
1638
|
break
|
|
1532
1639
|
}
|
|
1533
1640
|
case EventType.RoomLeave: {
|
|
@@ -1538,8 +1645,8 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1538
1645
|
break
|
|
1539
1646
|
}
|
|
1540
1647
|
case EventType.RoomTopic: {
|
|
1541
|
-
|
|
1542
|
-
|
|
1648
|
+
const roomTopic: PUPPET.payloads.EventRoomTopic = event.payload
|
|
1649
|
+
this.emit('room-topic', roomTopic)
|
|
1543
1650
|
break
|
|
1544
1651
|
}
|
|
1545
1652
|
}
|
|
@@ -1588,7 +1695,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1588
1695
|
* @param messagePayload
|
|
1589
1696
|
* @private
|
|
1590
1697
|
*/
|
|
1591
|
-
private async _getMessageImageFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1698
|
+
private async _getMessageImageFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1592
1699
|
const imageInfo: ImageMessagePayload = await parseImageMessagePayload(messagePayload)
|
|
1593
1700
|
if (!imageInfo.file_id) {
|
|
1594
1701
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1597,7 +1704,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1597
1704
|
return FileBox.fromUrl(url)
|
|
1598
1705
|
}
|
|
1599
1706
|
|
|
1600
|
-
private async _getMessageAudioFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1707
|
+
private async _getMessageAudioFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1601
1708
|
const audioInfo: AudioMessagePayload = await parseAudioMessagePayload(messagePayload)
|
|
1602
1709
|
if (!audioInfo.length) {
|
|
1603
1710
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1606,7 +1713,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1606
1713
|
return FileBox.fromUrl(url)
|
|
1607
1714
|
}
|
|
1608
1715
|
|
|
1609
|
-
private async _getMessageVideoFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1716
|
+
private async _getMessageVideoFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1610
1717
|
const videoInfo: VideoMessagePayload = await parseVideoMessagePayload(messagePayload)
|
|
1611
1718
|
if (!videoInfo.file_id) {
|
|
1612
1719
|
log.error(`Can not get file for message: ${messageId}`)
|
|
@@ -1622,7 +1729,7 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
1622
1729
|
* @param messagePayload
|
|
1623
1730
|
* @private
|
|
1624
1731
|
*/
|
|
1625
|
-
private async _getMessageFileFileBox (messageId: string, messagePayload: MessagePayload):Promise<FileBoxInterface> {
|
|
1732
|
+
private async _getMessageFileFileBox (messageId: string, messagePayload: MessagePayload): Promise<FileBoxInterface> {
|
|
1626
1733
|
const appPayload: AppMessagePayload = await parseAppmsgMessagePayload(messagePayload.msg)
|
|
1627
1734
|
if (!appPayload.appattach?.attachid) {
|
|
1628
1735
|
log.error(`Can not get file for message: ${messageId}`)
|