From aa496c511349d1a855e77122b3be22bc57e3a524 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Sun, 3 Feb 2013 12:25:11 +0100 Subject: [PATCH] Handle multiple contact resources --- src/gui/gtk/JubGtkRosterUI.m | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/gui/gtk/JubGtkRosterUI.m b/src/gui/gtk/JubGtkRosterUI.m index e474bf9..e59a79e 100644 --- a/src/gui/gtk/JubGtkRosterUI.m +++ b/src/gui/gtk/JubGtkRosterUI.m @@ -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: @"Resources:"]; + + [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: @": %@", 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); -- 2.39.5