From 5e39028c29f74526ec00677d589053f3ff9ff913 Mon Sep 17 00:00:00 2001 From: Huan LI Date: Tue, 29 May 2018 18:11:46 +0800 Subject: [PATCH] puppet Contact & Room support provide the payload when load() --- src/contact.ts | 13 +++++++++++-- src/room.ts | 12 ++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/contact.ts b/src/contact.ts index 05eca1319..a3cc10f99 100644 --- a/src/contact.ts +++ b/src/contact.ts @@ -103,8 +103,9 @@ export class Contact extends PuppetAccessory implements Sayable { * About the Generic: https://stackoverflow.com/q/43003970/1123955 */ public static load( - this : T, - id : string, + this : T, + id : string, + payload? : ContactPayload, ): T['prototype'] { if (!this.pool) { log.verbose('Contact', 'load(%s) init pool', id) @@ -121,6 +122,9 @@ export class Contact extends PuppetAccessory implements Sayable { } const existingContact = this.pool.get(id) if (existingContact) { + if (payload) { + existingContact.payload = payload + } return existingContact } @@ -128,6 +132,11 @@ export class Contact extends PuppetAccessory implements Sayable { // so we force `this as any` at here to make the call. const newContact = new (this as any)(id) this.pool.set(id, newContact) + + if (payload) { + newContact.payload = payload + } + return newContact } diff --git a/src/room.ts b/src/room.ts index b7715a8bd..a1dae54c3 100644 --- a/src/room.ts +++ b/src/room.ts @@ -174,8 +174,9 @@ export class Room extends PuppetAccessory implements Sayable { * About the Generic: https://stackoverflow.com/q/43003970/1123955 */ public static load( - this : T, - id : string, + this : T, + id : string, + payload? : RoomPayload, ): T['prototype'] { if (!this.pool) { this.pool = new Map() @@ -183,10 +184,17 @@ export class Room extends PuppetAccessory implements Sayable { const existingRoom = this.pool.get(id) if (existingRoom) { + if (payload) { + existingRoom.payload = payload + } return existingRoom } const newRoom = new (this as any)(id) + if (payload) { + newRoom.payload = payload + } + this.pool.set(id, newRoom) return newRoom } -- GitLab