Mercurial > pidgin
annotate src/protocols/msn/userlist.c @ 9218:08e7ccb4610d
[gaim-migrate @ 10014]
(13:27:46) nosnilmot: someone apply this before we have another gcc 2.x
broken release :
http://www.nosnilmot.com/patches/gaim-0.79cvs-msn-c99isms.patch
(13:28:02) LSchiere: because we are so close to releaseing ;-)
(13:28:19) nosnilmot: LSchiere: yeah, 15 minutes right?
;-)
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sun, 06 Jun 2004 17:28:52 +0000 |
| parents | 74c81f56b0a5 |
| children | f46154d6de2b |
| 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 | |
|
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
83 if (friendly != NULL) |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
84 { |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
85 msg = g_strdup_printf( |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
86 _("The user %s (%s) wants to add %s to his or her " |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
87 "buddy list."), |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
88 passport, friendly, |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
89 gaim_account_get_username(gc->account)); |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
90 } |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
91 else |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
92 { |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
93 msg = g_strdup_printf( |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
94 _("The user %s wants to add %s to his or " |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
95 "her buddy list."), |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
96 passport, gaim_account_get_username(gc->account)); |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
97 } |
| 9193 | 98 |
| 99 gaim_request_action(gc, NULL, msg, NULL, 0, pa, 2, | |
| 100 _("Authorize"), G_CALLBACK(msn_accept_add_cb), | |
| 101 _("Deny"), G_CALLBACK(msn_cancel_add_cb)); | |
| 102 | |
| 103 g_free(msg); | |
| 104 } | |
| 105 | |
| 106 /************************************************************************** | |
| 107 * Utility functions | |
| 108 **************************************************************************/ | |
| 109 | |
| 110 static gboolean | |
| 111 user_is_in_group(MsnUser *user, int group_id) | |
| 112 { | |
| 113 if (user == NULL) | |
| 114 return FALSE; | |
| 115 | |
| 116 if (group_id < 0) | |
| 117 return FALSE; | |
| 118 | |
| 119 if (g_list_find(user->group_ids, GINT_TO_POINTER(group_id))) | |
| 120 return TRUE; | |
| 121 | |
| 122 return FALSE; | |
| 123 } | |
| 124 | |
| 125 static gboolean | |
| 126 user_is_there(MsnUser *user, int list_id, int group_id) | |
| 127 { | |
| 128 int list_op; | |
| 129 | |
| 130 if (user == NULL) | |
| 131 return FALSE; | |
| 132 | |
| 133 list_op = 1 << list_id; | |
| 134 | |
| 135 if (!(user->list_op & list_op)) | |
| 136 return FALSE; | |
| 137 | |
| 138 if (list_id == MSN_LIST_FL) | |
| 139 { | |
| 140 if (group_id >= 0) | |
| 141 return user_is_in_group(user, group_id); | |
| 142 } | |
| 143 | |
| 144 return TRUE; | |
| 145 } | |
| 146 | |
| 147 static const char* | |
| 148 get_store_name(MsnUser *user) | |
| 149 { | |
| 150 const char *store_name; | |
| 151 | |
| 152 g_return_val_if_fail(user != NULL, NULL); | |
| 153 | |
| 154 if ((store_name = msn_user_get_store_name(user)) != NULL) | |
| 155 return gaim_url_encode(store_name); | |
| 156 | |
| 157 return msn_user_get_passport(user); | |
| 158 } | |
| 159 | |
| 160 static void | |
| 161 msn_request_add_group(MsnUserList *userlist, const char *who, | |
| 162 const char *old_group_name, const char *new_group_name) | |
| 163 { | |
| 164 MsnCmdProc *cmdproc; | |
| 165 MsnTransaction *trans; | |
| 9218 | 166 MsnMoveBuddy *data; |
| 9193 | 167 |
| 168 cmdproc = userlist->session->notification->cmdproc; | |
| 9218 | 169 data = g_new0(MsnMoveBuddy, 1); |
| 9193 | 170 |
| 171 data->who = g_strdup(who); | |
| 172 | |
| 173 if (old_group_name) | |
| 174 data->old_group_name = g_strdup(old_group_name); | |
| 175 | |
| 176 trans = msn_transaction_new("ADG", "%s %d", | |
| 177 gaim_url_encode(new_group_name), | |
| 178 0); | |
| 179 | |
| 180 msn_transaction_set_data(trans, data); | |
| 181 | |
| 182 msn_cmdproc_send_trans(cmdproc, trans); | |
| 183 } | |
| 184 | |
| 185 /************************************************************************** | |
| 186 * Server functions | |
| 187 **************************************************************************/ | |
| 188 | |
| 189 MsnListId | |
| 190 msn_get_list_id(const char *list) | |
| 191 { | |
| 192 if (list[0] == 'F') | |
| 193 return MSN_LIST_FL; | |
| 194 else if (list[0] == 'A') | |
| 195 return MSN_LIST_AL; | |
| 196 else if (list[0] == 'B') | |
| 197 return MSN_LIST_BL; | |
| 198 else if (list[0] == 'R') | |
| 199 return MSN_LIST_RL; | |
| 200 | |
| 201 return -1; | |
| 202 } | |
| 203 | |
| 204 void | |
| 205 msn_got_add_user(MsnSession *session, MsnUser *user, | |
| 206 MsnListId list_id, int group_id) | |
| 207 { | |
| 208 GaimAccount *account; | |
| 209 const char *passport; | |
| 210 const char *friendly; | |
| 211 | |
| 212 account = session->account; | |
| 213 | |
| 214 passport = msn_user_get_passport(user); | |
| 215 friendly = msn_user_get_friendly_name(user); | |
|
9197
ec417d2f9666
[gaim-migrate @ 9992]
Christian Hammond <chipx86@chipx86.com>
parents:
9196
diff
changeset
|
216 |
| 9193 | 217 if (list_id == MSN_LIST_FL) |
| 218 { | |
| 219 GaimConnection *gc = gaim_account_get_connection(account); | |
| 220 | |
| 221 serv_got_alias(gc, passport, friendly); | |
| 222 | |
| 223 if (group_id >= 0) | |
| 224 { | |
| 225 msn_user_add_group_id(user, group_id); | |
| 226 return; | |
| 227 } | |
| 228 else | |
| 229 { | |
| 230 /* session->sync->fl_users_count++; */ | |
| 231 } | |
| 232 } | |
| 233 else if (list_id == MSN_LIST_AL) | |
| 234 { | |
| 235 gaim_privacy_permit_add(account, passport, TRUE); | |
| 236 } | |
| 237 else if (list_id == MSN_LIST_BL) | |
| 238 { | |
| 239 gaim_privacy_deny_add(account, passport, TRUE); | |
| 240 } | |
| 241 else if (list_id == MSN_LIST_RL) | |
| 242 { | |
| 243 GaimConnection *gc = gaim_account_get_connection(account); | |
| 244 | |
| 245 gaim_debug_info("msn", | |
| 246 "%s has added you to his or her contact list.\n", | |
| 247 passport); | |
| 248 | |
| 249 if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) | |
| 250 got_new_entry(gc, passport, friendly); | |
| 251 } | |
| 252 | |
| 253 user->list_op |= (1 << list_id); | |
| 254 /* gaim_user_add_list_id (user, list_id); */ | |
| 255 } | |
| 256 | |
| 257 void | |
| 258 msn_got_rem_user(MsnSession *session, MsnUser *user, | |
| 259 MsnListId list_id, int group_id) | |
| 260 { | |
| 261 GaimAccount *account; | |
| 262 const char *passport; | |
| 263 | |
| 264 account = session->account; | |
| 265 | |
| 266 passport = msn_user_get_passport(user); | |
| 267 | |
| 268 if (list_id == MSN_LIST_FL) | |
| 269 { | |
| 270 /* TODO: When is the user totally removed? */ | |
| 271 if (group_id >= 0) | |
| 272 { | |
| 273 msn_user_remove_group_id(user, group_id); | |
| 274 return; | |
| 275 } | |
| 276 else | |
| 277 { | |
| 278 /* session->sync->fl_users_count--; */ | |
| 279 } | |
| 280 } | |
| 281 else if (list_id == MSN_LIST_AL) | |
| 282 { | |
| 283 gaim_privacy_permit_remove(account, passport, TRUE); | |
| 284 } | |
| 285 else if (list_id == MSN_LIST_BL) | |
| 286 { | |
| 287 gaim_privacy_deny_remove(account, passport, TRUE); | |
| 288 } | |
| 289 else if (list_id == MSN_LIST_RL) | |
| 290 { | |
| 291 gaim_debug_info("msn", | |
| 292 "%s has removed you from his or her contact list.\n", | |
| 293 passport); | |
| 294 } | |
| 295 | |
| 296 user->list_op &= ~(1 << list_id); | |
| 297 /* gaim_user_remove_list_id (user, list_id); */ | |
| 298 | |
| 299 if (user->list_op == 0) | |
| 300 { | |
| 301 gaim_debug_info("msn", "Buddy '%s' shall be deleted?.\n", | |
| 302 passport); | |
| 303 | |
| 304 } | |
| 305 } | |
| 306 | |
| 307 void | |
| 308 msn_got_lst_user(MsnSession *session, MsnUser *user, | |
| 309 int list_op, GSList *group_ids) | |
| 310 { | |
| 311 GaimConnection *gc; | |
| 312 GaimAccount *account; | |
| 313 const char *passport; | |
| 314 const char *store; | |
| 315 | |
| 316 account = session->account; | |
| 317 gc = gaim_account_get_connection(account); | |
| 318 | |
| 319 passport = msn_user_get_passport(user); | |
|
9211
74c81f56b0a5
[gaim-migrate @ 10006]
Christian Hammond <chipx86@chipx86.com>
parents:
9210
diff
changeset
|
320 store = msn_user_get_store_name(user); |
| 9193 | 321 |
| 322 if (list_op & MSN_LIST_FL_OP) | |
| 323 { | |
| 324 GSList *c; | |
| 325 for (c = group_ids; c != NULL; c = g_slist_next(c)) | |
| 326 { | |
| 327 int group_id; | |
| 328 group_id = GPOINTER_TO_INT(c->data); | |
| 329 msn_user_add_group_id(user, group_id); | |
| 330 } | |
| 331 | |
| 332 /* FIXME: It might be a real alias */ | |
| 333 /* serv_got_alias(gc, passport, store); */ | |
| 334 } | |
| 335 | |
| 336 if (list_op & MSN_LIST_AL_OP) | |
| 337 { | |
| 338 /* These are users who are allowed to see our status. */ | |
| 339 | |
| 340 if (g_slist_find_custom(account->deny, passport, | |
| 341 (GCompareFunc)strcmp)) | |
| 342 { | |
| 343 gaim_privacy_deny_remove(gc->account, passport, TRUE); | |
| 344 } | |
| 345 | |
| 346 gaim_privacy_permit_add(account, passport, TRUE); | |
| 347 } | |
| 348 | |
| 349 if (list_op & MSN_LIST_BL_OP) | |
| 350 { | |
| 351 /* These are users who are not allowed to see our status. */ | |
| 352 | |
| 353 if (g_slist_find_custom(account->permit, passport, | |
| 354 (GCompareFunc)strcmp)) | |
| 355 { | |
| 356 gaim_privacy_permit_remove(gc->account, passport, TRUE); | |
| 357 } | |
| 358 | |
| 359 gaim_privacy_deny_add(account, passport, TRUE); | |
| 360 } | |
| 361 | |
| 362 if (list_op & MSN_LIST_RL_OP) | |
| 363 { | |
| 364 /* These are users who have us on their contact list. */ | |
| 365 /* TODO: what does store name is when this happens? */ | |
| 366 | |
| 367 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) | |
| 368 got_new_entry(gc, passport, store); | |
| 369 } | |
| 370 | |
| 371 user->list_op = list_op; | |
| 372 } | |
| 373 | |
| 374 /************************************************************************** | |
| 375 * UserList functions | |
| 376 **************************************************************************/ | |
| 377 | |
| 378 MsnUserList* | |
| 379 msn_userlist_new(MsnSession *session) | |
| 380 { | |
| 381 MsnUserList *userlist; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
382 |
| 9193 | 383 userlist = g_new0(MsnUserList, 1); |
| 384 | |
| 385 userlist->session = session; | |
| 386 | |
| 387 return userlist; | |
| 388 } | |
| 389 | |
| 390 void | |
| 391 msn_userlist_destroy(MsnUserList *userlist) | |
| 392 { | |
| 393 GList *l; | |
| 394 | |
| 395 for (l = userlist->users; l != NULL; l = l->next) | |
| 396 { | |
| 397 msn_user_destroy(l->data); | |
| 398 } | |
| 399 | |
| 400 g_list_free(userlist->users); | |
| 401 | |
| 402 for (l = userlist->groups; l != NULL; l = l->next) | |
| 403 { | |
| 404 msn_group_destroy(l->data); | |
| 405 } | |
| 406 | |
| 407 g_list_free(userlist->groups); | |
| 408 } | |
| 409 | |
| 410 void | |
| 411 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) | |
| 412 { | |
| 413 userlist->users = g_list_append(userlist->users, user); | |
| 414 } | |
| 415 | |
| 416 void | |
| 417 msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user) | |
| 418 { | |
| 419 userlist->users = g_list_remove(userlist->users, user); | |
| 420 } | |
| 421 | |
| 422 MsnUser * | |
| 423 msn_userlist_find_user(MsnUserList *userlist, const char *passport) | |
| 424 { | |
| 425 GList *l; | |
| 426 | |
| 427 g_return_val_if_fail(passport != NULL, NULL); | |
| 428 | |
| 429 for (l = userlist->users; l != NULL; l = l->next) | |
| 430 { | |
| 431 MsnUser *user = (MsnUser *)l->data; | |
| 432 | |
| 433 g_return_val_if_fail(user->passport != NULL, NULL); | |
| 434 | |
| 435 if (!strcmp(passport, user->passport)) | |
| 436 return user; | |
| 437 } | |
| 438 | |
| 439 return NULL; | |
| 440 } | |
| 441 | |
| 442 void | |
| 443 msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group) | |
| 444 { | |
| 445 userlist->groups = g_list_append(userlist->groups, group); | |
| 446 } | |
| 447 | |
| 448 void | |
| 449 msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group) | |
| 450 { | |
| 451 userlist->groups = g_list_remove(userlist->groups, group); | |
| 452 } | |
| 453 | |
| 454 MsnGroup * | |
| 455 msn_userlist_find_group_with_id(MsnUserList *userlist, int id) | |
| 456 { | |
| 457 GList *l; | |
| 458 | |
| 459 g_return_val_if_fail(userlist != NULL, NULL); | |
| 460 g_return_val_if_fail(id >= 0, NULL); | |
| 461 | |
| 462 for (l = userlist->groups; l != NULL; l = l->next) | |
| 463 { | |
| 464 MsnGroup *group = l->data; | |
| 465 | |
| 466 if (group->id == id) | |
| 467 return group; | |
| 468 } | |
| 469 | |
| 470 return NULL; | |
| 471 } | |
| 472 | |
| 473 MsnGroup * | |
| 474 msn_userlist_find_group_with_name(MsnUserList *userlist, const char *name) | |
| 475 { | |
| 476 GList *l; | |
| 477 | |
| 478 g_return_val_if_fail(userlist != NULL, NULL); | |
| 479 g_return_val_if_fail(name != NULL, NULL); | |
| 480 | |
| 481 for (l = userlist->groups; l != NULL; l = l->next) | |
| 482 { | |
| 483 MsnGroup *group = l->data; | |
| 484 | |
| 485 if ((group->name != NULL) && !g_ascii_strcasecmp(name, group->name)) | |
| 486 return group; | |
| 487 } | |
| 488 | |
| 489 return NULL; | |
| 490 } | |
| 491 | |
| 492 int | |
| 493 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) | |
| 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_name(userlist, group_name); |
| 498 | |
| 499 if (group != NULL) | |
| 500 return msn_group_get_id(group); | |
| 501 else | |
| 502 return -1; | |
| 503 } | |
| 504 | |
| 505 const char * | |
| 506 msn_userlist_find_group_name(MsnUserList *userlist, int group_id) | |
| 507 { | |
| 508 MsnGroup *group; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
509 |
| 9193 | 510 group = msn_userlist_find_group_with_id(userlist, group_id); |
| 511 | |
| 512 if (group != NULL) | |
| 513 return msn_group_get_name(group); | |
| 514 else | |
| 515 return NULL; | |
| 516 } | |
| 517 | |
| 518 void | |
| 519 msn_userlist_rename_group_id(MsnUserList *userlist, int group_id, | |
| 520 const char *new_name) | |
| 521 { | |
| 522 MsnGroup *group; | |
| 523 | |
| 524 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 525 | |
| 526 if (group != NULL) | |
| 527 msn_group_set_name(group, new_name); | |
| 528 } | |
| 529 | |
| 530 void | |
| 531 msn_userlist_remove_group_id(MsnUserList *userlist, int group_id) | |
| 532 { | |
| 533 MsnGroup *group; | |
| 534 | |
| 535 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 536 | |
| 537 if (group != NULL) | |
| 538 msn_userlist_remove_group(userlist, group); | |
| 539 } | |
| 540 | |
| 541 void | |
| 542 msn_userlist_rem_buddy(MsnUserList *userlist, | |
| 543 const char *who, int list_id, const char *group_name) | |
| 544 { | |
| 545 MsnUser *user; | |
| 546 int group_id; | |
| 547 const char *list; | |
| 548 | |
| 549 user = msn_userlist_find_user(userlist, who); | |
| 550 group_id = -1; | |
| 551 | |
| 552 if (group_name != NULL) | |
| 553 { | |
| 554 group_id = msn_userlist_find_group_id(userlist, group_name); | |
| 555 | |
| 556 if (group_id < 0) | |
| 557 { | |
| 558 /* Whoa, there is no such group. */ | |
| 559 gaim_debug_error("msn", "Group doesn't exist: %s\n", group_name); | |
| 560 return; | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 /* First we're going to check if not there. */ | |
| 565 if (!(user_is_there(user, list_id, group_id))) | |
| 566 { | |
| 567 list = lists[list_id]; | |
| 568 gaim_debug_error("msn", "User '%s' is not there: %s\n", | |
| 569 who, list); | |
| 570 return; | |
| 571 } | |
| 572 | |
| 573 /* Then request the rem to the server. */ | |
| 574 list = lists[list_id]; | |
| 575 | |
| 576 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); | |
| 577 } | |
| 578 | |
| 579 void | |
| 580 msn_userlist_add_buddy(MsnUserList *userlist, | |
| 581 const char *who, int list_id, | |
| 582 const char *group_name) | |
| 583 { | |
| 584 MsnUser *user; | |
| 585 int group_id; | |
| 586 const char *list; | |
| 587 const char *store_name; | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
588 |
| 9193 | 589 group_id = -1; |
| 590 | |
| 591 if (group_name != NULL) | |
| 592 { | |
| 593 group_id = msn_userlist_find_group_id(userlist, group_name); | |
| 594 | |
| 595 if (group_id < 0) | |
| 596 { | |
| 597 /* Whoa, we must add that group first. */ | |
| 598 msn_request_add_group(userlist, who, NULL, group_name); | |
| 599 return; | |
| 600 } | |
| 601 } | |
| 602 | |
| 603 user = msn_userlist_find_user(userlist, who); | |
| 604 | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
605 /* First we're going to check if it's already there. */ |
| 9193 | 606 if (user_is_there(user, list_id, group_id)) |
| 607 { | |
| 608 list = lists[list_id]; | |
|
9195
d5487fdec696
[gaim-migrate @ 9990]
Christian Hammond <chipx86@chipx86.com>
parents:
9194
diff
changeset
|
609 #if 0 |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
610 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
|
611 #endif |
| 9193 | 612 return; |
| 613 } | |
| 614 | |
| 615 store_name = (user != NULL) ? get_store_name(user) : who; | |
| 616 | |
| 617 /* Then request the add to the server. */ | |
| 618 list = lists[list_id]; | |
| 619 | |
| 620 msn_notification_add_buddy(userlist->session->notification, list, who, | |
| 621 store_name, group_id); | |
| 622 } | |
| 623 | |
| 624 void | |
| 625 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, | |
| 626 const char *old_group_name, const char *new_group_name) | |
| 627 { | |
| 628 int new_group_id; | |
| 629 | |
| 630 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); | |
| 631 | |
| 632 if (new_group_id < 0) | |
| 633 { | |
| 634 msn_request_add_group(userlist, who, old_group_name, new_group_name); | |
| 635 return; | |
| 636 } | |
| 637 | |
| 638 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name); | |
| 639 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); | |
| 640 } |
