libpurple/protocols/jabber/roster.c

changeset 28071
a0706162fefd
parent 27743
ce49b08a7990
child 28322
ac8fec1d2234
equal deleted inserted replaced
28070:df31e9d5ad88 28071:a0706162fefd
64 64
65 g_slist_free(buddies); 65 g_slist_free(buddies);
66 } 66 }
67 67
68 static void add_purple_buddy_to_groups(JabberStream *js, const char *jid, 68 static void add_purple_buddy_to_groups(JabberStream *js, const char *jid,
69 const char *alias, GSList *groups, const char *own_jid) 69 const char *alias, GSList *groups)
70 { 70 {
71 GSList *buddies, *l; 71 GSList *buddies, *l;
72 GSList *pool = NULL; 72 GSList *pool = NULL;
73 73
74 buddies = purple_find_buddies(js->gc->account, jid); 74 buddies = purple_find_buddies(js->gc->account, jid);
160 } 160 }
161 161
162 purple_blist_add_buddy(b, NULL, g, NULL); 162 purple_blist_add_buddy(b, NULL, g, NULL);
163 purple_blist_alias_buddy(b, alias); 163 purple_blist_alias_buddy(b, alias);
164 164
165 /* If we just learned about ourself, then fake our status,
166 * because we won't be receiving a normal presence message
167 * about ourself. */
168 if(!strcmp(purple_buddy_get_name(b), own_jid))
169 jabber_presence_fake_to_self(js, NULL);
170
171 g_free(groups->data); 165 g_free(groups->data);
172 groups = g_slist_delete_link(groups, groups); 166 groups = g_slist_delete_link(groups, groups);
173 } 167 }
174 168
175 /* Remove this person from all the groups they're no longer in on the 169 /* Remove this person from all the groups they're no longer in on the
185 179
186 void jabber_roster_parse(JabberStream *js, const char *from, 180 void jabber_roster_parse(JabberStream *js, const char *from,
187 JabberIqType type, const char *id, xmlnode *query) 181 JabberIqType type, const char *id, xmlnode *query)
188 { 182 {
189 xmlnode *item, *group; 183 xmlnode *item, *group;
190 gchar *own_jid;
191 184
192 if (!jabber_is_own_account(js, from)) { 185 if (!jabber_is_own_account(js, from)) {
193 purple_debug_warning("jabber", "Received bogon roster push from %s\n", 186 purple_debug_warning("jabber", "Received bogon roster push from %s\n",
194 from); 187 from);
195 return; 188 return;
196 } 189 }
197 190
198 js->currently_parsing_roster_push = TRUE; 191 js->currently_parsing_roster_push = TRUE;
199
200 own_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
201 192
202 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) 193 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item))
203 { 194 {
204 const char *jid, *name, *subscription, *ask; 195 const char *jid, *name, *subscription, *ask;
205 JabberBuddy *jb; 196 JabberBuddy *jb;
214 205
215 if(!(jb = jabber_buddy_find(js, jid, TRUE))) 206 if(!(jb = jabber_buddy_find(js, jid, TRUE)))
216 continue; 207 continue;
217 208
218 if(subscription) { 209 if(subscription) {
219 gboolean me = FALSE; 210 if (jb == js->user_jb)
220
221 me = g_str_equal(own_jid, jabber_normalize(js->gc->account, jid));
222
223 if(me)
224 jb->subscription = JABBER_SUB_BOTH; 211 jb->subscription = JABBER_SUB_BOTH;
225 else if(!strcmp(subscription, "none")) 212 else if(!strcmp(subscription, "none"))
226 jb->subscription = JABBER_SUB_NONE; 213 jb->subscription = JABBER_SUB_NONE;
227 else if(!strcmp(subscription, "to")) 214 else if(!strcmp(subscription, "to"))
228 jb->subscription = JABBER_SUB_TO; 215 jb->subscription = JABBER_SUB_TO;
258 } 245 }
259 246
260 groups = g_slist_prepend(groups, group_name); 247 groups = g_slist_prepend(groups, group_name);
261 } 248 }
262 249
263 add_purple_buddy_to_groups(js, jid, name, groups, own_jid); 250 add_purple_buddy_to_groups(js, jid, name, groups);
264 } 251 if (jb == js->user_jb)
265 } 252 jabber_presence_fake_to_self(js, NULL);
266 253 }
267 g_free(own_jid); 254 }
255
268 js->currently_parsing_roster_push = FALSE; 256 js->currently_parsing_roster_push = FALSE;
269 257
270 /* if we're just now parsing the roster for the first time, 258 /* if we're just now parsing the roster for the first time,
271 * then now would be the time to declare ourselves connected. 259 * then now would be the time to declare ourselves connected.
272 */ 260 */
346 { 334 {
347 JabberStream *js = gc->proto_data; 335 JabberStream *js = gc->proto_data;
348 char *who; 336 char *who;
349 JabberBuddy *jb; 337 JabberBuddy *jb;
350 JabberBuddyResource *jbr; 338 JabberBuddyResource *jbr;
351 char *own_jid;
352 const char *name; 339 const char *name;
353 340
354 /* If we haven't received the roster yet, ignore any adds */ 341 /* If we haven't received the roster yet, ignore any adds */
355 if (js->state != JABBER_STREAM_CONNECTED) 342 if (js->state != JABBER_STREAM_CONNECTED)
356 return; 343 return;
364 purple_debug_info("jabber", "jabber_roster_add_buddy(): Adding %s\n", 351 purple_debug_info("jabber", "jabber_roster_add_buddy(): Adding %s\n",
365 name); 352 name);
366 353
367 jabber_roster_update(js, who, NULL); 354 jabber_roster_update(js, who, NULL);
368 355
369 own_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); 356 if (jb == js->user_jb) {
370 if (g_str_equal(who, own_jid)) {
371 jabber_presence_fake_to_self(js, NULL); 357 jabber_presence_fake_to_self(js, NULL);
372 } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) { 358 } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) {
373 jabber_presence_subscription_set(js, who, "subscribe"); 359 jabber_presence_subscription_set(js, who, "subscribe");
374 } else if((jbr =jabber_buddy_find_resource(jb, NULL))) { 360 } else if((jbr =jabber_buddy_find_resource(jb, NULL))) {
375 purple_prpl_got_user_status(gc->account, who, 361 purple_prpl_got_user_status(gc->account, who,
376 jabber_buddy_state_get_status_id(jbr->state), 362 jabber_buddy_state_get_status_id(jbr->state),
377 "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); 363 "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL);
378 } 364 }
379 365
380 g_free(own_jid);
381 g_free(who); 366 g_free(who);
382 } 367 }
383 368
384 void jabber_roster_alias_change(PurpleConnection *gc, const char *name, const char *alias) 369 void jabber_roster_alias_change(PurpleConnection *gc, const char *name, const char *alias)
385 { 370 {

mercurial