From f11c9f30cd96a3ad908c2a720d650cda072be33f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 1 Dec 2017 14:09:06 -0500
Subject: [PATCH] conversationsview: always retrieve the correct best id
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We used the registeredname as the best id, but it's not the case, we
need to get the best id from the registeredname or the uri.
note, remove useless TODO linked to the quality.

Change-Id: I1339d20ee1e4dd96c5c53b932b1fe262b6a53783
Reviewed-by: Nicolas Jäger <nicolas.jager@savoirfairelinux.com>
---
 src/chatview.cpp          |  5 +++--
 src/conversationsview.cpp | 26 ++++++++++++++++----------
 src/currentcallview.cpp   |  2 --
 3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/chatview.cpp b/src/chatview.cpp
index 03e3e608..0e4d0c34 100644
--- a/src/chatview.cpp
+++ b/src/chatview.cpp
@@ -306,10 +306,11 @@ update_contact_methods(ChatView *self)
     if (!priv->conversation_) return;
     auto contactUri = priv->conversation_->participants.front();
     auto contactInfo = priv->accountContainer_->info.contactModel->getContact(contactUri);
-    if (contactInfo.profileInfo.alias == contactInfo.registeredName) {
+    auto bestId = std::string(contactInfo.registeredName).empty() ? contactInfo.profileInfo.uri : contactInfo.registeredName;
+    if (contactInfo.profileInfo.alias == bestId) {
         gtk_widget_hide(priv->label_cm);
     } else {
-        gtk_label_set_text(GTK_LABEL(priv->label_cm), contactInfo.registeredName.c_str());
+        gtk_label_set_text(GTK_LABEL(priv->label_cm), bestId.c_str());
         gtk_widget_show(priv->label_cm);
     }
 
diff --git a/src/conversationsview.cpp b/src/conversationsview.cpp
index b89d402d..54504ca3 100644
--- a/src/conversationsview.cpp
+++ b/src/conversationsview.cpp
@@ -121,23 +121,26 @@ render_name_and_last_interaction(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
     gchar *lastInteraction;
     gchar *text;
     gchar *uid;
+    gchar *uri;
 
     gtk_tree_model_get (model, iter,
                         0 /* col# */, &uid /* data */,
                         1 /* col# */, &alias /* data */,
-                        2 /* col# */, &registeredName /* data */,
-                        4 /* col# */, &lastInteraction /* data */,
+                        2 /* col# */, &uri /* data */,
+                        3 /* col# */, &registeredName /* data */,
+                        5 /* col# */, &lastInteraction /* data */,
                         -1);
 
+    auto bestId = std::string(registeredName).empty() ? uri: registeredName;
     if (std::string(alias).empty()) {
         // For conversations with contacts with no alias
         text = g_markup_printf_escaped(
             "<span font_weight=\"bold\">%s</span>\n<span size=\"smaller\" color=\"#666\">%s</span>",
-            registeredName,
+            bestId,
             lastInteraction
         );
-    } else if (std::string(alias) == std::string(registeredName)
-        || std::string(registeredName).empty() || std::string(uid).empty()) {
+    } else if (std::string(alias) == std::string(bestId)
+        || std::string(bestId).empty() || std::string(uid).empty()) {
         // For temporary item
         text = g_markup_printf_escaped(
             "<span font_weight=\"bold\">%s</span>\n<span size=\"smaller\" color=\"#666\">%s</span>",
@@ -149,13 +152,14 @@ render_name_and_last_interaction(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
         text = g_markup_printf_escaped(
             "<span font_weight=\"bold\">%s</span>\n<span size=\"smaller\" color=\"#666\">%s</span>\n<span size=\"smaller\" color=\"#666\">%s</span>",
             alias,
-            registeredName,
+            bestId,
             lastInteraction
         );
     }
 
     g_object_set(G_OBJECT(cell), "markup", text, NULL);
     g_free(uid);
+    g_free(uri);
     g_free(alias);
     g_free(registeredName);
 }
@@ -222,7 +226,8 @@ static GtkTreeModel*
 create_and_fill_model(ConversationsView *self)
 {
     auto priv = CONVERSATIONS_VIEW_GET_PRIVATE(self);
-    auto store = gtk_list_store_new (5 /* # of cols */ ,
+    auto store = gtk_list_store_new (6 /* # of cols */ ,
+                                     G_TYPE_STRING,
                                      G_TYPE_STRING,
                                      G_TYPE_STRING,
                                      G_TYPE_STRING,
@@ -245,9 +250,10 @@ create_and_fill_model(ConversationsView *self)
         gtk_list_store_set (store, &iter,
             0 /* col # */ , conversation.uid.c_str() /* celldata */,
             1 /* col # */ , alias.c_str() /* celldata */,
-            2 /* col # */ , contactInfo.registeredName.c_str() /* celldata */,
-            3 /* col # */ , contactInfo.profileInfo.avatar.c_str() /* celldata */,
-            4 /* col # */ , lastMessage.c_str() /* celldata */,
+            2 /* col # */ , contactInfo.profileInfo.uri.c_str() /* celldata */,
+            3 /* col # */ , contactInfo.registeredName.c_str() /* celldata */,
+            4 /* col # */ , contactInfo.profileInfo.avatar.c_str() /* celldata */,
+            5 /* col # */ , lastMessage.c_str() /* celldata */,
             -1 /* end */);
     }
 
diff --git a/src/currentcallview.cpp b/src/currentcallview.cpp
index 6bcd70aa..932efe4c 100644
--- a/src/currentcallview.cpp
+++ b/src/currentcallview.cpp
@@ -378,7 +378,6 @@ set_quality(Call *call, gboolean auto_quality_on, double desired_quality)
 static void
 autoquality_toggled(GtkToggleButton *button, CurrentCallView *self)
 {
-    // TODO
     g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
     CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
 
@@ -406,7 +405,6 @@ autoquality_toggled(GtkToggleButton *button, CurrentCallView *self)
 static void
 quality_changed(G_GNUC_UNUSED GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self)
 {
-    // TODO
     g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
     CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
 
-- 
GitLab