No html styling in processedEventText() + cleanups

This commit is contained in:
miruka 2019-11-30 08:14:39 -04:00
parent c8095f4874
commit db36ab6a74
3 changed files with 25 additions and 29 deletions

View File

@ -84,6 +84,7 @@ HRowLayout {
theme.chat.message.noticeBody : theme.chat.message.noticeBody :
theme.chat.message.body theme.chat.message.body
font.italic: model.event_type === "RoomMessageEmote"
wrapMode: TextEdit.Wrap wrapMode: TextEdit.Wrap
textFormat: Text.RichText textFormat: Text.RichText
text: text:

View File

@ -21,11 +21,8 @@ HTileDelegate {
Behavior on opacity { HNumberAnimation {} } Behavior on opacity { HNumberAnimation {} }
readonly property bool invited: readonly property bool invited: model.data.inviter_id && ! model.data.left
model.data.inviter_id && ! model.data.left readonly property var lastEvent: model.data.last_event
readonly property var eventDate:
model.data.last_event ? model.data.last_event.date : null
onActivated: pageLoader.showRoom(model.user_id, model.data.room_id) onActivated: pageLoader.showRoom(model.user_id, model.data.room_id)
@ -51,34 +48,36 @@ HTileDelegate {
rightInfo.color: theme.sidePane.room.lastEventDate rightInfo.color: theme.sidePane.room.lastEventDate
rightInfo.text: { rightInfo.text: {
! eventDate ? "" : ! lastEvent || ! lastEvent.date ?
"" :
Utils.dateIsToday(eventDate) ? Utils.dateIsToday(lastEvent.date) ?
Utils.formatTime(eventDate, false) : // no seconds Utils.formatTime(lastEvent.date, false) : // no seconds
eventDate.getFullYear() == new Date().getFullYear() ? lastEvent.date.getFullYear() == new Date().getFullYear() ?
Qt.formatDate(eventDate, "d MMM") : // e.g. "5 Dec" Qt.formatDate(lastEvent.date, "d MMM") : // e.g. "5 Dec"
eventDate.getFullYear() lastEvent.date.getFullYear()
} }
subtitle.color: theme.sidePane.room.subtitle subtitle.color: theme.sidePane.room.subtitle
subtitle.font.italic:
Boolean(lastEvent && lastEvent.event_type === "RoomMessageEmote")
subtitle.textFormat: Text.StyledText subtitle.textFormat: Text.StyledText
subtitle.text: { subtitle.text: {
if (! model.data.last_event) { return "" } if (! lastEvent) return ""
let ev = model.data.last_event
// If it's an emote or non-message/media event // If it's an emote or non-message/media event
if (ev.event_type === "RoomMessageEmote" || if (lastEvent.event_type === "RoomMessageEmote" ||
(! ev.event_type.startsWith("RoomMessage") && (! lastEvent.event_type.startsWith("RoomMessage") &&
! ev.event_type.startsWith("RoomEncrypted"))) { ! lastEvent.event_type.startsWith("RoomEncrypted")))
return Utils.processedEventText(ev) {
return Utils.processedEventText(lastEvent)
} }
let text = Utils.coloredNameHtml( let text = Utils.coloredNameHtml(
ev.sender_name, ev.sender_id lastEvent.sender_name, lastEvent.sender_id
) + ": " + ev.inline_content ) + ": " + lastEvent.inline_content
return text.replace( return text.replace(
/< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g, /< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g,

View File

@ -102,22 +102,18 @@ function escapeHtml(string) {
function processedEventText(ev) { function processedEventText(ev) {
if (ev.event_type == "RoomMessageEmote") { if (ev.event_type == "RoomMessageEmote")
return "<i>" + return coloredNameHtml(ev.sender_name, ev.sender_id) + " " + ev.content
coloredNameHtml(ev.sender_name, ev.sender_id) + " " +
ev.content + "</i>"
}
if (ev.event_type.startsWith("RoomMessage")) { return 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("RoomEncrypted")) return ev.content
let text = qsTr(ev.content).arg( let text = qsTr(ev.content).arg(
coloredNameHtml(ev.sender_name, ev.sender_id) 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)) text = text.arg(coloredNameHtml(ev.target_name, ev.target_id))
}
return text return text
} }