From e4dbb63a923b82f44aa4d40a92c5eca8421f2362 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Thu, 19 Nov 2020 11:41:32 +0100 Subject: [PATCH] Properly encode HTML entities for chat's last message --- qml/components/ChatListViewItem.qml | 2 +- .../ChatInformationTabItemMembersGroups.qml | 2 +- qml/js/functions.js | 19 +++++++++++++++++++ qml/pages/OverviewPage.qml | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/qml/components/ChatListViewItem.qml b/qml/components/ChatListViewItem.qml index b584d00..c6b8a6f 100644 --- a/qml/components/ChatListViewItem.qml +++ b/qml/components/ChatListViewItem.qml @@ -17,7 +17,7 @@ PhotoTextsListItem { // last user prologSecondaryText.text: is_channel ? "" : ( last_message_sender_id ? ( last_message_sender_id !== ownUserId ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(last_message_sender_id)), primaryText.font.pixelSize) : qsTr("You") ) : qsTr("Unknown") ) // last message - secondaryText.text: last_message_text ? Emoji.emojify(last_message_text, Theme.fontSizeExtraSmall, emojiBase) : qsTr("Unknown") + secondaryText.text: last_message_text ? Emoji.emojify(Functions.enhanceHtmlEntities(last_message_text), Theme.fontSizeExtraSmall, emojiBase) : qsTr("Unknown") // message date tertiaryText.text: ( last_message_date ? Functions.getDateTimeElapsed(last_message_date) : qsTr("Unknown") ) + Emoji.emojify(last_message_status, tertiaryText.font.pixelSize) unreadCount: unread_count diff --git a/qml/components/chatInformationPage/ChatInformationTabItemMembersGroups.qml b/qml/components/chatInformationPage/ChatInformationTabItemMembersGroups.qml index 28bb536..ef0ddc1 100644 --- a/qml/components/chatInformationPage/ChatInformationTabItemMembersGroups.qml +++ b/qml/components/chatInformationPage/ChatInformationTabItemMembersGroups.qml @@ -160,7 +160,7 @@ ChatInformationTabItemBase { onChatChanged: { if (changedChatId === chat_id) { // Force update of some list item elements (currently only last message text seems to create problems). dataChanged() doesn't seem to trigger them all :( - secondaryText.text = last_message_text ? Emoji.emojify(last_message_text, Theme.fontSizeExtraSmall, "../../js/emoji/") : qsTr("Unknown") + secondaryText.text = last_message_text ? Emoji.emojify(Functions.enhanceHtmlEntities(last_message_text), Theme.fontSizeExtraSmall, "../../js/emoji/") : qsTr("Unknown") } } } diff --git a/qml/js/functions.js b/qml/js/functions.js index 67f7838..9fd5e98 100644 --- a/qml/js/functions.js +++ b/qml/js/functions.js @@ -226,6 +226,25 @@ function handleHtmlEntity(messageText, messageInsertions, originalString, replac } } +function enhanceHtmlEntities(simpleText) { + + var messageInsertions = []; + var messageText = simpleText; + + handleHtmlEntity(messageText, messageInsertions, "&", "&"); + handleHtmlEntity(messageText, messageInsertions, "<", "<"); + handleHtmlEntity(messageText, messageInsertions, ">", ">"); + + messageInsertions.sort( function(a, b) { return (b.offset+b.removeLength) - (a.offset+a.removeLength) } ); + + for (var z = 0; z < messageInsertions.length; z++) { + messageText = messageText.substring(0, messageInsertions[z].offset) + messageInsertions[z].insertionString + messageText.substring(messageInsertions[z].offset + messageInsertions[z].removeLength); + } + + return messageText; + +} + function enhanceMessageText(formattedText) { var messageInsertions = []; diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index 27a9113..ee55c1f 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -245,7 +245,7 @@ Page { onChatChanged: { if (overviewPage.chatListCreated && changedChatId === chat_id) { // Force update of some list item elements (currently only last message text seems to create problems). dataChanged() doesn't seem to trigger them all :( - secondaryText.text = last_message_text ? Emoji.emojify(last_message_text, Theme.fontSizeExtraSmall) : qsTr("Unknown") + secondaryText.text = last_message_text ? Emoji.emojify(Functions.enhanceHtmlEntities(last_message_text), Theme.fontSizeExtraSmall) : qsTr("Unknown") } } }