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

make room-join event more reliable for invitee contact instance

上级 d48aab92
...@@ -99,7 +99,7 @@ export class Contact implements Sayable { ...@@ -99,7 +99,7 @@ export class Contact implements Sayable {
public get(prop) { return this.obj && this.obj[prop] } public get(prop) { return this.obj && this.obj[prop] }
public isReady(): boolean { public isReady(): boolean {
return !!(this.obj && this.obj.id) return !!(this.obj && this.obj.id && this.obj.name !== undefined)
} }
public async refresh(): Promise<this> { public async refresh(): Promise<this> {
......
...@@ -166,8 +166,7 @@ async function fireRoomJoin(m: Message): Promise<void> { ...@@ -166,8 +166,7 @@ async function fireRoomJoin(m: Message): Promise<void> {
[inviteeList, inviter] = checkRoomJoin(content) [inviteeList, inviter] = checkRoomJoin(content)
} catch (e) { } catch (e) {
log.silly('PuppetWebFirer', 'fireRoomJoin() "%s" is not a join message', content) log.silly('PuppetWebFirer', 'fireRoomJoin() "%s" is not a join message', content)
// not a room join message return // not a room join message
return
} }
log.silly('PuppetWebFirer', 'fireRoomJoin() inviteeList: %s, inviter: %s' log.silly('PuppetWebFirer', 'fireRoomJoin() inviteeList: %s, inviter: %s'
, inviteeList.join(',') , inviteeList.join(',')
...@@ -193,28 +192,43 @@ async function fireRoomJoin(m: Message): Promise<void> { ...@@ -193,28 +192,43 @@ async function fireRoomJoin(m: Message): Promise<void> {
log.silly('PuppetWebFirer', 'fireRoomJoin() retryPromise() attempt %d with timeout %d', attempt, timeout) log.silly('PuppetWebFirer', 'fireRoomJoin() retryPromise() attempt %d with timeout %d', attempt, timeout)
await room.refresh() await room.refresh()
let iDone, allDone = true let inviteeListAllDone = true
for (let i in inviteeList) { for (let i in inviteeList) {
iDone = inviteeContactList[i] instanceof Contact const loaded = inviteeContactList[i] instanceof Contact
if (!iDone) {
if (!loaded) {
let c = room.member(inviteeList[i]) let c = room.member(inviteeList[i])
if (c) { if (!c) {
inviteeContactList[i] = await c.ready() inviteeListAllDone = false
if (!c.isReady()) { continue
allDone = false }
}
} else { inviteeContactList[i] = await c.ready()
allDone = false const isReady = c.isReady()
if (!isReady) {
inviteeListAllDone = false
continue
} }
} }
if (inviteeContactList[i] instanceof Contact) {
const isReady = inviteeContactList[i].isReady()
if (!isReady) {
log.warn('PuppetWebFirer', 'fireRoomJoin() retryPromise() isReady false for contact %s', inviteeContactList[i].id)
inviteeListAllDone = false
await inviteeContactList[i].refresh()
continue
}
}
} }
if (!inviterContact) { if (!inviterContact) {
inviterContact = room.member(inviter) inviterContact = room.member(inviter)
} }
if (allDone && inviterContact) { if (inviteeListAllDone && inviterContact) {
log.silly('PuppetWebFirer', 'fireRoomJoin() resolve() inviteeContactList: %s, inviterContact: %s' log.silly('PuppetWebFirer', 'fireRoomJoin() resolve() inviteeContactList: %s, inviterContact: %s'
, inviteeContactList.map((c: Contact) => c.name()).join(',') , inviteeContactList.map((c: Contact) => c.name()).join(',')
, inviterContact.name() , inviterContact.name()
...@@ -228,7 +242,7 @@ async function fireRoomJoin(m: Message): Promise<void> { ...@@ -228,7 +242,7 @@ async function fireRoomJoin(m: Message): Promise<void> {
log.silly('PuppetWebFirer', 'fireRoomJoin() reject() inviteeContactList: %s, inviterContact: %s' log.silly('PuppetWebFirer', 'fireRoomJoin() reject() inviteeContactList: %s, inviterContact: %s'
, inviteeContactList.map((c: Contact) => c.name()).join(',') , inviteeContactList.map((c: Contact) => c.name()).join(',')
, inviter , inviter
) )
}) })
if (!inviterContact) { if (!inviterContact) {
......
...@@ -440,6 +440,37 @@ ...@@ -440,6 +440,37 @@
contactWithoutFunction[k] = c[k] contactWithoutFunction[k] = c[k]
} }
}) })
} else {
/**
* when `id` does not exist in _contact Array, maybe it is belongs to a stranger in a room.
* try to find in room's member list for this `id`, and return the contact info, if any.
*/
c = Object.keys(_contacts)
.filter(id => id.match(/^@@/)) // only search in room
.map(id => _contacts[id]) // map to room array
.filter(r => r.MemberList.length) // get rid of room without member list
.filter(r => r.MemberList
.filter(m => m.UserName === id)
.length
)
.map(c => c.MemberList
.filter(m => m.UserName === id)
[0]
)
[0]
if (c) {
c.stranger = true
Object.keys(c).forEach(function(k) {
if (typeof c[k] !== 'function') {
contactWithoutFunction[k] = c[k]
}
})
}
} }
return contactWithoutFunction return contactWithoutFunction
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册