changeset 6840:b67670ac5584

[gaim-migrate @ 7385] Tim Ringenbach (marv_sf) writes: " This fixes the following bugs: Deleting a buddy didn't make the prpl realize he was no longer on the server list (until signoff/signon), so adding his back yet failing didn't seem to fail. Adding a buddy that was offline showed him as not on server list until signoff/signon or he came online. Adding a buddy to a 2nd group actually added him a 2nd time to his first group on the server list (which isn't allowed, so generated an error) This also adds an error when adding to the server list fails for any reason except already being on the list. This also makes the error when a buddy rejects us a little nicer looking." committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 14 Sep 2003 21:21:32 +0000
parents bdc4e73f354d
children f76e26a0e6a9
files src/protocols/yahoo/yahoo.c
diffstat 1 files changed, 82 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/yahoo/yahoo.c	Sun Sep 14 21:08:56 2003 +0000
+++ b/src/protocols/yahoo/yahoo.c	Sun Sep 14 21:21:32 2003 +0000
@@ -299,10 +299,15 @@
 
 static void yahoo_update_status(GaimConnection *gc, const char *name, struct yahoo_friend *f)
 {
+	int online = 1;
+
 	if (!gc || !name || !f || !gaim_find_buddy(gaim_connection_get_account(gc), name))
 		return;
 
-	serv_got_update(gc, name, 1, 0, 0, f->idle, f->away ? UC_UNAVAILABLE : 0);
+	if (f->status == YAHOO_STATUS_OFFLINE)
+		online = 0;
+
+	serv_got_update(gc, name, online, 0, 0, f->idle, f->away ? UC_UNAVAILABLE : 0);
 }
 
 static void yahoo_process_status(GaimConnection *gc, struct yahoo_packet *pkt)
@@ -747,7 +752,7 @@
 			g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list."), who);
 		else
 			g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list for the following reason: %s."), who, msg);
-		gaim_notify_info(gc, NULL, buf->str, NULL);
+		gaim_notify_info(gc, NULL, _("Add buddy rejected"), buf->str);
 		g_string_free(buf, TRUE);
 		g_hash_table_remove(yd->friends, who);
 		serv_got_update(gc, who, 0, 0, 0, 0, 0);
@@ -1082,6 +1087,54 @@
 	gaim_connection_error(gc, msg);
 }
 
+static void yahoo_process_addbuddy(GaimConnection *gc, struct yahoo_packet *pkt)
+{
+	int err = 0;
+	char *who = NULL;
+	char *group = NULL;
+	char *buf;
+	struct yahoo_friend *f;
+	struct yahoo_data *yd = gc->proto_data;
+	GSList *l = pkt->hash;
+
+	while (l) {
+		struct yahoo_pair *pair = l->data;
+
+		switch (pair->key) {
+		case 66:
+			err = strtol(pair->value, NULL, 10);
+			break;
+		case 7:
+			who = pair->value;
+			break;
+		case 65:
+			group = pair->value;
+			break;
+		}
+
+		l = l->next;
+	}
+
+	if (!who)
+		return;
+	if (!group)
+		group = "";
+
+	if (!err || (err == 2)) { /* 0 = ok, 2 = already on serv list */
+		if (!g_hash_table_lookup(yd->friends, who)) {
+			f = yahoo_friend_new();
+			g_hash_table_insert(yd->friends, g_strdup(who), f);
+			yahoo_update_status(gc, who, f);
+		}
+		return;
+	}
+
+	buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."),
+				who, group, gaim_connection_get_display_name(gc));
+	gaim_notify_error(gc, NULL, _("Could not add buddy to server list"), buf);
+	g_free(buf);
+}
+
 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt)
 {
 	switch (pkt->service) {
@@ -1118,6 +1171,9 @@
 	case YAHOO_SERVICE_AUTH:
 		yahoo_process_auth(gc, pkt);
 		break;
+	case YAHOO_SERVICE_ADDBUDDY:
+		yahoo_process_addbuddy(gc, pkt);
+		break;
 	case YAHOO_SERVICE_IGNORECONTACT:
 		yahoo_process_ignore(gc, pkt);
 		break;
@@ -1781,11 +1837,15 @@
 	if (!yd->logged_in)
 		return;
 
-	g = gaim_find_buddys_group(gaim_find_buddy(gc->account, who));
-	if (g)
-		group = g->name;
-	else
-		group = "Buddies";
+	if (foo)
+		group = foo->name;
+	if (!group) {
+		g = gaim_find_buddys_group(gaim_find_buddy(gc->account, who));
+		if (g)
+			group = g->name;
+		else
+			group = "Buddies";
+	}
 
 	pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0);
 	yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
@@ -1801,11 +1861,25 @@
 	struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
 	struct yahoo_friend *f;
         struct yahoo_packet *pkt;
+	GSList *buddies, *l;
+	GaimGroup *g;
+	gboolean remove = TRUE;
 
 	if (!(f = g_hash_table_lookup(yd->friends, who)))
 		return;
 
-	if (!gaim_find_buddy(gaim_connection_get_account(gc), who))
+	buddies = gaim_find_buddies(gaim_connection_get_account(gc), who);
+	for (l = buddies; l; l = l->next) {
+		g = gaim_find_buddys_group(l->data);
+		if (gaim_utf8_strcasecmp(group, g->name)) {
+			remove = FALSE;
+			break;
+		}
+	}
+
+	g_slist_free(buddies);
+
+	if (remove)
 		g_hash_table_remove(yd->friends, who);
 
 	pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0);