]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Handle multiple contact resources
authorFlorian Zeitz <florob@babelmonkeys.de>
Sun, 3 Feb 2013 11:25:11 +0000 (12:25 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sun, 3 Feb 2013 11:25:11 +0000 (12:25 +0100)
src/gui/gtk/JubGtkRosterUI.m

index e474bf9bc2438b946860a277f5e477960a27ea73..e59a79ec6cd8d42de51d2e437eaf1041a644f74d 100644 (file)
@@ -316,6 +316,28 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
 -   (void)contact: (XMPPContact*)contact
   didSendPresence: (XMPPPresence*)presence
 {
+       OFDictionary *allPresences = [contact presences];
+       XMPPPresence *highPresence = [[[allPresences allObjects] sortedArray]
+                                        lastObject];
+       OFMutableString *tooltip =
+           [OFMutableString stringWithString: @"<b>Resources:</b>"];
+
+       [allPresences enumerateKeysAndObjectsUsingBlock:
+           ^(OFString *resource, XMPPPresence *pres, BOOL *stop) {
+               [tooltip appendString: @"\n"];
+               [tooltip appendString: resource];
+               if ([pres.type isEqual: @"available"]) {
+                       if (pres.show != nil)
+                               [tooltip appendFormat: @" (%@)", pres.show];
+                       else
+                               [tooltip appendString: @" (available)"];
+               } else
+                       [tooltip appendString: @" (unavailable)"];
+
+               if (pres.status)
+                       [tooltip appendFormat: @": <i>%@</i>", pres.status];
+       }];
+
        g_idle_add_block(^{
                GtkTreeIter iter;
                GtkTreePath *path;
@@ -330,19 +352,20 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
                            &iter, path);
                        gtk_tree_path_free(path);
 
-                       if ([presence.type isEqual: @"available"])
-                               if (presence.show != nil)
+                       if ([highPresence.type isEqual: @"available"]) {
+                               if (highPresence.show != nil)
                                        gtk_tree_store_set(roster_model, &iter,
-                                           2, [presence.show UTF8String], -1);
+                                           2, [highPresence.show UTF8String],
+                                           -1);
                                else
                                        gtk_tree_store_set(roster_model, &iter,
                                            2, "available", -1);
-                       else if ([presence.type isEqual: @"unavailable"])
+                       } else
                                gtk_tree_store_set(roster_model, &iter,
                                    2, "unavailable", -1);
 
                        gtk_tree_store_set(roster_model, &iter,
-                           3, [presence.status UTF8String], -1);
+                           3, [tooltip UTF8String], -1);
                }
 
                gtk_tree_model_filter_refilter(roster_filter);