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

code clean for #88

上级 d8854edb
......@@ -255,7 +255,7 @@ export class Contact implements Sayable {
public static load(id: string): Contact {
if (!id || typeof id !== 'string') {
throw new Error('id not found')
throw new Error('Contact.load(): id not found')
}
if (!(id in Contact.pool)) {
......
......@@ -331,6 +331,8 @@ export class Message implements Sayable {
return
}
// no parameter
if (!this.obj.to) {
return null
}
......
......@@ -299,12 +299,14 @@ export class PuppetWeb extends Puppet {
const content = message.content()
let destinationId
if (to) {
destinationId = to.id
}
if (room) {
destinationId = room.id
} else {
if (!to) {
throw new Error('PuppetWeb.send(): message with neither room nor to?')
}
destinationId = to.id
}
log.silly('PuppetWeb', 'send() destination: %s, content: %s)',
......
......@@ -140,6 +140,10 @@ export class Room extends EventEmitter implements Sayable {
return this
}
public say(content: string): Promise<any> {
public say(content: string, replyTo: Contact): Promise<any> {
public say(content: string, replyTo: Contact[]): Promise<any> {
public say(content: string, replyTo?: Contact|Contact[]): Promise<any> {
log.verbose('Room', 'say(%s, %s)'
, content
......@@ -151,19 +155,16 @@ export class Room extends EventEmitter implements Sayable {
const m = new Message()
m.room(this)
if (!replyTo) {
m.content(content)
return Config.puppetInstance()
.send(m)
}
const replyToList: Contact[] = arrify(replyTo)
let mentionList: string
m.to(replyToList[0])
mentionList = replyToList.map(c => '@' + c.name()).join(' ')
if (replyToList.length > 0) {
const mentionList = replyToList.map(c => '@' + c.name()).join(' ')
m.content(mentionList + ' ' + content)
} else {
m.content(content)
}
// m.to(replyToList[0])
m.content(mentionList + ' ' + content)
return Config.puppetInstance()
.send(m)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册