From e6b0149d25b983551590516d1e93edad2a23b3b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 16 Feb 2022 14:49:01 -0500
Subject: [PATCH] conversationmodel: avoid too long titles

https://git.jami.net/savoirfairelinux/jami-client-qt/-/issues/670

Change-Id: Ifbf8ba04a7a00f583ec0ec932ca07c8e1a9cf4fc
---
 src/conversationmodel.cpp | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp
index 41db5deb..d109e893 100644
--- a/src/conversationmodel.cpp
+++ b/src/conversationmodel.cpp
@@ -1041,18 +1041,29 @@ ConversationModel::title(const QString& conversationId) const
     }
     // NOTE: Do not call any daemon method there as title() is called a lot for drawing
     QString title;
-    auto idx = 0;
+    auto idx = 0u;
+    auto others = 0;
     for (const auto& member : conversation.participants) {
+        QString name;
         if (member.uri == owner.profileInfo.uri) {
-            title += owner.accountModel->bestNameForAccount(owner.id);
+            name = owner.accountModel->bestNameForAccount(owner.id);
         } else {
-            title += owner.contactModel->bestNameForContact(member.uri);
+            name = owner.contactModel->bestNameForContact(member.uri);
         }
+        if (title.length() + name.length() > 32) {
+            // Avoid too long titles
+            others += 1;
+            continue;
+        }
+        title += name;
         idx += 1;
-        if (idx != conversation.participants.size()) {
+        if (idx != conversation.participants.size() || others != 0) {
             title += ", ";
         }
     }
+    if (others != 0) {
+        title += QString("+ %1").arg(others);
+    }
     return title;
 }
 
-- 
GitLab