From c7c8e2e8f61e23361ea1d935ad523b3da7f4d446 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 30 Jan 2023 16:43:49 -0500
Subject: [PATCH] misc: show "deleted message" for deleted message

So that users can know when a message is deleted and can check
previous version like any edited version.

Change-Id: If3c1daeec930bd4b0f359573b971790199397489
---
 src/app/commoncomponents/EditedPopup.qml         | 5 +++--
 src/app/commoncomponents/EmojiReactions.qml      | 2 +-
 src/app/commoncomponents/ReplyToRow.qml          | 2 +-
 src/app/commoncomponents/SBSMessageBase.qml      | 8 ++++----
 src/app/commoncomponents/TextMessageDelegate.qml | 2 +-
 src/app/constant/JamiStrings.qml                 | 1 +
 src/app/mainview/components/MessageListView.qml  | 3 +--
 src/libclient/messagelistmodel.cpp               | 9 +++++++--
 8 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/app/commoncomponents/EditedPopup.qml b/src/app/commoncomponents/EditedPopup.qml
index 2df12aef0..d85b03c7a 100644
--- a/src/app/commoncomponents/EditedPopup.qml
+++ b/src/app/commoncomponents/EditedPopup.qml
@@ -55,8 +55,9 @@ BaseModalDialog {
                     anchors.centerIn: parent
 
                     Text {
-                        Layout.preferredWidth: root.width / 4
+                        Layout.maximumWidth: root.width / 2
                         Layout.leftMargin: JamiTheme.settingsMarginSize
+                        elide: Text.ElideRight
 
                         text: MessagesAdapter.getFormattedDay(modelData.timestamp.toString())
                               + " - " + MessagesAdapter.getFormattedTime(modelData.timestamp.toString())
@@ -72,7 +73,7 @@ BaseModalDialog {
                             id: metrics
                             elide: Text.ElideRight
                             elideWidth: 3 * rowBody.width / 4 - 2 * JamiTheme.preferredMarginSize
-                            text: modelData.body
+                            text: modelData.body === "" ? JamiStrings.deletedMessage : modelData.body
                         }
 
                         text: metrics.elidedText
diff --git a/src/app/commoncomponents/EmojiReactions.qml b/src/app/commoncomponents/EmojiReactions.qml
index 83563bd3a..f991f17be 100644
--- a/src/app/commoncomponents/EmojiReactions.qml
+++ b/src/app/commoncomponents/EmojiReactions.qml
@@ -31,7 +31,7 @@ Item {
     property real contentWidth: bubble.width
     property var emojiTexts: ownEmojiList
 
-    visible: emojis ? emojis.length : false
+    visible: emojis.length && Body !== ""
 
     property string emojis: {
         var space = ""
diff --git a/src/app/commoncomponents/ReplyToRow.qml b/src/app/commoncomponents/ReplyToRow.qml
index 9e9a1449d..6dc194eea 100644
--- a/src/app/commoncomponents/ReplyToRow.qml
+++ b/src/app/commoncomponents/ReplyToRow.qml
@@ -88,7 +88,7 @@ Item {
                     id: metrics
                     elide: Text.ElideRight
                     elideWidth: JamiTheme.preferredFieldWidth - JamiTheme.preferredMarginSize
-                    text: ReplyToBody
+                    text: ReplyToBody === "" && ReplyToAuthor !== "" ? "*(Deleted Message)*" : ReplyToBody
                 }
 
                 textFormat: Text.MarkdownText
diff --git a/src/app/commoncomponents/SBSMessageBase.qml b/src/app/commoncomponents/SBSMessageBase.qml
index 688d596f0..686b710cb 100644
--- a/src/app/commoncomponents/SBSMessageBase.qml
+++ b/src/app/commoncomponents/SBSMessageBase.qml
@@ -174,10 +174,10 @@ Control {
                         anchors.verticalCenter: parent.verticalCenter
                         anchors.right: isOutgoing ? optionButtonItem.right : undefined
                         anchors.left: !isOutgoing ? optionButtonItem.left : undefined
-                        visible: bubbleArea.bubbleHovered
+                        visible: Body !== "" && (bubbleArea.bubbleHovered
                                  || hovered
                                  || reply.hovered
-                                 || bgHandler.hovered
+                                 || bgHandler.hovered)
                         source: JamiResources.more_vert_24dp_svg
                         width: optionButtonItem.width / 2
                         height: optionButtonItem.height
@@ -202,10 +202,10 @@ Control {
                         anchors.verticalCenter: parent.verticalCenter
                         anchors.right: isOutgoing ? more.left : undefined
                         anchors.left: !isOutgoing ? more.right : undefined
-                        visible: bubbleArea.bubbleHovered
+                        visible: Body !== "" && (bubbleArea.bubbleHovered
                                  || hovered
                                  || more.hovered
-                                 || bgHandler.hovered
+                                 || bgHandler.hovered)
 
                         onClicked: {
                             MessagesAdapter.editId = ""
diff --git a/src/app/commoncomponents/TextMessageDelegate.qml b/src/app/commoncomponents/TextMessageDelegate.qml
index 05feb3388..adaa0bbee 100644
--- a/src/app/commoncomponents/TextMessageDelegate.qml
+++ b/src/app/commoncomponents/TextMessageDelegate.qml
@@ -58,7 +58,7 @@ SBSMessageBase {
 
             padding: isEmojiOnly ? 0 : JamiTheme.preferredMarginSize
             anchors.right: isOutgoing ? parent.right : undefined
-            text: Body
+            text: Body === "" ? "*("+ JamiStrings.deletedMessage +")*" : Body
             horizontalAlignment: Text.AlignLeft
 
             HoverHandler {
diff --git a/src/app/constant/JamiStrings.qml b/src/app/constant/JamiStrings.qml
index 20ff8d70e..a00f6b9e3 100644
--- a/src/app/constant/JamiStrings.qml
+++ b/src/app/constant/JamiStrings.qml
@@ -352,6 +352,7 @@ Item {
     property string backendError: qsTr("This is the error from the backend: %0")
     property string disabledAccount: qsTr("The account is disabled")
     property string noNetworkConnectivity: qsTr("No network connectivity")
+    property string deletedMessage: qsTr("Deleted message")
 
     // Chatview footer
     property string jumpToLatest: qsTr("Jump to latest")
diff --git a/src/app/mainview/components/MessageListView.qml b/src/app/mainview/components/MessageListView.qml
index 4f3213299..009337b14 100644
--- a/src/app/mainview/components/MessageListView.qml
+++ b/src/app/mainview/components/MessageListView.qml
@@ -215,8 +215,7 @@ JamiListView {
             readonly property int mergeType: Interaction.Type.MERGE
             readonly property int editedType: Interaction.Type.EDITED
             readonly property int reactionType: Interaction.Type.REACTION
-            expression: Body !== ""
-                        && Type !== mergeType
+            expression: Type !== mergeType
                         && Type !== editedType
                         && Type !== reactionType
         }
diff --git a/src/libclient/messagelistmodel.cpp b/src/libclient/messagelistmodel.cpp
index a17bada72..4828e48ed 100644
--- a/src/libclient/messagelistmodel.cpp
+++ b/src/libclient/messagelistmodel.cpp
@@ -394,6 +394,8 @@ MessageListModel::roleNames() const
 bool
 MessageListModel::isOnlyEmoji(const QString& text) const
 {
+    if (text.isEmpty())
+        return false;
     auto codepointList = text.toUcs4();
     for (QList<uint>::iterator it = codepointList.begin(); it != codepointList.end(); it++) {
         auto cur = false;
@@ -418,7 +420,7 @@ QVariant
 MessageListModel::dataForItem(item_t item, int, int role) const
 {
     QString replyId = item.second.commit["reply-to"];
-    int repliedMsg;
+    int repliedMsg = -1;
     if (!replyId.isEmpty() && (role == Role::ReplyToAuthor || role == Role::ReplyToBody)) {
         repliedMsg = getIndexOfMessage(replyId);
     }
@@ -695,7 +697,10 @@ MessageListModel::editMessage(const QString& msgId, interaction::Info& info)
         }
         info.body = it->rbegin()->body;
         editedBodies_.erase(it);
-        emitDataChanged(msgId, {MessageList::Role::Body, MessageList::Role::PreviousBodies});
+        emitDataChanged(msgId,
+                        {MessageList::Role::Body,
+                         MessageList::Role::PreviousBodies,
+                         MessageList::Role::IsEmojiOnly});
 
         // Body changed, replies should update
         for (const auto& replyId : replyTo_[msgId]) {
-- 
GitLab