look at prev_content when handling member events

This commit is contained in:
Bruno Windels 2020-03-30 21:59:44 +02:00
parent 3a6a2e1e99
commit e4563135bf
2 changed files with 35 additions and 13 deletions

View file

@ -7,20 +7,37 @@ export default class RoomNameTile extends SimpleTile {
}
get announcement() {
const {sender, content, stateKey} = this._entry;
switch (content.membership) {
case "invite": return `${stateKey} was invited to the room by ${sender}`;
case "join": return `${stateKey} joined the room`;
case "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}` : ""}`;
}
const {sender, content, prevContent, stateKey} = this._entry;
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`;
} else if (content.displayname !== prevContent.displayname) {
return `${stateKey} changed their name to ${content.displayname}`;
}
case "ban": return `${stateKey} was banned from the room by ${sender}`;
default: return `${sender} membership changed to ${content.membership}`;
} else if (membership === "join") {
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;
}
get prevContent() {
const unsigned = this._eventEntry.event.unsigned;
return unsigned && unsigned.prev_content;
}
get eventType() {
return this._eventEntry.event.type;
}