diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index d048eeec60d7702e2a48d45d1b40062c0b545928..d9311cc3af161f52d5d08e0349191c1ba22f7f0d 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -62,7 +62,7 @@ export class MatrixEventProcessor { private discord: DiscordBot; private matrixMsgProcessor: MatrixMessageProcessor; private mxCommandHandler: MatrixCommandHandler; - private mxUserProfileCache: TimedCache<string, {displayname: string, avatar_url: string}>; + private mxUserProfileCache: TimedCache<string, {displayname: string, avatar_url: string|undefined}>; constructor(opts: MatrixEventProcessorOpts, cm?: MatrixCommandHandler) { this.config = opts.config; @@ -212,6 +212,12 @@ export class MatrixEventProcessor { const membership = event.content!.membership; if (membership === "join") { this.mxUserProfileCache.delete(`${event.room_id}:${event.sender}`); + if (event.content!.displayname) { + this.mxUserProfileCache.set(`${event.room_id}:${event.sender}`, { + avatar_url: event.content!.avatar_url, + displayname: event.content!.displayname!, + }); + } // We don't know if the user also updated their profile, but to be safe.. this.mxUserProfileCache.delete(event.sender); } @@ -368,7 +374,7 @@ export class MatrixEventProcessor { private async GetUserProfileForRoom(roomId: string, userId: string) { const mxClient = this.bridge.getClientFactory().getClientAs(); const intent = this.bridge.getIntent(); - let profile: {displayname: string, avatar_url: string} | undefined; + let profile: {displayname: string, avatar_url: string|undefined} | undefined; try { // First try to pull out the room-specific profile from the cache. profile = this.mxUserProfileCache.get(`${roomId}:${userId}`); @@ -433,7 +439,7 @@ export class MatrixEventProcessor { private async SetEmbedAuthor(embed: Discord.RichEmbed, sender: string, profile?: { displayname: string, - avatar_url: string}) { + avatar_url: string|undefined }) { let displayName = sender; let avatarUrl; diff --git a/src/matrixtypes.ts b/src/matrixtypes.ts index 7535b59a89063a02e1f1946321550287f483dd94..f08ae1301c571fdbc866e7aafff94eed21e8229f 100644 --- a/src/matrixtypes.ts +++ b/src/matrixtypes.ts @@ -23,6 +23,7 @@ export interface IMatrixEventContent { msgtype?: string; url?: string; displayname?: string; + avatar_url?: string; reason?: string; "m.relates_to"?: any; // tslint:disable-line no-any }