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

linting with typescript v2.1

上级 e407c9e5
...@@ -141,20 +141,19 @@ function puppetInstance(instance: Puppet): void ...@@ -141,20 +141,19 @@ function puppetInstance(instance: Puppet): void
function puppetInstance(instance?: Puppet | null): Puppet | void { function puppetInstance(instance?: Puppet | null): Puppet | void {
if (instance === undefined) { if (instance === undefined) {
if (!global['_puppetInstance']) { if (!this._puppetInstance) {
throw new Error('no puppet instance') throw new Error('no puppet instance')
} }
return global['_puppetInstance'] return this._puppetInstance
} else if (instance === null) { } else if (instance === null) {
log.verbose('Config', 'puppetInstance(null)') log.verbose('Config', 'puppetInstance(null)')
global['_puppetInstance'] = null this._puppetInstance = null
return return
} }
log.verbose('Config', 'puppetInstance(%s)', instance.constructor.name) log.verbose('Config', 'puppetInstance(%s)', instance.constructor.name)
global['_puppetInstance'] = instance this._puppetInstance = instance
return return
} }
......
...@@ -20,6 +20,7 @@ export class MediaMessage extends Message { ...@@ -20,6 +20,7 @@ export class MediaMessage extends Message {
constructor(rawObj) { constructor(rawObj) {
super(rawObj) super(rawObj)
// FIXME: decoupling needed
this.bridge = (Config.puppetInstance() as PuppetWeb) this.bridge = (Config.puppetInstance() as PuppetWeb)
.bridge .bridge
} }
...@@ -89,6 +90,7 @@ export class MediaMessage extends Message { ...@@ -89,6 +90,7 @@ export class MediaMessage extends Message {
public readyStream(): Promise<NodeJS.ReadableStream> { public readyStream(): Promise<NodeJS.ReadableStream> {
return this.ready() return this.ready()
.then(() => { .then(() => {
// FIXME: decoupling needed
return (Config.puppetInstance() as PuppetWeb) return (Config.puppetInstance() as PuppetWeb)
.browser.readCookie() .browser.readCookie()
}) })
......
...@@ -272,7 +272,7 @@ async function checkRoomJoin(m: Message): Promise<void> { ...@@ -272,7 +272,7 @@ async function checkRoomJoin(m: Message): Promise<void> {
return return
} }
function parseRoomLeave(content: string): string|null { function parseRoomLeave(content: string): string {
const reList = regexConfig.roomLeave const reList = regexConfig.roomLeave
let found: string[]|null = [] let found: string[]|null = []
......
...@@ -95,7 +95,7 @@ export class PuppetWeb extends Puppet { ...@@ -95,7 +95,7 @@ export class PuppetWeb extends Puppet {
const food: WatchdogFood = { const food: WatchdogFood = {
data: 'inited' data: 'inited'
, timeout: 120000 // 2 mins for first login , timeout: 2 * 60 * 1000 // 2 mins for first login
} }
this.emit('watchdog', food) this.emit('watchdog', food)
...@@ -368,6 +368,7 @@ export class PuppetWeb extends Puppet { ...@@ -368,6 +368,7 @@ export class PuppetWeb extends Puppet {
throw e throw e
}) })
} }
public logined(): boolean { return !!(this.user) } public logined(): boolean { return !!(this.user) }
public ding(data?: any): Promise<string> { public ding(data?: any): Promise<string> {
if (!this.bridge) { if (!this.bridge) {
......
...@@ -35,7 +35,7 @@ export abstract class Puppet extends EventEmitter implements Sayable { ...@@ -35,7 +35,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
super() super()
} }
public abstract async init(): Promise<this> public abstract async init(): Promise<void>
/** /**
* @deprecated * @deprecated
* use Message.self() instead * use Message.self() instead
......
...@@ -70,22 +70,23 @@ export class Room extends EventEmitter implements Sayable { ...@@ -70,22 +70,23 @@ export class Room extends EventEmitter implements Sayable {
return !!(this.obj && this.obj.memberList && this.obj.memberList.length) return !!(this.obj && this.obj.memberList && this.obj.memberList.length)
} }
public async refresh(): Promise<this> { public async refresh(): Promise<void> {
if (this.isReady()) { if (this.isReady()) {
this.dirtyObj = this.obj this.dirtyObj = this.obj
} }
this.obj = null this.obj = null
return this.ready() await this.ready()
return
} }
public async ready(contactGetter?: (id: string) => Promise<RoomRawObj>): Promise<this> { public async ready(contactGetter?: (id: string) => Promise<any>): Promise<void> {
log.silly('Room', 'ready(%s)', contactGetter ? contactGetter.constructor.name : '') log.silly('Room', 'ready(%s)', contactGetter ? contactGetter.constructor.name : '')
if (!this.id) { if (!this.id) {
const e = new Error('ready() on a un-inited Room') const e = new Error('ready() on a un-inited Room')
log.warn('Room', e.message) log.warn('Room', e.message)
return Promise.reject(e) throw e
} else if (this.isReady()) { } else if (this.isReady()) {
return Promise.resolve(this) return
} else if (this.obj && this.obj.id) { } else if (this.obj && this.obj.id) {
log.warn('Room', 'ready() has obj.id but memberList empty in room %s. reloading', this.obj.topic) log.warn('Room', 'ready() has obj.id but memberList empty in room %s. reloading', this.obj.topic)
} }
...@@ -109,7 +110,7 @@ export class Room extends EventEmitter implements Sayable { ...@@ -109,7 +110,7 @@ export class Room extends EventEmitter implements Sayable {
} }
await Promise.all(this.obj.memberList.map(c => c.ready(contactGetter))) await Promise.all(this.obj.memberList.map(c => c.ready(contactGetter)))
return this return
} catch (e) { } catch (e) {
log.error('Room', 'contactGetter(%s) exception: %s', this.id, e.message) log.error('Room', 'contactGetter(%s) exception: %s', this.id, e.message)
...@@ -423,7 +424,9 @@ export class Room extends EventEmitter implements Sayable { ...@@ -423,7 +424,9 @@ export class Room extends EventEmitter implements Sayable {
if (!roomList || roomList.length < 1) { if (!roomList || roomList.length < 1) {
throw new Error('no room found') throw new Error('no room found')
} }
return roomList[0].ready() const room = roomList[0]
await room.ready()
return room
} }
public static load(id: string): Room | null { public static load(id: string): Room | null {
......
...@@ -323,8 +323,8 @@ export class Wechaty extends EventEmitter implements Sayable { ...@@ -323,8 +323,8 @@ export class Wechaty extends EventEmitter implements Sayable {
return return
} }
public sleep(millisecond: number): Promise<void> { public async sleep(millisecond: number): Promise<void> {
return new Promise(resolve => { await new Promise(resolve => {
setTimeout(resolve, millisecond) setTimeout(resolve, millisecond)
}) })
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册