From db36ab6a74f72df37d404ffcac0d611498fb6798 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 30 Nov 2019 08:14:39 -0400 Subject: [PATCH] No html styling in processedEventText() + cleanups --- src/qml/Chat/Timeline/EventContent.qml | 1 + src/qml/SidePane/RoomDelegate.qml | 39 +++++++++++++------------- src/qml/utils.js | 14 ++++----- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/qml/Chat/Timeline/EventContent.qml b/src/qml/Chat/Timeline/EventContent.qml index 452aceb5..5e6cb86a 100644 --- a/src/qml/Chat/Timeline/EventContent.qml +++ b/src/qml/Chat/Timeline/EventContent.qml @@ -84,6 +84,7 @@ HRowLayout { theme.chat.message.noticeBody : theme.chat.message.body + font.italic: model.event_type === "RoomMessageEmote" wrapMode: TextEdit.Wrap textFormat: Text.RichText text: diff --git a/src/qml/SidePane/RoomDelegate.qml b/src/qml/SidePane/RoomDelegate.qml index 2d1ad9c3..510ddd30 100644 --- a/src/qml/SidePane/RoomDelegate.qml +++ b/src/qml/SidePane/RoomDelegate.qml @@ -21,11 +21,8 @@ HTileDelegate { Behavior on opacity { HNumberAnimation {} } - readonly property bool invited: - model.data.inviter_id && ! model.data.left - - readonly property var eventDate: - model.data.last_event ? model.data.last_event.date : null + readonly property bool invited: model.data.inviter_id && ! model.data.left + readonly property var lastEvent: model.data.last_event onActivated: pageLoader.showRoom(model.user_id, model.data.room_id) @@ -51,34 +48,36 @@ HTileDelegate { rightInfo.color: theme.sidePane.room.lastEventDate rightInfo.text: { - ! eventDate ? "" : + ! lastEvent || ! lastEvent.date ? + "" : - Utils.dateIsToday(eventDate) ? - Utils.formatTime(eventDate, false) : // no seconds + Utils.dateIsToday(lastEvent.date) ? + Utils.formatTime(lastEvent.date, false) : // no seconds - eventDate.getFullYear() == new Date().getFullYear() ? - Qt.formatDate(eventDate, "d MMM") : // e.g. "5 Dec" + lastEvent.date.getFullYear() == new Date().getFullYear() ? + Qt.formatDate(lastEvent.date, "d MMM") : // e.g. "5 Dec" - eventDate.getFullYear() + lastEvent.date.getFullYear() } subtitle.color: theme.sidePane.room.subtitle + subtitle.font.italic: + Boolean(lastEvent && lastEvent.event_type === "RoomMessageEmote") subtitle.textFormat: Text.StyledText subtitle.text: { - if (! model.data.last_event) { return "" } - - let ev = model.data.last_event + if (! lastEvent) return "" // If it's an emote or non-message/media event - if (ev.event_type === "RoomMessageEmote" || - (! ev.event_type.startsWith("RoomMessage") && - ! ev.event_type.startsWith("RoomEncrypted"))) { - return Utils.processedEventText(ev) + if (lastEvent.event_type === "RoomMessageEmote" || + (! lastEvent.event_type.startsWith("RoomMessage") && + ! lastEvent.event_type.startsWith("RoomEncrypted"))) + { + return Utils.processedEventText(lastEvent) } let text = Utils.coloredNameHtml( - ev.sender_name, ev.sender_id - ) + ": " + ev.inline_content + lastEvent.sender_name, lastEvent.sender_id + ) + ": " + lastEvent.inline_content return text.replace( /< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g, diff --git a/src/qml/utils.js b/src/qml/utils.js index 46aa7072..9e5177b9 100644 --- a/src/qml/utils.js +++ b/src/qml/utils.js @@ -102,22 +102,18 @@ function escapeHtml(string) { function processedEventText(ev) { - if (ev.event_type == "RoomMessageEmote") { - return "" + - coloredNameHtml(ev.sender_name, ev.sender_id) + " " + - ev.content + "" - } + if (ev.event_type == "RoomMessageEmote") + return coloredNameHtml(ev.sender_name, ev.sender_id) + " " + ev.content - if (ev.event_type.startsWith("RoomMessage")) { return ev.content } - if (ev.event_type.startsWith("RoomEncrypted")) { return ev.content } + if (ev.event_type.startsWith("RoomMessage")) return ev.content + if (ev.event_type.startsWith("RoomEncrypted")) return ev.content let text = qsTr(ev.content).arg( coloredNameHtml(ev.sender_name, ev.sender_id) ) - if (text.includes("%2") && ev.target_id) { + if (text.includes("%2") && ev.target_id) text = text.arg(coloredNameHtml(ev.target_name, ev.target_id)) - } return text }