look at prev_content when handling member events
This commit is contained in:
parent
3a6a2e1e99
commit
e4563135bf
2 changed files with 35 additions and 13 deletions
|
@ -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 (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}`;
|
||||||
|
}
|
||||||
|
} 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) {
|
if (stateKey === sender) {
|
||||||
return `${stateKey} left the room`;
|
return `${stateKey} left the room`;
|
||||||
} else {
|
} else {
|
||||||
const reason = content.reason;
|
const reason = content.reason;
|
||||||
return `${stateKey} was kicked from the room by ${sender}${reason ? `: ${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}`;
|
||||||
}
|
}
|
||||||
case "ban": return `${stateKey} was banned from the room by ${sender}`;
|
|
||||||
default: return `${sender} membership changed to ${content.membership}`;
|
return `${sender} membership changed to ${content.membership}`;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue