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