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

save userId when received login event on time

上级 e648b876
......@@ -206,12 +206,18 @@ function onServerLogin(data) {
co.call(this, function* () {
// co.call to make `this` context work inside generator.
// See also: https://github.com/tj/co/issues/274
const userName = yield this.bridge.getUserName()
/**
* save login user id to this.userId
*/
const userName = this.userId = yield this.bridge.getUserName()
if (!userName) {
log.verbose('PuppetWebEvent', 'onServerLogin: browser not full loaded, retry later.')
setTimeout(onServerLogin.bind(this), 500)
return
}
log.verbose('PuppetWebEvent', 'bridge.getUserName: %s', userName)
this.user = yield Contact.load(userName).ready()
log.verbose('PuppetWebEvent', `onServerLogin() user ${this.user.name()} logined`)
......
......@@ -271,7 +271,10 @@ class PuppetWeb extends Puppet {
if (this.user) {
// FIXME: find a alternate way to check a message create by `self`
m.set('self', this.user.id)
} else {
} else if (this.userId) {
m.set('self', this.userId)
}
else {
log.warn('PuppetWeb', 'reply() too early before logined user be set')
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册