~ubuntu-branches/ubuntu/hardy/pidgin/hardy

« back to all changes in this revision

Viewing changes to libpurple/protocols/msnp9/userlist.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-12-21 02:48:06 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071221024806-pd44a5k9tiyh12mp
Tags: 1:2.3.1-2ubuntu1
* Sync with Debian, remaining Ubuntu changes; (LP: #177811)
  - Set Maintainer to Ubuntu Core Developers.
  - Add build-deps on liblaunchpad-integration-dev, intltool,
    libnm-glib-dev (for --enable-nm) (Ubuntu #112720).
  - Drop build-deps on libsilc-1.1-2-dev | libsilc-dev (>= 1.1.1) as 
    this library is in universe.
  - Drop the libpurple0 recommends on libpurple-bin.
  - Add a gaim transitionnal package for upgrades.
  - Ship compatibility symlinks via debian/gaim.links.
  - Pass --enable-nm to configure to enable NetworkManager support.
  - Pass --disable-silc to configure to disable silc support even if 
    it's installed in the build environment.
  - Add X-Ubuntu-Gettext-Domain to the desktop file and update the
    translation templates in common-install-impl::.
   - Update debian/prefs.xml to set the notify plugin prefs
    /plugins/gtk/X11/notify/* and set /pidgin/plugins/loaded to load 
    the notify plugin; Ubuntu: #13389.
  - Add LPI integration patch, 02_lpi.
  - Add patch 04_let_crasher_for_apport to stop catching the SIGSEGV signal
    and let apport handle it.
  - Add patch 05_default_to_irc_ubuntu_com to set the default IRC 
    server to irc.ubuntu.com.
  - Add autoconf patch, 70_autoconf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file userlist.c MSN user list support
 
3
 *
 
4
 * purple
 
5
 *
 
6
 * Purple is the legal property of its developers, whose names are too numerous
 
7
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 
8
 * source distribution.
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
23
 */
 
24
#include "msn.h"
 
25
#include "userlist.h"
 
26
 
 
27
const char *lists[] = { "FL", "AL", "BL", "RL" };
 
28
 
 
29
typedef struct
 
30
{
 
31
        PurpleConnection *gc;
 
32
        char *who;
 
33
        char *friendly;
 
34
 
 
35
} MsnPermitAdd;
 
36
 
 
37
/**************************************************************************
 
38
 * Callbacks
 
39
 **************************************************************************/
 
40
static void
 
41
msn_accept_add_cb(gpointer data)
 
42
{
 
43
        MsnPermitAdd *pa = data;
 
44
        MsnSession *session;
 
45
        MsnUserList *userlist;
 
46
 
 
47
        if (PURPLE_CONNECTION_IS_VALID(pa->gc)) {
 
48
                session = pa->gc->proto_data;
 
49
                userlist = session->userlist;
 
50
 
 
51
                msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL);
 
52
        }
 
53
 
 
54
        g_free(pa->who);
 
55
        g_free(pa->friendly);
 
56
        g_free(pa);
 
57
}
 
58
 
 
59
static void
 
60
msn_cancel_add_cb(gpointer data)
 
61
{
 
62
        MsnPermitAdd *pa = data;
 
63
        MsnSession *session;
 
64
        MsnUserList *userlist;
 
65
 
 
66
        if (PURPLE_CONNECTION_IS_VALID(pa->gc)) {
 
67
                session = pa->gc->proto_data;
 
68
                userlist = session->userlist;
 
69
 
 
70
                msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_BL, NULL);
 
71
        }
 
72
 
 
73
        g_free(pa->who);
 
74
        g_free(pa->friendly);
 
75
        g_free(pa);
 
76
}
 
77
 
 
78
static void
 
79
got_new_entry(PurpleConnection *gc, const char *passport, const char *friendly)
 
80
{
 
81
        MsnPermitAdd *pa;
 
82
 
 
83
        pa = g_new0(MsnPermitAdd, 1);
 
84
        pa->who = g_strdup(passport);
 
85
        pa->friendly = g_strdup(friendly);
 
86
        pa->gc = gc;
 
87
        
 
88
        purple_account_request_authorization(purple_connection_get_account(gc), passport, NULL, friendly, NULL,
 
89
                                           purple_find_buddy(purple_connection_get_account(gc), passport) != NULL,
 
90
                                           msn_accept_add_cb, msn_cancel_add_cb, pa);
 
91
}
 
92
 
 
93
/**************************************************************************
 
94
 * Utility functions
 
95
 **************************************************************************/
 
96
 
 
97
static gboolean
 
98
user_is_in_group(MsnUser *user, int group_id)
 
99
{
 
100
        if (user == NULL)
 
101
                return FALSE;
 
102
 
 
103
        if (group_id < 0)
 
104
                return FALSE;
 
105
 
 
106
        if (g_list_find(user->group_ids, GINT_TO_POINTER(group_id)))
 
107
                return TRUE;
 
108
 
 
109
        return FALSE;
 
110
}
 
111
 
 
112
static gboolean
 
113
user_is_there(MsnUser *user, int list_id, int group_id)
 
114
{
 
115
        int list_op;
 
116
 
 
117
        if (user == NULL)
 
118
                return FALSE;
 
119
 
 
120
        list_op = 1 << list_id;
 
121
 
 
122
        if (!(user->list_op & list_op))
 
123
                return FALSE;
 
124
 
 
125
        if (list_id == MSN_LIST_FL)
 
126
        {
 
127
                if (group_id >= 0)
 
128
                        return user_is_in_group(user, group_id);
 
129
        }
 
130
 
 
131
        return TRUE;
 
132
}
 
133
 
 
134
static const char*
 
135
get_friendly_name(MsnUser *user)
 
136
{
 
137
        const char *friendly_name;
 
138
 
 
139
        g_return_val_if_fail(user != NULL, NULL);
 
140
 
 
141
        friendly_name = msn_user_get_friendly_name(user);
 
142
 
 
143
        if (friendly_name != NULL)
 
144
                friendly_name = purple_url_encode(friendly_name);
 
145
        else
 
146
                friendly_name = msn_user_get_passport(user);
 
147
 
 
148
        /* this might be a bit of a hack, but it should prevent notification server
 
149
         * disconnections for people who have buddies with insane friendly names
 
150
         * who added you to their buddy list from being disconnected. Stu. */
 
151
        /* Shx: What? Isn't the store_name obtained from the server, and hence it's
 
152
         * below the BUDDY_ALIAS_MAXLEN ? */
 
153
        /* Stu: yeah, that's why it's a bit of a hack, as you pointed out, we're
 
154
         * probably decoding the incoming store_name wrong, or something. bleh. */
 
155
 
 
156
        if (strlen(friendly_name) > BUDDY_ALIAS_MAXLEN)
 
157
                friendly_name = msn_user_get_passport(user);
 
158
 
 
159
        return friendly_name;
 
160
}
 
161
 
 
162
static void
 
163
msn_request_add_group(MsnUserList *userlist, const char *who,
 
164
                                          const char *old_group_name, const char *new_group_name)
 
165
{
 
166
        MsnCmdProc *cmdproc;
 
167
        MsnTransaction *trans;
 
168
        MsnMoveBuddy *data;
 
169
 
 
170
        cmdproc = userlist->session->notification->cmdproc;
 
171
        data = g_new0(MsnMoveBuddy, 1);
 
172
 
 
173
        data->who = g_strdup(who);
 
174
 
 
175
        if (old_group_name)
 
176
                data->old_group_name = g_strdup(old_group_name);
 
177
 
 
178
        trans = msn_transaction_new(cmdproc, "ADG", "%s %d",
 
179
                                                                purple_url_encode(new_group_name),
 
180
                                                                0);
 
181
 
 
182
        msn_transaction_set_data(trans, data);
 
183
 
 
184
        msn_cmdproc_send_trans(cmdproc, trans);
 
185
}
 
186
 
 
187
/**************************************************************************
 
188
 * Server functions
 
189
 **************************************************************************/
 
190
 
 
191
MsnListId
 
192
msn_get_list_id(const char *list)
 
193
{
 
194
        if (list[0] == 'F')
 
195
                return MSN_LIST_FL;
 
196
        else if (list[0] == 'A')
 
197
                return MSN_LIST_AL;
 
198
        else if (list[0] == 'B')
 
199
                return MSN_LIST_BL;
 
200
        else if (list[0] == 'R')
 
201
                return MSN_LIST_RL;
 
202
 
 
203
        return -1;
 
204
}
 
205
 
 
206
void
 
207
msn_got_add_user(MsnSession *session, MsnUser *user,
 
208
                                 MsnListId list_id, int group_id)
 
209
{
 
210
        PurpleAccount *account;
 
211
        const char *passport;
 
212
        const char *friendly;
 
213
 
 
214
        account = session->account;
 
215
 
 
216
        passport = msn_user_get_passport(user);
 
217
        friendly = msn_user_get_friendly_name(user);
 
218
 
 
219
        if (list_id == MSN_LIST_FL)
 
220
        {
 
221
                PurpleConnection *gc;
 
222
 
 
223
                gc = purple_account_get_connection(account);
 
224
 
 
225
                serv_got_alias(gc, passport, friendly);
 
226
 
 
227
                if (group_id >= 0)
 
228
                {
 
229
                        msn_user_add_group_id(user, group_id);
 
230
                }
 
231
                else
 
232
                {
 
233
                        /* session->sync->fl_users_count++; */
 
234
                }
 
235
        }
 
236
        else if (list_id == MSN_LIST_AL)
 
237
        {
 
238
                purple_privacy_permit_add(account, passport, TRUE);
 
239
        }
 
240
        else if (list_id == MSN_LIST_BL)
 
241
        {
 
242
                purple_privacy_deny_add(account, passport, TRUE);
 
243
        }
 
244
        else if (list_id == MSN_LIST_RL)
 
245
        {
 
246
                PurpleConnection *gc;
 
247
                PurpleConversation *convo;
 
248
 
 
249
                gc = purple_account_get_connection(account);
 
250
 
 
251
                purple_debug_info("msn",
 
252
                                                "%s has added you to his or her buddy list.\n",
 
253
                                                passport);
 
254
 
 
255
                convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, passport, account);
 
256
                if (convo) {
 
257
                        PurpleBuddy *buddy;
 
258
                        char *msg;
 
259
 
 
260
                        buddy = purple_find_buddy(account, passport);
 
261
                        msg = g_strdup_printf(
 
262
                                _("%s has added you to his or her buddy list."),
 
263
                                buddy ? purple_buddy_get_contact_alias(buddy) : passport);
 
264
                        purple_conv_im_write(PURPLE_CONV_IM(convo), passport, msg,
 
265
                                PURPLE_MESSAGE_SYSTEM, time(NULL));
 
266
                        g_free(msg);
 
267
                }
 
268
 
 
269
                if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP)))
 
270
                {
 
271
                        /*
 
272
                         * TODO: The friendly name was NULL for me when I
 
273
                         *       looked at this.  Maybe we should use the store
 
274
                         *       name instead? --KingAnt
 
275
                         */
 
276
                        got_new_entry(gc, passport, friendly);
 
277
                }
 
278
        }
 
279
 
 
280
        user->list_op |= (1 << list_id);
 
281
        /* purple_user_add_list_id (user, list_id); */
 
282
}
 
283
 
 
284
void
 
285
msn_got_rem_user(MsnSession *session, MsnUser *user,
 
286
                                 MsnListId list_id, int group_id)
 
287
{
 
288
        PurpleAccount *account;
 
289
        const char *passport;
 
290
 
 
291
        account = session->account;
 
292
 
 
293
        passport = msn_user_get_passport(user);
 
294
 
 
295
        if (list_id == MSN_LIST_FL)
 
296
        {
 
297
                /* TODO: When is the user totally removed? */
 
298
                if (group_id >= 0)
 
299
                {
 
300
                        msn_user_remove_group_id(user, group_id);
 
301
                        return;
 
302
                }
 
303
                else
 
304
                {
 
305
                        /* session->sync->fl_users_count--; */
 
306
                }
 
307
        }
 
308
        else if (list_id == MSN_LIST_AL)
 
309
        {
 
310
                purple_privacy_permit_remove(account, passport, TRUE);
 
311
        }
 
312
        else if (list_id == MSN_LIST_BL)
 
313
        {
 
314
                purple_privacy_deny_remove(account, passport, TRUE);
 
315
        }
 
316
        else if (list_id == MSN_LIST_RL)
 
317
        {
 
318
                PurpleConversation *convo;
 
319
 
 
320
                purple_debug_info("msn",
 
321
                                                "%s has removed you from his or her buddy list.\n",
 
322
                                                passport);
 
323
 
 
324
                convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, passport, account);
 
325
                if (convo) {
 
326
                        PurpleBuddy *buddy;
 
327
                        char *msg;
 
328
 
 
329
                        buddy = purple_find_buddy(account, passport);
 
330
                        msg = g_strdup_printf(
 
331
                                _("%s has removed you from his or her buddy list."),
 
332
                                buddy ? purple_buddy_get_contact_alias(buddy) : passport);
 
333
                        purple_conv_im_write(PURPLE_CONV_IM(convo), passport, msg,
 
334
                                PURPLE_MESSAGE_SYSTEM, time(NULL));
 
335
                        g_free(msg);
 
336
                }
 
337
        }
 
338
 
 
339
        user->list_op &= ~(1 << list_id);
 
340
        /* purple_user_remove_list_id (user, list_id); */
 
341
 
 
342
        if (user->list_op == 0)
 
343
        {
 
344
                purple_debug_info("msn", "Buddy '%s' shall be deleted?.\n",
 
345
                                                passport);
 
346
 
 
347
        }
 
348
}
 
349
 
 
350
void
 
351
msn_got_lst_user(MsnSession *session, MsnUser *user,
 
352
                                 int list_op, GSList *group_ids)
 
353
{
 
354
        PurpleConnection *gc;
 
355
        PurpleAccount *account;
 
356
        const char *passport;
 
357
        const char *store;
 
358
 
 
359
        account = session->account;
 
360
        gc = purple_account_get_connection(account);
 
361
 
 
362
        passport = msn_user_get_passport(user);
 
363
        store = msn_user_get_friendly_name(user);
 
364
 
 
365
        if (list_op & MSN_LIST_FL_OP)
 
366
        {
 
367
                GSList *c;
 
368
                for (c = group_ids; c != NULL; c = g_slist_next(c))
 
369
                {
 
370
                        int group_id;
 
371
                        group_id = GPOINTER_TO_INT(c->data);
 
372
                        msn_user_add_group_id(user, group_id);
 
373
                }
 
374
 
 
375
                /* FIXME: It might be a real alias */
 
376
                /* Umm, what? This might fix bug #1385130 */
 
377
                serv_got_alias(gc, passport, store);
 
378
        }
 
379
 
 
380
        if (list_op & MSN_LIST_AL_OP)
 
381
        {
 
382
                /* These are users who are allowed to see our status. */
 
383
                purple_privacy_deny_remove(account, passport, TRUE);
 
384
                purple_privacy_permit_add(account, passport, TRUE);
 
385
        }
 
386
 
 
387
        if (list_op & MSN_LIST_BL_OP)
 
388
        {
 
389
                /* These are users who are not allowed to see our status. */
 
390
                purple_privacy_permit_remove(account, passport, TRUE);
 
391
                purple_privacy_deny_add(account, passport, TRUE);
 
392
        }
 
393
 
 
394
        if (list_op & MSN_LIST_RL_OP)
 
395
        {
 
396
                /* These are users who have us on their buddy list. */
 
397
                /*
 
398
                 * TODO: What is store name set to when this happens?
 
399
                 *       For one of my accounts "something@hotmail.com"
 
400
                 *       the store name was "something."  Maybe we
 
401
                 *       should use the friendly name, instead? --KingAnt
 
402
                 */
 
403
 
 
404
                if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP)))
 
405
                {
 
406
                        got_new_entry(gc, passport, store);
 
407
                }
 
408
        }
 
409
 
 
410
        user->list_op = list_op;
 
411
}
 
412
 
 
413
/**************************************************************************
 
414
 * UserList functions
 
415
 **************************************************************************/
 
416
 
 
417
MsnUserList*
 
418
msn_userlist_new(MsnSession *session)
 
419
{
 
420
        MsnUserList *userlist;
 
421
 
 
422
        userlist = g_new0(MsnUserList, 1);
 
423
 
 
424
        userlist->session = session;
 
425
        userlist->buddy_icon_requests = g_queue_new();
 
426
        
 
427
        /* buddy_icon_window is the number of allowed simultaneous buddy icon requests.
 
428
         * XXX With smarter rate limiting code, we could allow more at once... 5 was the limit set when
 
429
         * we weren't retrieiving any more than 5 per MSN session. */
 
430
        userlist->buddy_icon_window = 1;
 
431
 
 
432
        return userlist;
 
433
}
 
434
 
 
435
void
 
436
msn_userlist_destroy(MsnUserList *userlist)
 
437
{
 
438
        GList *l;
 
439
 
 
440
        for (l = userlist->users; l != NULL; l = l->next)
 
441
        {
 
442
                msn_user_destroy(l->data);
 
443
        }
 
444
 
 
445
        g_list_free(userlist->users);
 
446
 
 
447
        for (l = userlist->groups; l != NULL; l = l->next)
 
448
        {
 
449
                msn_group_destroy(l->data);
 
450
        }
 
451
 
 
452
        g_list_free(userlist->groups);
 
453
 
 
454
        g_queue_free(userlist->buddy_icon_requests);
 
455
 
 
456
        if (userlist->buddy_icon_request_timer)
 
457
                purple_timeout_remove(userlist->buddy_icon_request_timer);
 
458
 
 
459
        g_free(userlist);
 
460
}
 
461
 
 
462
void
 
463
msn_userlist_add_user(MsnUserList *userlist, MsnUser *user)
 
464
{
 
465
        userlist->users = g_list_prepend(userlist->users, user);
 
466
}
 
467
 
 
468
void
 
469
msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user)
 
470
{
 
471
        userlist->users = g_list_remove(userlist->users, user);
 
472
}
 
473
 
 
474
MsnUser *
 
475
msn_userlist_find_user(MsnUserList *userlist, const char *passport)
 
476
{
 
477
        GList *l;
 
478
 
 
479
        g_return_val_if_fail(passport != NULL, NULL);
 
480
 
 
481
        for (l = userlist->users; l != NULL; l = l->next)
 
482
        {
 
483
                MsnUser *user = (MsnUser *)l->data;
 
484
 
 
485
                g_return_val_if_fail(user->passport != NULL, NULL);
 
486
 
 
487
                if (!strcmp(passport, user->passport))
 
488
                        return user;
 
489
        }
 
490
 
 
491
        return NULL;
 
492
}
 
493
 
 
494
void
 
495
msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group)
 
496
{
 
497
        userlist->groups = g_list_append(userlist->groups, group);
 
498
}
 
499
 
 
500
void
 
501
msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group)
 
502
{
 
503
        userlist->groups = g_list_remove(userlist->groups, group);
 
504
}
 
505
 
 
506
MsnGroup *
 
507
msn_userlist_find_group_with_id(MsnUserList *userlist, int id)
 
508
{
 
509
        GList *l;
 
510
 
 
511
        g_return_val_if_fail(userlist != NULL, NULL);
 
512
        g_return_val_if_fail(id       >= 0,    NULL);
 
513
 
 
514
        for (l = userlist->groups; l != NULL; l = l->next)
 
515
        {
 
516
                MsnGroup *group = l->data;
 
517
 
 
518
                if (group->id == id)
 
519
                        return group;
 
520
        }
 
521
 
 
522
        return NULL;
 
523
}
 
524
 
 
525
MsnGroup *
 
526
msn_userlist_find_group_with_name(MsnUserList *userlist, const char *name)
 
527
{
 
528
        GList *l;
 
529
 
 
530
        g_return_val_if_fail(userlist != NULL, NULL);
 
531
        g_return_val_if_fail(name     != NULL, NULL);
 
532
 
 
533
        for (l = userlist->groups; l != NULL; l = l->next)
 
534
        {
 
535
                MsnGroup *group = l->data;
 
536
 
 
537
                if ((group->name != NULL) && !g_ascii_strcasecmp(name, group->name))
 
538
                        return group;
 
539
        }
 
540
 
 
541
        return NULL;
 
542
}
 
543
 
 
544
int
 
545
msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name)
 
546
{
 
547
        MsnGroup *group;
 
548
 
 
549
        group = msn_userlist_find_group_with_name(userlist, group_name);
 
550
 
 
551
        if (group != NULL)
 
552
                return msn_group_get_id(group);
 
553
        else
 
554
                return -1;
 
555
}
 
556
 
 
557
const char *
 
558
msn_userlist_find_group_name(MsnUserList *userlist, int group_id)
 
559
{
 
560
        MsnGroup *group;
 
561
 
 
562
        group = msn_userlist_find_group_with_id(userlist, group_id);
 
563
 
 
564
        if (group != NULL)
 
565
                return msn_group_get_name(group);
 
566
        else
 
567
                return NULL;
 
568
}
 
569
 
 
570
void
 
571
msn_userlist_rename_group_id(MsnUserList *userlist, int group_id,
 
572
                                                         const char *new_name)
 
573
{
 
574
        MsnGroup *group;
 
575
 
 
576
        group = msn_userlist_find_group_with_id(userlist, group_id);
 
577
 
 
578
        if (group != NULL)
 
579
                msn_group_set_name(group, new_name);
 
580
}
 
581
 
 
582
void
 
583
msn_userlist_remove_group_id(MsnUserList *userlist, int group_id)
 
584
{
 
585
        MsnGroup *group;
 
586
 
 
587
        group = msn_userlist_find_group_with_id(userlist, group_id);
 
588
 
 
589
        if (group != NULL)
 
590
        {
 
591
                msn_userlist_remove_group(userlist, group);
 
592
                msn_group_destroy(group);
 
593
        }
 
594
}
 
595
 
 
596
void
 
597
msn_userlist_rem_buddy(MsnUserList *userlist,
 
598
                                           const char *who, int list_id, const char *group_name)
 
599
{
 
600
        MsnUser *user;
 
601
        int group_id;
 
602
        const char *list;
 
603
 
 
604
        user = msn_userlist_find_user(userlist, who);
 
605
        group_id = -1;
 
606
 
 
607
        if (group_name != NULL)
 
608
        {
 
609
                group_id = msn_userlist_find_group_id(userlist, group_name);
 
610
 
 
611
                if (group_id < 0)
 
612
                {
 
613
                        /* Whoa, there is no such group. */
 
614
                        purple_debug_error("msn", "Group doesn't exist: %s\n", group_name);
 
615
                        return;
 
616
                }
 
617
        }
 
618
 
 
619
        /* First we're going to check if not there. */
 
620
        if (!(user_is_there(user, list_id, group_id)))
 
621
        {
 
622
                list = lists[list_id];
 
623
                purple_debug_error("msn", "User '%s' is not there: %s\n",
 
624
                                                 who, list);
 
625
                return;
 
626
        }
 
627
 
 
628
        /* Then request the rem to the server. */
 
629
        list = lists[list_id];
 
630
 
 
631
        msn_notification_rem_buddy(userlist->session->notification, list, who, group_id);
 
632
}
 
633
 
 
634
void
 
635
msn_userlist_add_buddy(MsnUserList *userlist,
 
636
                                           const char *who, int list_id,
 
637
                                           const char *group_name)
 
638
{
 
639
        MsnUser *user;
 
640
        int group_id;
 
641
        const char *list;
 
642
        const char *friendly_name;
 
643
 
 
644
        group_id = -1;
 
645
 
 
646
        if (!purple_email_is_valid(who))
 
647
        {
 
648
                /* only notify the user about problems adding to the friends list
 
649
                 * maybe we should do something else for other lists, but it probably
 
650
                 * won't cause too many problems if we just ignore it */
 
651
                if (list_id == MSN_LIST_FL)
 
652
                {
 
653
                        char *str = g_strdup_printf(_("Unable to add \"%s\"."), who);
 
654
                        purple_notify_error(NULL, NULL, str,
 
655
                                                          _("The screen name specified is invalid."));
 
656
                        g_free(str);
 
657
                }
 
658
 
 
659
                return;
 
660
        }
 
661
 
 
662
        if (group_name != NULL)
 
663
        {
 
664
                group_id = msn_userlist_find_group_id(userlist, group_name);
 
665
 
 
666
                if (group_id < 0)
 
667
                {
 
668
                        /* Whoa, we must add that group first. */
 
669
                        msn_request_add_group(userlist, who, NULL, group_name);
 
670
                        return;
 
671
                }
 
672
        }
 
673
 
 
674
        user = msn_userlist_find_user(userlist, who);
 
675
 
 
676
        /* First we're going to check if it's already there. */
 
677
        if (user_is_there(user, list_id, group_id))
 
678
        {
 
679
                list = lists[list_id];
 
680
                purple_debug_error("msn", "User '%s' is already there: %s\n", who, list);
 
681
                return;
 
682
        }
 
683
 
 
684
        friendly_name = (user != NULL) ? get_friendly_name(user) : who;
 
685
 
 
686
        /* Then request the add to the server. */
 
687
        list = lists[list_id];
 
688
 
 
689
        msn_notification_add_buddy(userlist->session->notification, list, who,
 
690
                                                           friendly_name, group_id);
 
691
}
 
692
 
 
693
void
 
694
msn_userlist_move_buddy(MsnUserList *userlist, const char *who,
 
695
                                                const char *old_group_name, const char *new_group_name)
 
696
{
 
697
        int new_group_id;
 
698
 
 
699
        new_group_id = msn_userlist_find_group_id(userlist, new_group_name);
 
700
 
 
701
        if (new_group_id < 0)
 
702
        {
 
703
                msn_request_add_group(userlist, who, old_group_name, new_group_name);
 
704
                return;
 
705
        }
 
706
 
 
707
        msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name);
 
708
        msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name);
 
709
}