提交 72d34801 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

retry to search new members on room join event. (#1324)

上级 c130f7fe
...@@ -660,12 +660,20 @@ export class PadchatManager extends PadchatRpc { ...@@ -660,12 +660,20 @@ export class PadchatManager extends PadchatRpc {
return roomIdList return roomIdList
} }
public async getRoomMemberIdList(roomId: string): Promise<string[]> { public async getRoomMemberIdList(
roomId: string,
noCache = false,
): Promise<string[]> {
log.verbose('PuppetPadchatManager', 'getRoomMemberIdList(%d)', roomId) log.verbose('PuppetPadchatManager', 'getRoomMemberIdList(%d)', roomId)
if (!this.cacheRoomMemberRawPayload) { if (!this.cacheRoomMemberRawPayload) {
throw new Error('cache not inited' ) throw new Error('cache not inited' )
} }
if (noCache) {
log.verbose('PuppetPadchatManager', 'getRoomMemberIdList(%d) cache PURGE', roomId)
this.cacheRoomMemberRawPayload.delete(roomId)
}
const memberRawPayloadDict = this.cacheRoomMemberRawPayload.get(roomId) const memberRawPayloadDict = this.cacheRoomMemberRawPayload.get(roomId)
|| await this.syncRoomMember(roomId) || await this.syncRoomMember(roomId)
......
...@@ -28,6 +28,8 @@ import { ...@@ -28,6 +28,8 @@ import {
FileBox, FileBox,
} from 'file-box' } from 'file-box'
import Misc from '../misc'
import { import {
ContactPayload, ContactPayload,
...@@ -333,22 +335,48 @@ export class PuppetPadchat extends Puppet { ...@@ -333,22 +335,48 @@ export class PuppetPadchat extends Puppet {
const inviterName = roomJoin.inviterName const inviterName = roomJoin.inviterName
const roomId = roomJoin.roomId const roomId = roomJoin.roomId
const inviteeIdList = flatten<string>( const inviteeIdList = await Misc.retry(async (retry, attempt) => {
await Promise.all( log.verbose('PuppetPadchat', 'onPadchatMessageRoomEvent({id=%s}) roomJoin retry(attempt=%d)', attempt)
inviteeNameList.map(
inviteeName => this.roomMemberSearch(roomId, inviteeName), const tryIdList = flatten<string>(
await Promise.all(
inviteeNameList.map(
inviteeName => this.roomMemberSearch(roomId, inviteeName),
),
), ),
), )
)
if (tryIdList.length) {
return tryIdList
}
if (!this.bridge) {
throw new Error('no manager')
}
/**
* PURGE Cache and Reload
*/
await this.bridge.getRoomMemberIdList(roomId, true)
return retry(new Error('roomMemberSearch() not found'))
}).catch(e => {
log.warn('PuppetPadchat', 'onPadchatMessageRoomEvent({id=%s}) roomJoin retry() fail: %s', e.message)
return [] as string[]
})
const inviterIdList = await this.roomMemberSearch(roomId, inviterName) const inviterIdList = await this.roomMemberSearch(roomId, inviterName)
if (inviterIdList.length < 1) { if (inviterIdList.length < 1) {
throw new Error('no inviterId found') throw new Error('no inviterId found')
} else if (inviterIdList.length > 1) { } else if (inviterIdList.length > 1) {
log.warn('PuppetPadchat', 'onPadchatMessageRoomEvent() case PadchatMesssageSys: inviterId found more than 1, use the first one.') log.warn('PuppetPadchat', 'onPadchatMessageRoomEvent() case PadchatMesssageSys: inviterId found more than 1, use the first one.')
} }
const inviterId = inviterIdList[0] const inviterId = inviterIdList[0]
this.emit('room-join', roomId, inviteeIdList, inviterId) this.emit('room-join', roomId, inviteeIdList, inviterId)
} }
/** /**
* 2. Look for room leave event * 2. Look for room leave event
......
...@@ -695,7 +695,6 @@ export abstract class Puppet extends EventEmitter implements Sayable { ...@@ -695,7 +695,6 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/** /**
* 2. for RoomMemberQueryFilter * 2. for RoomMemberQueryFilter
*/ */
// const roomPayload = await this.roomPayload(roomId)
const memberIdList = await this.roomMemberList(roomId) const memberIdList = await this.roomMemberList(roomId)
let idList: string[] = [] let idList: string[] = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册