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