diff --git a/src/contact.ts b/src/contact.ts index 05eca131937fb16920540dfc38b539d04b146d67..a3cc10f99d8afdbd107c4c4117ee448ca1e4d8a4 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 b7715a8bdd36283af309e5714fe16f0d3291da96..a1dae54c3d4ba59df460e81cd2f6583f9a950165 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 }