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

#32 Room Event: `join` & `leave`

上级 12a81eb8
......@@ -336,6 +336,9 @@ function onServerLogout(data) {
function onServerMessage(data) {
let m = new Message(data)
co.call(this, function* () {
yield m.ready()
/**
* Fire Events if match message type & content
*/
......@@ -383,6 +386,7 @@ function onServerMessage(data) {
* setTimeout(onServerMessage.bind(this, data, ++attempt), 1000)
*/
})
})
}
module.exports = PuppetWebEvent
......@@ -115,6 +115,13 @@ function fireRoomJoin(m) {
let inviterContact, inviteeContact
co.call(this, function* () {
yield room.refresh()
yield new Promise(resolve => {
setTimeout(_ => resolve(), 1000)
})
if (inviter === "You've") {
inviterContact = Contact.load(this.userId)
} else {
......@@ -124,10 +131,11 @@ function fireRoomJoin(m) {
inviteeContact = room.member(invitee)
if (!inviterContact || !inviteeContact) {
log.error('PuppetWebEvent', 'inivter or invitee not found for %s, %s', inviter, invitee)
log.error('PuppetWebEvent', 'inivter or invitee not found for %s, %s', inviter.name(), invitee.name())
return
}
room.emit('join', inviteeContact, inviterContact)
})
}
function checkRoomLeave(content) {
......@@ -151,6 +159,7 @@ function fireRoomLeave(m) {
}
const room = m.room()
leaverContact = room.member(leaver)
if (!leaverContact) {
......@@ -158,6 +167,7 @@ function fireRoomLeave(m) {
return
}
room.emit('leave', leaverContact)
room.refresh()
}
module.exports = PuppetWebFirer
......@@ -214,12 +214,18 @@ class Room extends EventEmitter{
}
member(name) {
log.verbose('Room', 'member(%s)', name)
if (!this.obj.memberList) {
log.warn('Room', 'member() not ready')
return null
}
const nickMap = this.obj.nickMap
const idList = Object.keys(nickMap)
.filter(k => nickMap[k] === name)
log.silly('Room', 'member() check nickMap: %s', JSON.stringify(nickMap))
if (idList.length) {
return Contact.load(idList[0])
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册