]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-roster-view.c
sort contacts by most recent event
[empathy.git] / libempathy-gtk / empathy-roster-view.c
index e3d8c7a6e9ba54443c18975d0c962b93f622f2ff..e463bd9f0ac539f53a2437b1c1e1112902f4213a 100644 (file)
@@ -189,6 +189,10 @@ add_roster_contact (EmpathyRosterView *self,
   g_signal_connect (contact, "notify::alias",
       G_CALLBACK (roster_contact_changed_cb), self);
 
+  /* Need to resort if most recent event changed */
+  g_signal_connect (contact, "notify::most-recent-event",
+      G_CALLBACK (roster_contact_changed_cb), self);
+
   gtk_widget_show (contact);
   gtk_container_add (GTK_CONTAINER (self), contact);
 
@@ -196,9 +200,9 @@ add_roster_contact (EmpathyRosterView *self,
 }
 
 static void
-group_expanded_cb (EmpathyRosterGroup *group,
+group_expanded_cb (GtkWidget *expander,
     GParamSpec *spec,
-    EmpathyRosterView *self)
+    EmpathyRosterGroup *group)
 {
   GList *widgets, *l;
 
@@ -241,8 +245,8 @@ ensure_roster_group (EmpathyRosterView *self,
   gtk_expander_set_expanded (EMPATHY_ROSTER_GROUP (roster_group)->expander,
       empathy_contact_group_get_expanded (group));
 
-  g_signal_connect (roster_group, "notify::expanded",
-      G_CALLBACK (group_expanded_cb), self);
+  g_signal_connect (EMPATHY_ROSTER_GROUP (roster_group)->expander,
+      "notify::expanded", G_CALLBACK (group_expanded_cb), roster_group);
 
   gtk_widget_show (roster_group);
   gtk_container_add (GTK_CONTAINER (self), roster_group);
@@ -625,6 +629,20 @@ contact_in_top (EmpathyRosterView *self,
   return FALSE;
 }
 
+static gint
+compare_roster_contacts_by_conversation_time (EmpathyRosterContact *a,
+    EmpathyRosterContact *b)
+{
+  gint64 ts_a, ts_b;
+
+  ts_a = empathy_roster_contact_get_most_recent_timestamp (a);
+  ts_b = empathy_roster_contact_get_most_recent_timestamp (b);
+
+  if (ts_a == ts_b) return 0;
+  if (ts_a > ts_b) return -1;
+  return 1;
+}
+
 static gint
 compare_roster_contacts_by_alias (EmpathyRosterContact *a,
     EmpathyRosterContact *b)
@@ -654,7 +672,7 @@ compare_roster_contacts_no_group (EmpathyRosterView *self,
   if (top_a == top_b)
     /* Both contacts are in the top of the roster (or not). Sort them
      * alphabetically */
-    return compare_roster_contacts_by_alias (a, b);
+    return compare_roster_contacts_by_conversation_time (a, b);
   else if (top_a)
     return -1;
   else
@@ -691,7 +709,7 @@ compare_roster_contacts_with_groups (EmpathyRosterView *self,
 
   if (!tp_strdiff (group_a, group_b))
     /* Same group, compare the contacts */
-    return compare_roster_contacts_by_alias (a, b);
+    return compare_roster_contacts_by_conversation_time (a, b);
 
   /* Sort by group */
   return compare_group_names (group_a, group_b);
@@ -768,11 +786,11 @@ update_header (GtkListBoxRow *row,
   if (before == NULL)
     {
       /* No separator before the first row */
-      gtk_list_box_row_set_header(row, NULL);
+      gtk_list_box_row_set_header (row, NULL);
       return;
     }
 
-  if (gtk_list_box_row_get_header(row) != NULL)
+  if (gtk_list_box_row_get_header (row) != NULL)
     return;
 
   gtk_list_box_row_set_header (row,