moment/harmonyqml/components/side_pane/utils.js
miruka 1d0cce402e Proper display name retrieval implementation
For any name not found in rooms data, rely on new
nio.HttpClient.get_displayname() function to get and cache it,
e.g. for our own name if no room is joined and past events from users
who left the room.

@futurize now returns PyQtFuture objects, wrapper for the
concurrent.futures.Future objects that can be used from QML,
to ensure name retrieval does not block the GUI.
2019-04-19 02:26:29 -04:00

43 lines
1.2 KiB
JavaScript

.import "../chat/utils.js" as ChatJS
function get_last_room_event_text(room_id) {
var eventsModel = Backend.models.roomEvents.get(room_id)
for (var i = 0; i < eventsModel.count; i++) {
var ev = eventsModel.get(i)
if (ev.type !== "RoomMemberEvent") {
var found = true
break
}
}
if (! found) { return "" }
var name = Backend.getUserDisplayName(ev.dict.sender, false).result()
var undecryptable = ev.type === "OlmEvent" || ev.type === "MegolmEvent"
if (undecryptable || ev.type.startsWith("RoomMessage")) {
var color = ev.dict.sender === roomList.for_user_id ?
"darkblue" : "purple"
return "<font color='" +
color +
"'>" +
name +
":</font> " +
(undecryptable ?
"<font color='darkred'>Undecryptable<font>" :
ev.dict.body)
} else {
return "<font color='" +
(undecryptable ? "darkred" : "#444") +
"'>" +
name +
" " +
ChatJS.get_event_text(ev.type, ev.dict) +
"</font>"
}
}