conversationsview: always retrieve the correct best id

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>
diff --git a/src/chatview.cpp b/src/chatview.cpp
index 03e3e60..0e4d0c3 100644
--- a/src/chatview.cpp
+++ b/src/chatview.cpp
@@ -306,10 +306,11 @@
     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 b89d402..54504ca 100644
--- a/src/conversationsview.cpp
+++ b/src/conversationsview.cpp
@@ -121,23 +121,26 @@
     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 @@
         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 @@
 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 @@
         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 6bcd70a..932efe4 100644
--- a/src/currentcallview.cpp
+++ b/src/currentcallview.cpp
@@ -378,7 +378,6 @@
 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 @@
 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);