From 12305be06a11affaca79848ff6359078f421108b Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sat, 19 Jun 2021 16:01:02 +0530 Subject: [PATCH] Fix issue #397 Signed-off-by: RMidhunSuresh --- .../room/timeline/tiles/RoomMemberTile.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/domain/session/room/timeline/tiles/RoomMemberTile.js b/src/domain/session/room/timeline/tiles/RoomMemberTile.js index a4f0268d..ce41f031 100644 --- a/src/domain/session/room/timeline/tiles/RoomMemberTile.js +++ b/src/domain/session/room/timeline/tiles/RoomMemberTile.js @@ -33,7 +33,10 @@ export class RoomMemberTile extends SimpleTile { if (content.avatar_url !== prevContent.avatar_url) { return `${senderName} changed their avatar`; } else if (content.displayname !== prevContent.displayname) { - return `${prevContent.displayname} changed their name to ${content.displayname}`; + if (!content.displayname) { + return `${stateKey} removed their name (${prevContent.displayname})`; + } + return `${prevContent.displayname ?? stateKey} changed their name to ${content.displayname}`; } } else if (membership === "join") { return `${targetName} joined the room`; @@ -59,3 +62,28 @@ export class RoomMemberTile extends SimpleTile { return `${sender} membership changed to ${content.membership}`; } } + +export function tests() { + return { + "user removes display name": (assert) => { + const tile = new RoomMemberTile({ + entry: { + prevContent: {displayname: "foo", membership: "join"}, + content: {membership: "join"}, + stateKey: "foo@bar.com", + }, + }); + assert.strictEqual(tile.announcement, "foo@bar.com removed their name (foo)"); + }, + "user without display name sets a new display name": (assert) => { + const tile = new RoomMemberTile({ + entry: { + prevContent: {membership: "join"}, + content: {displayname: "foo", membership: "join" }, + stateKey: "foo@bar.com", + }, + }); + assert.strictEqual(tile.announcement, "foo@bar.com changed their name to foo"); + }, + }; +}