Merge pull request #42 from bwindels/bwindels/fixnamechangeshownasjoin

look at prev_content when handling member events
This commit is contained in:
Bruno Windels 2020-03-30 20:00:39 +00:00 committed by GitHub
commit 2f7c825d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 13 deletions

View File

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

View File

@ -18,6 +18,11 @@ export default class EventEntry extends BaseEntry {
return this._eventEntry.event.content; return this._eventEntry.event.content;
} }
get prevContent() {
const unsigned = this._eventEntry.event.unsigned;
return unsigned && unsigned.prev_content;
}
get eventType() { get eventType() {
return this._eventEntry.event.type; return this._eventEntry.event.type;
} }