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

linting with typescript v2.1

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