From 2b564384599973fdbba7c057e759eab8fde1c48e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 17 Feb 2022 16:54:21 -0500
Subject: [PATCH] interaction: better messages for notifications

Use best name in notifications and show banned members

https://git.jami.net/savoirfairelinux/jami-client-qt/-/issues/340
Change-Id: I79b76bdf036f32558414a949aebfec0f4700fa10
---
 src/api/interaction.h     | 10 +++++-----
 src/conversationmodel.cpp |  7 +++++++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/api/interaction.h b/src/api/interaction.h
index 64e5a924..8156db71 100644
--- a/src/api/interaction.h
+++ b/src/api/interaction.h
@@ -206,7 +206,7 @@ to_action(const QString& action)
         return ContactAction::JOIN;
     else if (action == "remove")
         return ContactAction::LEAVE;
-    else if (action == "banned")
+    else if (action == "ban")
         return ContactAction::BANNED;
     return ContactAction::INVALID;
 }
@@ -219,12 +219,13 @@ getContactInteractionString(const QString& authorUri, const ContactAction& actio
         if (authorUri.isEmpty()) {
             return QObject::tr("Contact added");
         }
-        return QObject::tr("Invitation received");
+        return QObject::tr("%1 was invited to join").arg(authorUri);
     case ContactAction::JOIN:
-        return QObject::tr("Invitation accepted");
+        return QObject::tr("%1 joined").arg(authorUri);
     case ContactAction::LEAVE:
-        return QObject::tr("Contact left conversation");
+        return QObject::tr("%1 left").arg(authorUri);
     case ContactAction::BANNED:
+        return QObject::tr("%1 was kicked").arg(authorUri);
     case ContactAction::INVALID:
         return {};
     }
@@ -289,7 +290,6 @@ struct Info
         isRead = false;
         if (type == Type::CONTACT) {
             authorUri = accountURI == message["uri"] ? "" : message["uri"];
-            body = getContactInteractionString(authorUri, to_action(message["action"]));
         } else if (type == Type::INITIAL) {
             body = QObject::tr("Swarm created");
         } else if (type == Type::CALL) {
diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp
index d109e893..a7102fd7 100644
--- a/src/conversationmodel.cpp
+++ b/src/conversationmodel.cpp
@@ -2282,6 +2282,13 @@ ConversationModelPimpl::slotConversationLoaded(uint32_t requestId,
                 downloadFile = (bytesProgress == 0);
             } else if (msg.type == interaction::Type::CALL) {
                 msg.body = storage::getCallInteractionString(msg.authorUri, msg.duration);
+            } else if (msg.type == interaction::Type::CONTACT) {
+                auto bestName = msg.authorUri == linked.owner.profileInfo.uri
+                                    ? linked.owner.accountModel->bestNameForAccount(linked.owner.id)
+                                    : linked.owner.contactModel->bestNameForContact(msg.authorUri);
+                msg.body = interaction::getContactInteractionString(bestName,
+                                                                    interaction::to_action(
+                                                                        message["action"]));
             }
             insertSwarmInteraction(msgId, msg, conversation, true);
             if (downloadFile) {
-- 
GitLab