render display name in timeline

This commit is contained in:
Bruno Windels 2020-08-20 10:26:28 +02:00
parent 41c00ce44a
commit d31a1b5fff
3 changed files with 21 additions and 12 deletions

View File

@ -31,7 +31,7 @@ export class MessageTile extends SimpleTile {
}
get sender() {
return this._entry.sender;
return this._entry.displayName || this._entry.sender;
}
get senderColorNumber() {

View File

@ -23,35 +23,36 @@ export class RoomMemberTile extends SimpleTile {
}
get announcement() {
const {sender, content, prevContent, stateKey} = this._entry;
const {sender, content, prevContent} = this._entry;
const name = this._entry.displayName || sender;
const membership = content && content.membership;
const prevMembership = prevContent && prevContent.membership;
if (prevMembership === "join" && membership === "join") {
if (content.avatar_url !== prevContent.avatar_url) {
return `${stateKey} changed their avatar`;
return `${name} changed their avatar`;
} else if (content.displayname !== prevContent.displayname) {
return `${stateKey} changed their name to ${content.displayname}`;
return `${name} changed their name to ${content.displayname}`;
}
} else if (membership === "join") {
return `${stateKey} joined the room`;
return `${name} joined the room`;
} else if (membership === "invite") {
return `${stateKey} was invited to the room by ${sender}`;
return `${name} was invited to the room by ${sender}`;
} else if (prevMembership === "invite") {
if (membership === "join") {
return `${stateKey} accepted the invitation to join the room`;
return `${name} accepted the invitation to join the room`;
} else if (membership === "leave") {
return `${stateKey} declined the invitation to join the room`;
return `${name} declined the invitation to join the room`;
}
} else if (membership === "leave") {
if (stateKey === sender) {
return `${stateKey} left the room`;
if (name === sender) {
return `${name} left the room`;
} else {
const reason = content.reason;
return `${stateKey} was kicked from the room by ${sender}${reason ? `: ${reason}` : ""}`;
return `${name} was kicked from the room by ${sender}${reason ? `: ${reason}` : ""}`;
}
} else if (membership === "ban") {
return `${stateKey} was banned from the room by ${sender}`;
return `${name} was banned from the room by ${sender}`;
}
return `${sender} membership changed to ${content.membership}`;

View File

@ -50,6 +50,14 @@ export class EventEntry extends BaseEntry {
return this._eventEntry.event.sender;
}
get displayName() {
return this._eventEntry.displayName;
}
get avatarUrl() {
return this._eventEntry.avatarUrl;
}
get timestamp() {
return this._eventEntry.event.origin_server_ts;
}