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

puppet Contact & Room support provide the payload when load()

上级 04c559dd
...@@ -103,8 +103,9 @@ export class Contact extends PuppetAccessory implements Sayable { ...@@ -103,8 +103,9 @@ export class Contact extends PuppetAccessory implements Sayable {
* About the Generic: https://stackoverflow.com/q/43003970/1123955 * About the Generic: https://stackoverflow.com/q/43003970/1123955
*/ */
public static load<T extends typeof Contact>( public static load<T extends typeof Contact>(
this : T, this : T,
id : string, id : string,
payload? : ContactPayload,
): T['prototype'] { ): T['prototype'] {
if (!this.pool) { if (!this.pool) {
log.verbose('Contact', 'load(%s) init pool', id) log.verbose('Contact', 'load(%s) init pool', id)
...@@ -121,6 +122,9 @@ export class Contact extends PuppetAccessory implements Sayable { ...@@ -121,6 +122,9 @@ export class Contact extends PuppetAccessory implements Sayable {
} }
const existingContact = this.pool.get(id) const existingContact = this.pool.get(id)
if (existingContact) { if (existingContact) {
if (payload) {
existingContact.payload = payload
}
return existingContact return existingContact
} }
...@@ -128,6 +132,11 @@ export class Contact extends PuppetAccessory implements Sayable { ...@@ -128,6 +132,11 @@ export class Contact extends PuppetAccessory implements Sayable {
// so we force `this as any` at here to make the call. // so we force `this as any` at here to make the call.
const newContact = new (this as any)(id) const newContact = new (this as any)(id)
this.pool.set(id, newContact) this.pool.set(id, newContact)
if (payload) {
newContact.payload = payload
}
return newContact return newContact
} }
......
...@@ -174,8 +174,9 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -174,8 +174,9 @@ export class Room extends PuppetAccessory implements Sayable {
* About the Generic: https://stackoverflow.com/q/43003970/1123955 * About the Generic: https://stackoverflow.com/q/43003970/1123955
*/ */
public static load<T extends typeof Room>( public static load<T extends typeof Room>(
this : T, this : T,
id : string, id : string,
payload? : RoomPayload,
): T['prototype'] { ): T['prototype'] {
if (!this.pool) { if (!this.pool) {
this.pool = new Map<string, Room>() this.pool = new Map<string, Room>()
...@@ -183,10 +184,17 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -183,10 +184,17 @@ export class Room extends PuppetAccessory implements Sayable {
const existingRoom = this.pool.get(id) const existingRoom = this.pool.get(id)
if (existingRoom) { if (existingRoom) {
if (payload) {
existingRoom.payload = payload
}
return existingRoom return existingRoom
} }
const newRoom = new (this as any)(id) const newRoom = new (this as any)(id)
if (payload) {
newRoom.payload = payload
}
this.pool.set(id, newRoom) this.pool.set(id, newRoom)
return newRoom return newRoom
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册