2019-04-21 07:36:21 +10:00
|
|
|
function getEventText(type, dict) {
|
2019-04-15 02:56:30 +10:00
|
|
|
switch (type) {
|
|
|
|
case "RoomCreateEvent":
|
|
|
|
return (dict.federate ? "allowed" : "blocked") +
|
|
|
|
" users on other matrix servers " +
|
|
|
|
(dict.federate ? "to join" : "from joining") +
|
|
|
|
" this room."
|
|
|
|
break
|
|
|
|
|
|
|
|
case "RoomGuestAccessEvent":
|
|
|
|
return (dict.guest_access === "can_join" ? "allowed " : "forbad") +
|
|
|
|
"guests to join the room."
|
|
|
|
break
|
|
|
|
|
|
|
|
case "RoomJoinRulesEvent":
|
|
|
|
return "made the room " +
|
|
|
|
(dict.join_rule === "public." ? "public" : "invite only.")
|
|
|
|
break
|
|
|
|
|
|
|
|
case "RoomHistoryVisibilityEvent":
|
2019-04-21 07:36:21 +10:00
|
|
|
return getHistoryVisibilityEventText(dict)
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
|
|
|
|
case "PowerLevelsEvent":
|
|
|
|
return "changed the room's permissions."
|
|
|
|
|
|
|
|
case "RoomMemberEvent":
|
2019-04-21 07:36:21 +10:00
|
|
|
return getMemberEventText(dict)
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
|
|
|
|
case "RoomAliasEvent":
|
|
|
|
return "set the room's main address to " +
|
|
|
|
dict.canonical_alias + "."
|
|
|
|
break
|
|
|
|
|
|
|
|
case "RoomNameEvent":
|
|
|
|
return "changed the room's name to \"" + dict.name + "\"."
|
|
|
|
break
|
|
|
|
|
|
|
|
case "RoomTopicEvent":
|
|
|
|
return "changed the room's topic to \"" + dict.topic + "\"."
|
|
|
|
break
|
|
|
|
|
|
|
|
case "RoomEncryptionEvent":
|
|
|
|
return "turned on encryption for this room."
|
|
|
|
break
|
|
|
|
|
2019-04-15 04:09:54 +10:00
|
|
|
case "OlmEvent":
|
|
|
|
case "MegolmEvent":
|
|
|
|
return "hasn't sent your device the keys to decrypt this message."
|
|
|
|
|
2019-04-15 02:56:30 +10:00
|
|
|
default:
|
|
|
|
console.log(type + "\n" + JSON.stringify(dict, null, 4) + "\n")
|
|
|
|
return "did something this client does not understand."
|
|
|
|
|
|
|
|
//case "CallEvent": TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
function getHistoryVisibilityEventText(dict) {
|
2019-04-15 02:56:30 +10:00
|
|
|
switch (dict.history_visibility) {
|
|
|
|
case "shared":
|
|
|
|
var end = "all room members."
|
|
|
|
break
|
|
|
|
|
|
|
|
case "world_readable":
|
|
|
|
var end = "any member or outsider."
|
|
|
|
break
|
|
|
|
|
|
|
|
case "joined":
|
2019-04-22 02:25:55 +10:00
|
|
|
var end = "all room members, since the point they joined."
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
|
|
|
|
case "invited":
|
2019-04-22 02:25:55 +10:00
|
|
|
var end = "all room members, since the point they were invited."
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
return "made future history visible to " + end
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-22 02:25:55 +10:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
function getMemberEventText(dict) {
|
2019-04-15 02:56:30 +10:00
|
|
|
var info = dict.content, prev = dict.prev_content
|
|
|
|
|
|
|
|
if (! prev || (info.membership != prev.membership)) {
|
2019-04-22 02:25:55 +10:00
|
|
|
var reason = info.reason ? (" Reason: " + info.reason) : ""
|
|
|
|
|
2019-04-15 02:56:30 +10:00
|
|
|
switch (info.membership) {
|
|
|
|
case "join":
|
2019-04-22 02:25:55 +10:00
|
|
|
return prev && prev.membership === "invite" ?
|
|
|
|
"accepted the invitation." : "joined the room."
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
|
|
|
|
case "invite":
|
2019-04-22 02:25:55 +10:00
|
|
|
return "invited " + getStateDisplayName(dict) + " to the room."
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
|
|
|
|
case "leave":
|
2019-04-22 02:25:55 +10:00
|
|
|
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
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
|
|
|
|
case "ban":
|
2019-04-22 02:25:55 +10:00
|
|
|
var name = getStateDisplayName(dict)
|
|
|
|
return "banned " + name + " from the room." + reason
|
2019-04-15 02:56:30 +10:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var changed = []
|
|
|
|
|
|
|
|
if (prev && (info.avatar_url != prev.avatar_url)) {
|
|
|
|
changed.push("profile picture")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prev && (info.displayname != prev.displayname)) {
|
|
|
|
changed.push("display name from \"" +
|
|
|
|
(prev.displayname || dict.state_key) + '" to "' +
|
|
|
|
(info.displayname || dict.state_key) + '"')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed.length > 0) {
|
|
|
|
return "changed their " + changed.join(" and ") + "."
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
2019-04-15 06:12:07 +10:00
|
|
|
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
function getTypingUsersText(users, ourAccountId) {
|
2019-04-15 06:12:07 +10:00
|
|
|
var names = []
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
for (var i = 0; i < users.length; i++) {
|
|
|
|
if (users[i] !== ourAccountId) {
|
|
|
|
names.push(Backend.getUserDisplayName(users[i], false).result())
|
2019-04-19 17:11:56 +10:00
|
|
|
}
|
2019-04-15 06:12:07 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
if (names.length < 1) { return "" }
|
|
|
|
|
|
|
|
return "🖋 " +
|
|
|
|
[names.slice(0, -1).join(", "), names.slice(-1)[0]]
|
|
|
|
.join(names.length < 2 ? "" : " and ") +
|
|
|
|
(names.length > 1 ? " are" : " is") + " typing…"
|
|
|
|
}
|