diff --git a/TODO.md b/TODO.md index 5026c86a..bcbaf207 100644 --- a/TODO.md +++ b/TODO.md @@ -18,3 +18,5 @@ - Better names and organization for the Message components - Load previous events on scroll up + +- Migrate more JS functions to their own files diff --git a/harmonyqml/components/chat/EventContent.qml b/harmonyqml/components/chat/EventContent.qml index 1c98cee1..6381ccab 100644 --- a/harmonyqml/components/chat/EventContent.qml +++ b/harmonyqml/components/chat/EventContent.qml @@ -2,7 +2,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.4 import "../base" as Base -import "get_event_text.js" as GetEventTextJS +import "utils.js" as ChatJS Row { id: row @@ -11,9 +11,7 @@ Row { anchors.right: isOwn ? parent.right : undefined readonly property string contentText: - (isMessage || isUndecryptableEvent) ? - "" : - GetEventTextJS.get_event_text(type, dict) + isMessage ? "" : ChatJS.get_event_text(type, dict) Base.Avatar { id: avatar @@ -24,7 +22,8 @@ Row { Base.HLabel { id: contentLabel - text: "" + + text: "" + displayName + " " + contentText + "  " + Qt.formatDateTime(date_time, "hh:mm:ss") + diff --git a/harmonyqml/components/chat/MessageContent.qml b/harmonyqml/components/chat/MessageContent.qml index 10801ab8..5d7f5680 100644 --- a/harmonyqml/components/chat/MessageContent.qml +++ b/harmonyqml/components/chat/MessageContent.qml @@ -38,9 +38,7 @@ Row { //"" + // (isOwn ? "  " + content : "") - text: (isUndecryptableEvent ? - "Missing decryption keys for this message." : - dict.formatted_body || dict.body) + + text: (dict.formatted_body || dict.body) + "  " + Qt.formatDateTime(date_time, "hh:mm:ss") + "" diff --git a/harmonyqml/components/chat/MessageDelegate.qml b/harmonyqml/components/chat/MessageDelegate.qml index 91caece4..6272e98a 100644 --- a/harmonyqml/components/chat/MessageDelegate.qml +++ b/harmonyqml/components/chat/MessageDelegate.qml @@ -55,7 +55,7 @@ Column { Daybreak { visible: dayBreak } - MessageContent { visible: isMessage || isUndecryptableEvent } + MessageContent { visible: isMessage } - EventContent { visible: ! (isMessage || isUndecryptableEvent) } + EventContent { visible: ! isMessage } } diff --git a/harmonyqml/components/chat/get_event_text.js b/harmonyqml/components/chat/utils.js similarity index 96% rename from harmonyqml/components/chat/get_event_text.js rename to harmonyqml/components/chat/utils.js index 8ca0abf0..f65e579a 100644 --- a/harmonyqml/components/chat/get_event_text.js +++ b/harmonyqml/components/chat/utils.js @@ -45,6 +45,10 @@ function get_event_text(type, dict) { return "turned on encryption for this room." break + case "OlmEvent": + case "MegolmEvent": + return "hasn't sent your device the keys to decrypt this message." + default: console.log(type + "\n" + JSON.stringify(dict, null, 4) + "\n") return "did something this client does not understand." diff --git a/harmonyqml/components/side_pane/RoomDelegate.qml b/harmonyqml/components/side_pane/RoomDelegate.qml index c0eec909..d5b88ba2 100644 --- a/harmonyqml/components/side_pane/RoomDelegate.qml +++ b/harmonyqml/components/side_pane/RoomDelegate.qml @@ -2,6 +2,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.4 import "../base" as Base +import "utils.js" as SidePaneJS MouseArea { id: "root" @@ -38,24 +39,10 @@ MouseArea { rightPadding: leftPadding } Base.HLabel { - property var msgModel: Backend.models.roomEvents.get(room_id) - - function get_text() { - if (msgModel.count < 1) { return "" } - - var msg = msgModel.get(-1) - var color_ = (msg.sender_id === roomList.user_id ? - "darkblue" : "purple") - - return "" + - Backend.getUser(msg.sender_id).display_name + - ": " + - msg.content - } - id: subtitleLabel visible: text !== "" - //text: msgModel.reloadThis, get_text() + text: Backend.models.roomEvents.get(room_id).reloadThis, + SidePaneJS.get_last_room_event_text(room_id) textFormat: Text.StyledText font.pixelSize: smallSize diff --git a/harmonyqml/components/side_pane/utils.js b/harmonyqml/components/side_pane/utils.js new file mode 100644 index 00000000..097bb764 --- /dev/null +++ b/harmonyqml/components/side_pane/utils.js @@ -0,0 +1,42 @@ +.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 = -1; i >= -eventsModel.count; i--) { + var ev = eventsModel.get(i) + + if (ev.type !== "RoomMemberEvent") { + var found = true + break + } + } + + if (! found) { return "" } + + var name = Backend.getUser(ev.dict.sender).display_name + 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 "" + + name + + ": " + + (undecryptable ? + "Undecryptable" : + ev.dict.body) + } else { + return "" + + name + + " " + + ChatJS.get_event_text(ev.type, ev.dict) + + "" + } +}