提交 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 {
public get(prop) { return this.obj && this.obj[prop] }
public isReady(): boolean {
return !!(this.obj && this.obj.id)
return !!(this.obj && this.obj.id && this.obj.name !== undefined)
}
public async refresh(): Promise<this> {
......
......@@ -166,8 +166,7 @@ async function fireRoomJoin(m: Message): Promise<void> {
[inviteeList, inviter] = checkRoomJoin(content)
} catch (e) {
log.silly('PuppetWebFirer', 'fireRoomJoin() "%s" is not a join message', content)
// not a room join message
return
return // not a room join message
}
log.silly('PuppetWebFirer', 'fireRoomJoin() inviteeList: %s, inviter: %s'
, inviteeList.join(',')
......@@ -193,28 +192,43 @@ async function fireRoomJoin(m: Message): Promise<void> {
log.silly('PuppetWebFirer', 'fireRoomJoin() retryPromise() attempt %d with timeout %d', attempt, timeout)
await room.refresh()
let iDone, allDone = true
let inviteeListAllDone = true
for (let i in inviteeList) {
iDone = inviteeContactList[i] instanceof Contact
if (!iDone) {
const loaded = inviteeContactList[i] instanceof Contact
if (!loaded) {
let c = room.member(inviteeList[i])
if (c) {
inviteeContactList[i] = await c.ready()
if (!c.isReady()) {
allDone = false
}
} else {
allDone = false
if (!c) {
inviteeListAllDone = false
continue
}
inviteeContactList[i] = await c.ready()
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) {
inviterContact = room.member(inviter)
}
if (allDone && inviterContact) {
if (inviteeListAllDone && inviterContact) {
log.silly('PuppetWebFirer', 'fireRoomJoin() resolve() inviteeContactList: %s, inviterContact: %s'
, inviteeContactList.map((c: Contact) => c.name()).join(',')
, inviterContact.name()
......@@ -228,7 +242,7 @@ async function fireRoomJoin(m: Message): Promise<void> {
log.silly('PuppetWebFirer', 'fireRoomJoin() reject() inviteeContactList: %s, inviterContact: %s'
, inviteeContactList.map((c: Contact) => c.name()).join(',')
, inviter
)
)
})
if (!inviterContact) {
......
......@@ -440,6 +440,37 @@
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册