Merge pull request #398 from MidhunSureshR/fix-397

Support removing display names in RoomMemberTile
This commit is contained in:
Bruno Windels 2021-06-24 07:27:22 +00:00 committed by GitHub
commit 197c247044
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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");
},
};
}