comparison src/protocols/jabber/presence.c @ 12285:af257d8679fe

[gaim-migrate @ 14589] Ok, so I'm changing the semantics of gaim_account_notify_added, having it check for the existance of a buddy was breaking some jabber scenarios. So buddy checks should now be done in the prpls. I also added a gaim_account_request_add. _notify_added only notifies the user of the add, request_add notifies the user AND asks them if they want to add the buddy to their buddy list. I only updated jabber for these changes because it's the only protocol I really know at all well. So everyone PLEASE make sure that the other protocols get updated for this. That is make sure that when you expect to prompt the user to add the buddy you use _request_add instead of just using _notify_added and expecting the core to determine if it needs to prompt the user. Oh, there are also some other jabber changes which should hopefully fix some issues that people were seeing, like buddies not signing off when you unsubscribed with them, etc. Let me know if anyone notices any jabber oddities after this. committer: Tailor Script <tailor@pidgin.im>
author Etan Reisner <pidgin@unreliablesource.net>
date Thu, 01 Dec 2005 20:09:27 +0000
parents f82b6d559ea7
children e4e47871c373
comparison
equal deleted inserted replaced
12284:ecd471d1eeec 12285:af257d8679fe
169 169
170 return presence; 170 return presence;
171 } 171 }
172 172
173 struct _jabber_add_permit { 173 struct _jabber_add_permit {
174 JabberStream *js;
174 GaimConnection *gc; 175 GaimConnection *gc;
175 char *who; 176 char *who;
176 }; 177 };
177 178
178 static void authorize_add_cb(struct _jabber_add_permit *jap) 179 static void authorize_add_cb(struct _jabber_add_permit *jap)
179 { 180 {
180 if(g_list_find(gaim_connections_get_all(), jap->gc)) { 181 if(g_list_find(gaim_connections_get_all(), jap->gc)) {
182 GaimBuddy *buddy = NULL;
183
181 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, 184 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
182 "subscribed"); 185 "subscribed");
183 186
184 if(!gaim_find_buddy(jap->gc->account, jap->who)) 187 buddy = gaim_find_buddy(jap->gc->account, jap->who);
185 gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL); 188
189 if (buddy) {
190 JabberBuddy *jb = NULL;
191
192 jb = jabber_buddy_find(jap->js, jap->who, TRUE);
193
194 if ((jb->subscription & JABBER_SUB_TO) == 0) {
195 gaim_account_request_add(jap->gc->account,
196 jap->who, NULL,
197 NULL, NULL);
198 } else {
199 gaim_account_notify_added(jap->gc->account,
200 jap->who, NULL,
201 NULL, NULL);
202 }
203 } else {
204 gaim_account_request_add(jap->gc->account, jap->who,
205 NULL, NULL, NULL);
206 }
186 } 207 }
187 208
188 g_free(jap->who); 209 g_free(jap->who);
189 g_free(jap); 210 g_free(jap);
190 } 211 }
289 msg = g_strdup_printf(_("The user %s wants to add %s to his or " 310 msg = g_strdup_printf(_("The user %s wants to add %s to his or "
290 "her buddy list."), 311 "her buddy list."),
291 from, gaim_account_get_username(js->gc->account)); 312 from, gaim_account_get_username(js->gc->account));
292 jap->gc = js->gc; 313 jap->gc = js->gc;
293 jap->who = g_strdup(from); 314 jap->who = g_strdup(from);
315 jap->js = js;
294 316
295 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, 317 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE,
296 jap, 2, 318 jap, 2,
297 _("Authorize"), G_CALLBACK(authorize_add_cb), 319 _("Authorize"), G_CALLBACK(authorize_add_cb),
298 _("Deny"), G_CALLBACK(deny_add_cb)); 320 _("Deny"), G_CALLBACK(deny_add_cb));
299 g_free(msg); 321 g_free(msg);
300 jabber_id_free(jid); 322 jabber_id_free(jid);
301 return; 323 return;
302 } else if(type && !strcmp(type, "subscribed")) { 324 } else if(type && !strcmp(type, "subscribed")) {
303 /* we've been allowed to see their presence, but we don't care */ 325 /* we've been allowed to see their presence, but we don't care */
326 jabber_id_free(jid);
327 return;
328 } else if(type && !strcmp(type, "unsubscribe")) {
329 /* XXX I'm not sure this is the right way to handle this, it
330 * might be better to add "unsubscribe" to the presence status
331 * if lower down, but I'm not sure. */
332 /* they are unsubscribing from our presence, we don't care */
333 /* Well, maybe just a little, we might want/need to start
334 * acknowledging this (and the others) at some point. */
304 jabber_id_free(jid); 335 jabber_id_free(jid);
305 return; 336 return;
306 } else { 337 } else {
307 if((y = xmlnode_get_child(packet, "show"))) { 338 if((y = xmlnode_get_child(packet, "show"))) {
308 char *show = xmlnode_get_data(y); 339 char *show = xmlnode_get_data(y);
491 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, 522 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource,
492 flags); 523 flags);
493 } 524 }
494 g_free(room_jid); 525 g_free(room_jid);
495 } else { 526 } else {
496 if(state != JABBER_BUDDY_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO || jb->subscription & JABBER_SUB_PENDING)) {
497 gaim_debug(GAIM_DEBUG_INFO, "jabber",
498 "got unexpected presence from %s, ignoring\n", from);
499 jabber_id_free(jid);
500 g_free(status);
501 if(avatar_hash)
502 g_free(avatar_hash);
503 return;
504 }
505
506 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", 527 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "",
507 jid->node ? "@" : "", jid->domain); 528 jid->node ? "@" : "", jid->domain);
508 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { 529 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) {
509 jabber_id_free(jid); 530 jabber_id_free(jid);
510 if(avatar_hash) 531 if(avatar_hash)