Fix and improve room members event texts

This commit is contained in:
miruka 2019-04-21 12:25:55 -04:00
parent 94d6bc0e52
commit 909e1c3363
3 changed files with 42 additions and 11 deletions

View File

@ -93,7 +93,12 @@ class SignalManager(QObject):
def onRoomLeft(self, client: Client, room_id: str) -> None:
rooms = self.backend.models.rooms[client.userId]
del rooms[rooms.indexWhere("roomId", room_id)]
try:
index = rooms.indexWhere("roomId", room_id)
except ValueError:
pass
else:
del rooms[index]
def onRoomSyncPrevBatchTokenReceived(

View File

@ -24,7 +24,9 @@ RowLayout {
id: contentLabel
text: "<font color='" +
(isUndecryptableEvent ? "darkred" : "gray") + "'>" +
(displayName.value || dict.sender) + " " + contentText +
(displayName.value || dict.sender) +
(contentText.startsWith("'s ") ? "" : " ") +
contentText +
"&nbsp;&nbsp;<font size=" + smallSize + "px color='gray'>" +
Qt.formatDateTime(dateTime, "hh:mm:ss") +
"</font></font>"

View File

@ -69,11 +69,11 @@ function getHistoryVisibilityEventText(dict) {
break
case "joined":
var end = "all room members since they joined."
var end = "all room members, since the point they joined."
break
case "invited":
var end = "all room members since they were invited."
var end = "all room members, since the point they were invited."
break
}
@ -81,28 +81,52 @@ function getHistoryVisibilityEventText(dict) {
}
function getStateDisplayName(dict) {
// The dict.content.displayname may be outdated, prefer
// retrieving it fresh
var name = Backend.getUserDisplayName(dict.state_key, false)
return name === dict.state_key ?
dict.content.displayname : name.result()
}
function getMemberEventText(dict) {
var info = dict.content, prev = dict.prev_content
if (! prev || (info.membership != prev.membership)) {
var reason = info.reason ? (" Reason: " + info.reason) : ""
switch (info.membership) {
case "join":
return "joined the room."
return prev && prev.membership === "invite" ?
"accepted the invitation." : "joined the room."
break
case "invite":
var name = Backend.getUserDisplayName(dict.state_key, false)
var name = name === dict.state_key ?
info.displayname : name.result()
return "invited " + name + " to the room."
return "invited " + getStateDisplayName(dict) + " to the room."
break
case "leave":
return "left the room."
if (dict.state_key === dict.sender) {
return (prev && prev.membership === "invite" ?
"declined the invitation." : "left the room.") +
reason
}
var name = getStateDisplayName(dict)
return (prev && prev.membership === "invite" ?
"withdrew " + name + "'s invitation." :
prev && prev.membership == "ban" ?
"unbanned " + name + " from the room." :
"kicked out " + name + " from the room.") +
reason
break
case "ban":
return "was banned from the room."
var name = getStateDisplayName(dict)
return "banned " + name + " from the room." + reason
break
}
}