Fix and improve room members event texts
This commit is contained in:
parent
94d6bc0e52
commit
909e1c3363
|
@ -93,7 +93,12 @@ class SignalManager(QObject):
|
||||||
|
|
||||||
def onRoomLeft(self, client: Client, room_id: str) -> None:
|
def onRoomLeft(self, client: Client, room_id: str) -> None:
|
||||||
rooms = self.backend.models.rooms[client.userId]
|
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(
|
def onRoomSyncPrevBatchTokenReceived(
|
||||||
|
|
|
@ -24,7 +24,9 @@ RowLayout {
|
||||||
id: contentLabel
|
id: contentLabel
|
||||||
text: "<font color='" +
|
text: "<font color='" +
|
||||||
(isUndecryptableEvent ? "darkred" : "gray") + "'>" +
|
(isUndecryptableEvent ? "darkred" : "gray") + "'>" +
|
||||||
(displayName.value || dict.sender) + " " + contentText +
|
(displayName.value || dict.sender) +
|
||||||
|
(contentText.startsWith("'s ") ? "" : " ") +
|
||||||
|
contentText +
|
||||||
" <font size=" + smallSize + "px color='gray'>" +
|
" <font size=" + smallSize + "px color='gray'>" +
|
||||||
Qt.formatDateTime(dateTime, "hh:mm:ss") +
|
Qt.formatDateTime(dateTime, "hh:mm:ss") +
|
||||||
"</font></font>"
|
"</font></font>"
|
||||||
|
|
|
@ -69,11 +69,11 @@ function getHistoryVisibilityEventText(dict) {
|
||||||
break
|
break
|
||||||
|
|
||||||
case "joined":
|
case "joined":
|
||||||
var end = "all room members since they joined."
|
var end = "all room members, since the point they joined."
|
||||||
break
|
break
|
||||||
|
|
||||||
case "invited":
|
case "invited":
|
||||||
var end = "all room members since they were invited."
|
var end = "all room members, since the point they were invited."
|
||||||
break
|
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) {
|
function getMemberEventText(dict) {
|
||||||
var info = dict.content, prev = dict.prev_content
|
var info = dict.content, prev = dict.prev_content
|
||||||
|
|
||||||
if (! prev || (info.membership != prev.membership)) {
|
if (! prev || (info.membership != prev.membership)) {
|
||||||
|
var reason = info.reason ? (" Reason: " + info.reason) : ""
|
||||||
|
|
||||||
switch (info.membership) {
|
switch (info.membership) {
|
||||||
case "join":
|
case "join":
|
||||||
return "joined the room."
|
return prev && prev.membership === "invite" ?
|
||||||
|
"accepted the invitation." : "joined the room."
|
||||||
break
|
break
|
||||||
|
|
||||||
case "invite":
|
case "invite":
|
||||||
var name = Backend.getUserDisplayName(dict.state_key, false)
|
return "invited " + getStateDisplayName(dict) + " to the room."
|
||||||
var name = name === dict.state_key ?
|
|
||||||
info.displayname : name.result()
|
|
||||||
return "invited " + name + " to the room."
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case "leave":
|
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
|
break
|
||||||
|
|
||||||
case "ban":
|
case "ban":
|
||||||
return "was banned from the room."
|
var name = getStateDisplayName(dict)
|
||||||
|
return "banned " + name + " from the room." + reason
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user