Properly encode HTML entities for chat's last message

This commit is contained in:
Sebastian Wolf 2020-11-19 11:41:32 +01:00
parent 204966e265
commit e4dbb63a92
4 changed files with 22 additions and 3 deletions

View file

@ -17,7 +17,7 @@ PhotoTextsListItem {
// last user // 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") ) 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 // 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 // message date
tertiaryText.text: ( last_message_date ? Functions.getDateTimeElapsed(last_message_date) : qsTr("Unknown") ) + Emoji.emojify(last_message_status, tertiaryText.font.pixelSize) tertiaryText.text: ( last_message_date ? Functions.getDateTimeElapsed(last_message_date) : qsTr("Unknown") ) + Emoji.emojify(last_message_status, tertiaryText.font.pixelSize)
unreadCount: unread_count unreadCount: unread_count

View file

@ -160,7 +160,7 @@ ChatInformationTabItemBase {
onChatChanged: { onChatChanged: {
if (changedChatId === chat_id) { 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 :( // 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")
} }
} }
} }

View file

@ -226,6 +226,25 @@ function handleHtmlEntity(messageText, messageInsertions, originalString, replac
} }
} }
function enhanceHtmlEntities(simpleText) {
var messageInsertions = [];
var messageText = simpleText;
handleHtmlEntity(messageText, messageInsertions, "&", "&");
handleHtmlEntity(messageText, messageInsertions, "<", "&lt;");
handleHtmlEntity(messageText, messageInsertions, ">", "&gt;");
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) { function enhanceMessageText(formattedText) {
var messageInsertions = []; var messageInsertions = [];

View file

@ -245,7 +245,7 @@ Page {
onChatChanged: { onChatChanged: {
if (overviewPage.chatListCreated && changedChatId === chat_id) { 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 :( // 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")
} }
} }
} }