Mercurial > pidgin
annotate src/protocols/msn/userlist.c @ 9208:ef7360cb07a0
[gaim-migrate @ 10003]
I don't know what a store name is. Hopefully this fixes the segfaults.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Sun, 06 Jun 2004 04:54:57 +0000 |
| parents | ab6636c5a136 |
| children | 62b601ddb4bc |
| rev | line source |
|---|---|
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
1 /** |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
2 * @file userlist.c MSN user list support |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
3 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
4 * gaim |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
5 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
8 * source distribution. |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
9 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
13 * (at your option) any later version. |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
14 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
18 * GNU General Public License for more details. |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
19 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
23 */ |
| 9193 | 24 #include "msn.h" |
| 25 #include "userlist.h" | |
| 26 | |
| 27 const char *lists[] = { "FL", "AL", "BL", "RL" }; | |
| 28 | |
| 29 typedef struct | |
| 30 { | |
| 31 GaimConnection *gc; | |
| 32 char *who; | |
| 33 | |
| 34 } MsnPermitAdd; | |
| 35 | |
| 36 /************************************************************************** | |
| 37 * Callbacks | |
| 38 **************************************************************************/ | |
| 39 static void | |
| 40 msn_accept_add_cb(MsnPermitAdd *pa) | |
| 41 { | |
| 42 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
| 43 { | |
| 44 MsnSession *session = pa->gc->proto_data; | |
| 45 MsnUserList *userlist = session->userlist; | |
| 46 | |
| 47 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL); | |
| 48 | |
| 49 /* TODO: This ask for the alias, right? */ | |
| 50 gaim_account_notify_added(pa->gc->account, NULL, pa->who, NULL, NULL); | |
| 51 } | |
| 52 | |
| 53 g_free(pa->who); | |
| 54 g_free(pa); | |
| 55 } | |
| 56 | |
| 57 static void | |
| 58 msn_cancel_add_cb(MsnPermitAdd *pa) | |
| 59 { | |
| 60 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
| 61 { | |
| 62 MsnSession *session = pa->gc->proto_data; | |
| 63 MsnUserList *userlist = session->userlist; | |
| 64 | |
| 65 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_BL, NULL); | |
| 66 } | |
| 67 | |
| 68 g_free(pa->who); | |
| 69 g_free(pa); | |
| 70 } | |
| 71 | |
| 72 static void | |
| 73 got_new_entry(GaimConnection *gc, const char *passport, | |
| 74 const char *friendly) | |
| 75 { | |
| 76 MsnPermitAdd *pa; | |
| 77 char *msg; | |
| 78 | |
| 79 pa = g_new0(MsnPermitAdd, 1); | |
| 80 pa->who = g_strdup(passport); | |
| 81 pa->gc = gc; | |
| 82 | |
| 83 msg = g_strdup_printf( | |
| 84 _("The user %s (%s) wants to add %s to his or her buddy list."), | |
| 85 passport, friendly, gaim_account_get_username(gc->account)); | |
| 86 | |
| 87 gaim_request_action(gc, NULL, msg, NULL, 0, pa, 2, | |
| 88 _("Authorize"), G_CALLBACK(msn_accept_add_cb), | |
| 89 _("Deny"), G_CALLBACK(msn_cancel_add_cb)); | |
| 90 | |
| 91 g_free(msg); | |
| 92 } | |
| 93 | |
| 94 /************************************************************************** | |
| 95 * Utility functions | |
| 96 **************************************************************************/ | |
| 97 | |
| 98 static gboolean | |
| 99 user_is_in_group(MsnUser *user, int group_id) | |
| 100 { | |
| 101 if (user == NULL) | |
| 102 return FALSE; | |
| 103 | |
| 104 if (group_id < 0) | |
| 105 return FALSE; | |
| 106 | |
| 107 if (g_list_find(user->group_ids, GINT_TO_POINTER(group_id))) | |
| 108 return TRUE; | |
| 109 | |
| 110 return FALSE; | |
| 111 } | |
| 112 | |
| 113 static gboolean | |
| 114 user_is_there(MsnUser *user, int list_id, int group_id) | |
| 115 { | |
| 116 int list_op; | |
| 117 | |
| 118 if (user == NULL) | |
| 119 return FALSE; | |
| 120 | |
| 121 list_op = 1 << list_id; | |
| 122 | |
| 123 if (!(user->list_op & list_op)) | |
| 124 return FALSE; | |
| 125 | |
| 126 if (list_id == MSN_LIST_FL) | |
| 127 { | |
| 128 if (group_id >= 0) | |
| 129 return user_is_in_group(user, group_id); | |
| 130 } | |
| 131 | |
| 132 return TRUE; | |
| 133 } | |
| 134 | |
| 135 static const char* | |
| 136 get_store_name(MsnUser *user) | |
| 137 { | |
| 138 const char *store_name; | |
| 139 | |
| 140 g_return_val_if_fail(user != NULL, NULL); | |
| 141 | |
| 142 if ((store_name = msn_user_get_store_name(user)) != NULL) | |
| 143 return gaim_url_encode(store_name); | |
| 144 | |
| 145 return msn_user_get_passport(user); | |
| 146 } | |
| 147 | |
| 148 static void | |
| 149 msn_request_add_group(MsnUserList *userlist, const char *who, | |
| 150 const char *old_group_name, const char *new_group_name) | |
| 151 { | |
| 152 MsnCmdProc *cmdproc; | |
| 153 MsnTransaction *trans; | |
| 154 | |
| 155 cmdproc = userlist->session->notification->cmdproc; | |
| 156 MsnMoveBuddy *data = g_new0(MsnMoveBuddy, 1); | |
| 157 | |
| 158 data->who = g_strdup(who); | |
| 159 | |
| 160 if (old_group_name) | |
| 161 data->old_group_name = g_strdup(old_group_name); | |
| 162 | |
| 163 trans = msn_transaction_new("ADG", "%s %d", | |
| 164 gaim_url_encode(new_group_name), | |
| 165 0); | |
| 166 | |
| 167 msn_transaction_set_data(trans, data); | |
| 168 | |
| 169 msn_cmdproc_send_trans(cmdproc, trans); | |
| 170 } | |
| 171 | |
| 172 /************************************************************************** | |
| 173 * Server functions | |
| 174 **************************************************************************/ | |
| 175 | |
| 176 MsnListId | |
| 177 msn_get_list_id(const char *list) | |
| 178 { | |
| 179 if (list[0] == 'F') | |
| 180 return MSN_LIST_FL; | |
| 181 else if (list[0] == 'A') | |
| 182 return MSN_LIST_AL; | |
| 183 else if (list[0] == 'B') | |
| 184 return MSN_LIST_BL; | |
| 185 else if (list[0] == 'R') | |
| 186 return MSN_LIST_RL; | |
| 187 | |
| 188 return -1; | |
| 189 } | |
| 190 | |
| 191 void | |
| 192 msn_got_add_user(MsnSession *session, MsnUser *user, | |
| 193 MsnListId list_id, int group_id) | |
| 194 { | |
| 195 GaimAccount *account; | |
| 196 const char *passport; | |
| 197 const char *friendly; | |
| 198 | |
| 199 account = session->account; | |
| 200 | |
| 201 passport = msn_user_get_passport(user); | |
| 202 friendly = msn_user_get_friendly_name(user); | |
|
9197
ec417d2f9666
[gaim-migrate @ 9992]
Christian Hammond <chipx86@chipx86.com>
parents:
9196
diff
changeset
|
203 |
| 9193 | 204 if (list_id == MSN_LIST_FL) |
| 205 { | |
| 206 GaimConnection *gc = gaim_account_get_connection(account); | |
| 207 | |
| 208 serv_got_alias(gc, passport, friendly); | |
| 209 | |
| 210 if (group_id >= 0) | |
| 211 { | |
| 212 msn_user_add_group_id(user, group_id); | |
| 213 return; | |
| 214 } | |
| 215 else | |
| 216 { | |
| 217 /* session->sync->fl_users_count++; */ | |
| 218 } | |
| 219 } | |
| 220 else if (list_id == MSN_LIST_AL) | |
| 221 { | |
| 222 gaim_privacy_permit_add(account, passport, TRUE); | |
| 223 } | |
| 224 else if (list_id == MSN_LIST_BL) | |
| 225 { | |
| 226 gaim_privacy_deny_add(account, passport, TRUE); | |
| 227 } | |
| 228 else if (list_id == MSN_LIST_RL) | |
| 229 { | |
| 230 GaimConnection *gc = gaim_account_get_connection(account); | |
| 231 | |
| 232 gaim_debug_info("msn", | |
| 233 "%s has added you to his or her contact list.\n", | |
| 234 passport); | |
| 235 | |
| 236 if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) | |
| 237 got_new_entry(gc, passport, friendly); | |
| 238 } | |
| 239 | |
| 240 user->list_op |= (1 << list_id); | |
| 241 /* gaim_user_add_list_id (user, list_id); */ | |
| 242 } | |
| 243 | |
| 244 void | |
| 245 msn_got_rem_user(MsnSession *session, MsnUser *user, | |
| 246 MsnListId list_id, int group_id) | |
| 247 { | |
| 248 GaimAccount *account; | |
| 249 const char *passport; | |
| 250 | |
| 251 account = session->account; | |
| 252 | |
| 253 passport = msn_user_get_passport(user); | |
| 254 | |
| 255 if (list_id == MSN_LIST_FL) | |
| 256 { | |
| 257 /* TODO: When is the user totally removed? */ | |
| 258 if (group_id >= 0) | |
| 259 { | |
| 260 msn_user_remove_group_id(user, group_id); | |
| 261 return; | |
| 262 } | |
| 263 else | |
| 264 { | |
| 265 /* session->sync->fl_users_count--; */ | |
| 266 } | |
| 267 } | |
| 268 else if (list_id == MSN_LIST_AL) | |
| 269 { | |
| 270 gaim_privacy_permit_remove(account, passport, TRUE); | |
| 271 } | |
| 272 else if (list_id == MSN_LIST_BL) | |
| 273 { | |
| 274 gaim_privacy_deny_remove(account, passport, TRUE); | |
| 275 } | |
| 276 else if (list_id == MSN_LIST_RL) | |
| 277 { | |
| 278 gaim_debug_info("msn", | |
| 279 "%s has removed you from his or her contact list.\n", | |
| 280 passport); | |
| 281 } | |
| 282 | |
| 283 user->list_op &= ~(1 << list_id); | |
| 284 /* gaim_user_remove_list_id (user, list_id); */ | |
| 285 | |
| 286 if (user->list_op == 0) | |
| 287 { | |
| 288 gaim_debug_info("msn", "Buddy '%s' shall be deleted?.\n", | |
| 289 passport); | |
| 290 | |
| 291 } | |
| 292 } | |
| 293 | |
| 294 void | |
| 295 msn_got_lst_user(MsnSession *session, MsnUser *user, | |
| 296 int list_op, GSList *group_ids) | |
| 297 { | |
| 298 GaimConnection *gc; | |
| 299 GaimAccount *account; | |
| 300 const char *passport; | |
| 301 const char *store; | |
| 302 | |
| 303 account = session->account; | |
| 304 gc = gaim_account_get_connection(account); | |
| 305 | |
| 306 passport = msn_user_get_passport(user); | |
|
9208
ef7360cb07a0
[gaim-migrate @ 10003]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
307 store = msn_user_get_friendly_name(user); |
| 9193 | 308 |
| 309 if (list_op & MSN_LIST_FL_OP) | |
| 310 { | |
| 311 GSList *c; | |
| 312 for (c = group_ids; c != NULL; c = g_slist_next(c)) | |
| 313 { | |
| 314 int group_id; | |
| 315 group_id = GPOINTER_TO_INT(c->data); | |
| 316 msn_user_add_group_id(user, group_id); | |
| 317 } | |
| 318 | |
| 319 /* FIXME: It might be a real alias */ | |
| 320 /* serv_got_alias(gc, passport, store); */ | |
| 321 } | |
| 322 | |
| 323 if (list_op & MSN_LIST_AL_OP) | |
| 324 { | |
| 325 /* These are users who are allowed to see our status. */ | |
| 326 | |
| 327 if (g_slist_find_custom(account->deny, passport, | |
| 328 (GCompareFunc)strcmp)) | |
| 329 { | |
| 330 gaim_privacy_deny_remove(gc->account, passport, TRUE); | |
| 331 } | |
| 332 | |
| 333 gaim_privacy_permit_add(account, passport, TRUE); | |
| 334 } | |
| 335 | |
| 336 if (list_op & MSN_LIST_BL_OP) | |
| 337 { | |
| 338 /* These are users who are not allowed to see our status. */ | |
| 339 | |
| 340 if (g_slist_find_custom(account->permit, passport, | |
| 341 (GCompareFunc)strcmp)) | |
| 342 { | |
| 343 gaim_privacy_permit_remove(gc->account, passport, TRUE); | |
| 344 } | |
| 345 | |
| 346 gaim_privacy_deny_add(account, passport, TRUE); | |
| 347 } | |
| 348 | |
| 349 if (list_op & MSN_LIST_RL_OP) | |
| 350 { | |
| 351 /* These are users who have us on their contact list. */ | |
| 352 /* TODO: what does store name is when this happens? */ | |
| 353 | |
| 354 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) | |
| 355 got_new_entry(gc, passport, store); | |
| 356 } | |
| 357 | |
| 358 user->list_op = list_op; | |
| 359 } | |
| 360 | |
| 361 /************************************************************************** | |
| 362 * UserList functions | |
| 363 **************************************************************************/ | |
| 364 | |
| 365 MsnUserList* | |
| 366 msn_userlist_new(MsnSession *session) | |
| 367 { | |
| 368 MsnUserList *userlist; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
369 |
| 9193 | 370 userlist = g_new0(MsnUserList, 1); |
| 371 | |
| 372 userlist->session = session; | |
| 373 | |
| 374 return userlist; | |
| 375 } | |
| 376 | |
| 377 void | |
| 378 msn_userlist_destroy(MsnUserList *userlist) | |
| 379 { | |
| 380 GList *l; | |
| 381 | |
| 382 for (l = userlist->users; l != NULL; l = l->next) | |
| 383 { | |
| 384 msn_user_destroy(l->data); | |
| 385 } | |
| 386 | |
| 387 g_list_free(userlist->users); | |
| 388 | |
| 389 for (l = userlist->groups; l != NULL; l = l->next) | |
| 390 { | |
| 391 msn_group_destroy(l->data); | |
| 392 } | |
| 393 | |
| 394 g_list_free(userlist->groups); | |
| 395 } | |
| 396 | |
| 397 void | |
| 398 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) | |
| 399 { | |
| 400 userlist->users = g_list_append(userlist->users, user); | |
| 401 } | |
| 402 | |
| 403 void | |
| 404 msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user) | |
| 405 { | |
| 406 userlist->users = g_list_remove(userlist->users, user); | |
| 407 } | |
| 408 | |
| 409 MsnUser * | |
| 410 msn_userlist_find_user(MsnUserList *userlist, const char *passport) | |
| 411 { | |
| 412 GList *l; | |
| 413 | |
| 414 g_return_val_if_fail(passport != NULL, NULL); | |
| 415 | |
| 416 for (l = userlist->users; l != NULL; l = l->next) | |
| 417 { | |
| 418 MsnUser *user = (MsnUser *)l->data; | |
| 419 | |
| 420 g_return_val_if_fail(user->passport != NULL, NULL); | |
| 421 | |
| 422 if (!strcmp(passport, user->passport)) | |
| 423 return user; | |
| 424 } | |
| 425 | |
| 426 return NULL; | |
| 427 } | |
| 428 | |
| 429 void | |
| 430 msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group) | |
| 431 { | |
| 432 userlist->groups = g_list_append(userlist->groups, group); | |
| 433 } | |
| 434 | |
| 435 void | |
| 436 msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group) | |
| 437 { | |
| 438 userlist->groups = g_list_remove(userlist->groups, group); | |
| 439 } | |
| 440 | |
| 441 MsnGroup * | |
| 442 msn_userlist_find_group_with_id(MsnUserList *userlist, int id) | |
| 443 { | |
| 444 GList *l; | |
| 445 | |
| 446 g_return_val_if_fail(userlist != NULL, NULL); | |
| 447 g_return_val_if_fail(id >= 0, NULL); | |
| 448 | |
| 449 for (l = userlist->groups; l != NULL; l = l->next) | |
| 450 { | |
| 451 MsnGroup *group = l->data; | |
| 452 | |
| 453 if (group->id == id) | |
| 454 return group; | |
| 455 } | |
| 456 | |
| 457 return NULL; | |
| 458 } | |
| 459 | |
| 460 MsnGroup * | |
| 461 msn_userlist_find_group_with_name(MsnUserList *userlist, const char *name) | |
| 462 { | |
| 463 GList *l; | |
| 464 | |
| 465 g_return_val_if_fail(userlist != NULL, NULL); | |
| 466 g_return_val_if_fail(name != NULL, NULL); | |
| 467 | |
| 468 for (l = userlist->groups; l != NULL; l = l->next) | |
| 469 { | |
| 470 MsnGroup *group = l->data; | |
| 471 | |
| 472 if ((group->name != NULL) && !g_ascii_strcasecmp(name, group->name)) | |
| 473 return group; | |
| 474 } | |
| 475 | |
| 476 return NULL; | |
| 477 } | |
| 478 | |
| 479 int | |
| 480 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) | |
| 481 { | |
| 482 MsnGroup *group; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
483 |
| 9193 | 484 group = msn_userlist_find_group_with_name(userlist, group_name); |
| 485 | |
| 486 if (group != NULL) | |
| 487 return msn_group_get_id(group); | |
| 488 else | |
| 489 return -1; | |
| 490 } | |
| 491 | |
| 492 const char * | |
| 493 msn_userlist_find_group_name(MsnUserList *userlist, int group_id) | |
| 494 { | |
| 495 MsnGroup *group; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
496 |
| 9193 | 497 group = msn_userlist_find_group_with_id(userlist, group_id); |
| 498 | |
| 499 if (group != NULL) | |
| 500 return msn_group_get_name(group); | |
| 501 else | |
| 502 return NULL; | |
| 503 } | |
| 504 | |
| 505 void | |
| 506 msn_userlist_rename_group_id(MsnUserList *userlist, int group_id, | |
| 507 const char *new_name) | |
| 508 { | |
| 509 MsnGroup *group; | |
| 510 | |
| 511 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 512 | |
| 513 if (group != NULL) | |
| 514 msn_group_set_name(group, new_name); | |
| 515 } | |
| 516 | |
| 517 void | |
| 518 msn_userlist_remove_group_id(MsnUserList *userlist, int group_id) | |
| 519 { | |
| 520 MsnGroup *group; | |
| 521 | |
| 522 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 523 | |
| 524 if (group != NULL) | |
| 525 msn_userlist_remove_group(userlist, group); | |
| 526 } | |
| 527 | |
| 528 void | |
| 529 msn_userlist_rem_buddy(MsnUserList *userlist, | |
| 530 const char *who, int list_id, const char *group_name) | |
| 531 { | |
| 532 MsnUser *user; | |
| 533 int group_id; | |
| 534 const char *list; | |
| 535 | |
| 536 user = msn_userlist_find_user(userlist, who); | |
| 537 group_id = -1; | |
| 538 | |
| 539 if (group_name != NULL) | |
| 540 { | |
| 541 group_id = msn_userlist_find_group_id(userlist, group_name); | |
| 542 | |
| 543 if (group_id < 0) | |
| 544 { | |
| 545 /* Whoa, there is no such group. */ | |
| 546 gaim_debug_error("msn", "Group doesn't exist: %s\n", group_name); | |
| 547 return; | |
| 548 } | |
| 549 } | |
| 550 | |
| 551 /* First we're going to check if not there. */ | |
| 552 if (!(user_is_there(user, list_id, group_id))) | |
| 553 { | |
| 554 list = lists[list_id]; | |
| 555 gaim_debug_error("msn", "User '%s' is not there: %s\n", | |
| 556 who, list); | |
| 557 return; | |
| 558 } | |
| 559 | |
| 560 /* Then request the rem to the server. */ | |
| 561 list = lists[list_id]; | |
| 562 | |
| 563 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); | |
| 564 } | |
| 565 | |
| 566 void | |
| 567 msn_userlist_add_buddy(MsnUserList *userlist, | |
| 568 const char *who, int list_id, | |
| 569 const char *group_name) | |
| 570 { | |
| 571 MsnUser *user; | |
| 572 int group_id; | |
| 573 const char *list; | |
| 574 const char *store_name; | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
575 |
| 9193 | 576 group_id = -1; |
| 577 | |
| 578 if (group_name != NULL) | |
| 579 { | |
| 580 group_id = msn_userlist_find_group_id(userlist, group_name); | |
| 581 | |
| 582 if (group_id < 0) | |
| 583 { | |
| 584 /* Whoa, we must add that group first. */ | |
| 585 msn_request_add_group(userlist, who, NULL, group_name); | |
| 586 return; | |
| 587 } | |
| 588 } | |
| 589 | |
| 590 user = msn_userlist_find_user(userlist, who); | |
| 591 | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
592 /* First we're going to check if it's already there. */ |
| 9193 | 593 if (user_is_there(user, list_id, group_id)) |
| 594 { | |
| 595 list = lists[list_id]; | |
|
9195
d5487fdec696
[gaim-migrate @ 9990]
Christian Hammond <chipx86@chipx86.com>
parents:
9194
diff
changeset
|
596 #if 0 |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
597 gaim_debug_error("msn", "User '%s' is already there: %s\n", who, list); |
|
9196
336e87c71d06
[gaim-migrate @ 9991]
Christian Hammond <chipx86@chipx86.com>
parents:
9195
diff
changeset
|
598 #endif |
| 9193 | 599 return; |
| 600 } | |
| 601 | |
| 602 store_name = (user != NULL) ? get_store_name(user) : who; | |
| 603 | |
| 604 /* Then request the add to the server. */ | |
| 605 list = lists[list_id]; | |
| 606 | |
| 607 msn_notification_add_buddy(userlist->session->notification, list, who, | |
| 608 store_name, group_id); | |
| 609 } | |
| 610 | |
| 611 void | |
| 612 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, | |
| 613 const char *old_group_name, const char *new_group_name) | |
| 614 { | |
| 615 int new_group_id; | |
| 616 | |
| 617 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); | |
| 618 | |
| 619 if (new_group_id < 0) | |
| 620 { | |
| 621 msn_request_add_group(userlist, who, old_group_name, new_group_name); | |
| 622 return; | |
| 623 } | |
| 624 | |
| 625 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name); | |
| 626 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); | |
| 627 } |
