Mercurial > pidgin
annotate src/protocols/msn/userlist.c @ 13867:a092ea4edd4e
[gaim-migrate @ 16333]
Patch #1511180: Buddy list ui_ops fix
I had a hard time figuring out why things were not
working even after I set the blist-uiops using
gaim_blist_set_ui_ops. This patch is a fix for it.
committer: Tailor Script <tailor@pidgin.im>
| author | Sadrul Habib Chowdhury <imadil@gmail.com> |
|---|---|
| date | Sat, 24 Jun 2006 22:25:22 +0000 |
| parents | 6c3c8d0d389f |
| children | 6fc412e59214 852b32710df0 |
| 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; | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
33 char *friendly; |
| 9193 | 34 |
| 35 } MsnPermitAdd; | |
| 36 | |
| 37 /************************************************************************** | |
| 38 * Callbacks | |
| 39 **************************************************************************/ | |
| 40 static void | |
| 41 msn_accept_add_cb(MsnPermitAdd *pa) | |
| 42 { | |
| 43 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
| 44 { | |
| 45 MsnSession *session = pa->gc->proto_data; | |
| 46 MsnUserList *userlist = session->userlist; | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
47 GaimBuddy *buddy; |
| 9193 | 48 |
| 49 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL); | |
| 50 | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
51 buddy = gaim_find_buddy(pa->gc->account, pa->who); |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
52 |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
53 if (buddy != NULL) |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
54 gaim_account_notify_added(pa->gc->account, pa->who, |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
55 NULL, pa->friendly, NULL); |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
56 else |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
57 gaim_account_request_add(pa->gc->account, pa->who, |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
58 NULL, pa->friendly, NULL); |
| 9193 | 59 } |
| 60 | |
| 61 g_free(pa->who); | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
62 g_free(pa->friendly); |
| 9193 | 63 g_free(pa); |
| 64 } | |
| 65 | |
| 66 static void | |
| 67 msn_cancel_add_cb(MsnPermitAdd *pa) | |
| 68 { | |
| 69 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
| 70 { | |
| 71 MsnSession *session = pa->gc->proto_data; | |
| 72 MsnUserList *userlist = session->userlist; | |
| 73 | |
| 74 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_BL, NULL); | |
| 75 } | |
| 76 | |
| 77 g_free(pa->who); | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
78 g_free(pa->friendly); |
| 9193 | 79 g_free(pa); |
| 80 } | |
| 81 | |
| 82 static void | |
| 9976 | 83 got_new_entry(GaimConnection *gc, const char *passport, const char *friendly) |
| 9193 | 84 { |
| 85 MsnPermitAdd *pa; | |
| 10774 | 86 char *msg; |
| 9193 | 87 |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
88 pa = g_new0(MsnPermitAdd, 1); |
| 9193 | 89 pa->who = g_strdup(passport); |
| 12381 | 90 pa->friendly = g_strdup(friendly); |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
91 pa->gc = gc; |
| 9193 | 92 |
|
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
93 if (friendly != NULL) |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
94 { |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
95 msg = g_strdup_printf( |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
96 _("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
|
97 "buddy list."), |
| 10774 | 98 passport, friendly, |
|
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
99 gaim_account_get_username(gc->account)); |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
100 } |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
101 else |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
102 { |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
103 msg = g_strdup_printf( |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
104 _("The user %s wants to add %s to his or " |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
105 "her buddy list."), |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
106 passport, gaim_account_get_username(gc->account)); |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
107 } |
| 9193 | 108 |
| 9976 | 109 gaim_request_action(gc, NULL, msg, NULL, |
| 9948 | 110 GAIM_DEFAULT_ACTION_NONE, pa, 2, |
| 9193 | 111 _("Authorize"), G_CALLBACK(msn_accept_add_cb), |
| 112 _("Deny"), G_CALLBACK(msn_cancel_add_cb)); | |
| 113 | |
| 114 g_free(msg); | |
| 115 } | |
| 116 | |
| 117 /************************************************************************** | |
| 118 * Utility functions | |
| 119 **************************************************************************/ | |
| 120 | |
| 121 static gboolean | |
| 122 user_is_in_group(MsnUser *user, int group_id) | |
| 123 { | |
| 124 if (user == NULL) | |
| 125 return FALSE; | |
| 126 | |
| 127 if (group_id < 0) | |
| 128 return FALSE; | |
| 129 | |
| 130 if (g_list_find(user->group_ids, GINT_TO_POINTER(group_id))) | |
| 131 return TRUE; | |
| 132 | |
| 133 return FALSE; | |
| 134 } | |
| 135 | |
| 136 static gboolean | |
| 137 user_is_there(MsnUser *user, int list_id, int group_id) | |
| 138 { | |
| 139 int list_op; | |
| 140 | |
| 141 if (user == NULL) | |
| 142 return FALSE; | |
| 143 | |
| 144 list_op = 1 << list_id; | |
| 145 | |
| 146 if (!(user->list_op & list_op)) | |
| 147 return FALSE; | |
| 148 | |
| 149 if (list_id == MSN_LIST_FL) | |
| 150 { | |
| 151 if (group_id >= 0) | |
| 152 return user_is_in_group(user, group_id); | |
| 153 } | |
| 154 | |
| 155 return TRUE; | |
| 156 } | |
| 157 | |
| 158 static const char* | |
| 159 get_store_name(MsnUser *user) | |
| 160 { | |
| 161 const char *store_name; | |
| 162 | |
| 163 g_return_val_if_fail(user != NULL, NULL); | |
| 164 | |
| 10533 | 165 store_name = msn_user_get_store_name(user); |
| 166 | |
| 167 if (store_name != NULL) | |
| 168 store_name = gaim_url_encode(store_name); | |
| 169 else | |
| 170 store_name = msn_user_get_passport(user); | |
| 9193 | 171 |
| 10533 | 172 /* this might be a bit of a hack, but it should prevent notification server |
| 173 * disconnections for people who have buddies with insane friendly names | |
| 174 * who added you to their buddy list from being disconnected. Stu. */ | |
| 175 /* Shx: What? Isn't the store_name obtained from the server, and hence it's | |
| 176 * below the BUDDY_ALIAS_MAXLEN ? */ | |
| 177 /* Stu: yeah, that's why it's a bit of a hack, as you pointed out, we're | |
| 178 * probably decoding the incoming store_name wrong, or something. bleh. */ | |
| 179 | |
| 180 if (strlen(store_name) > BUDDY_ALIAS_MAXLEN) | |
| 181 store_name = msn_user_get_passport(user); | |
| 182 | |
| 183 return store_name; | |
| 9193 | 184 } |
| 185 | |
| 186 static void | |
| 187 msn_request_add_group(MsnUserList *userlist, const char *who, | |
| 188 const char *old_group_name, const char *new_group_name) | |
| 189 { | |
| 190 MsnCmdProc *cmdproc; | |
| 191 MsnTransaction *trans; | |
| 9218 | 192 MsnMoveBuddy *data; |
| 9193 | 193 |
| 194 cmdproc = userlist->session->notification->cmdproc; | |
| 9218 | 195 data = g_new0(MsnMoveBuddy, 1); |
| 9193 | 196 |
| 197 data->who = g_strdup(who); | |
| 198 | |
| 199 if (old_group_name) | |
| 200 data->old_group_name = g_strdup(old_group_name); | |
| 201 | |
| 10225 | 202 trans = msn_transaction_new(cmdproc, "ADG", "%s %d", |
| 9193 | 203 gaim_url_encode(new_group_name), |
| 204 0); | |
| 205 | |
| 206 msn_transaction_set_data(trans, data); | |
| 207 | |
| 208 msn_cmdproc_send_trans(cmdproc, trans); | |
| 209 } | |
| 210 | |
| 211 /************************************************************************** | |
| 212 * Server functions | |
| 213 **************************************************************************/ | |
| 214 | |
| 215 MsnListId | |
| 216 msn_get_list_id(const char *list) | |
| 217 { | |
| 218 if (list[0] == 'F') | |
| 219 return MSN_LIST_FL; | |
| 220 else if (list[0] == 'A') | |
| 221 return MSN_LIST_AL; | |
| 222 else if (list[0] == 'B') | |
| 223 return MSN_LIST_BL; | |
| 224 else if (list[0] == 'R') | |
| 225 return MSN_LIST_RL; | |
| 226 | |
| 227 return -1; | |
| 228 } | |
| 229 | |
| 230 void | |
| 231 msn_got_add_user(MsnSession *session, MsnUser *user, | |
| 232 MsnListId list_id, int group_id) | |
| 233 { | |
| 234 GaimAccount *account; | |
| 235 const char *passport; | |
| 236 const char *friendly; | |
| 237 | |
| 238 account = session->account; | |
| 239 | |
| 240 passport = msn_user_get_passport(user); | |
| 241 friendly = msn_user_get_friendly_name(user); | |
|
9197
ec417d2f9666
[gaim-migrate @ 9992]
Christian Hammond <chipx86@chipx86.com>
parents:
9196
diff
changeset
|
242 |
| 9193 | 243 if (list_id == MSN_LIST_FL) |
| 244 { | |
| 9861 | 245 GaimConnection *gc; |
| 246 | |
| 247 gc = gaim_account_get_connection(account); | |
| 9193 | 248 |
| 249 serv_got_alias(gc, passport, friendly); | |
| 250 | |
| 251 if (group_id >= 0) | |
| 252 { | |
| 253 msn_user_add_group_id(user, group_id); | |
| 254 } | |
| 255 else | |
| 256 { | |
| 257 /* session->sync->fl_users_count++; */ | |
| 258 } | |
| 259 } | |
| 260 else if (list_id == MSN_LIST_AL) | |
| 261 { | |
| 262 gaim_privacy_permit_add(account, passport, TRUE); | |
| 263 } | |
| 264 else if (list_id == MSN_LIST_BL) | |
| 265 { | |
| 266 gaim_privacy_deny_add(account, passport, TRUE); | |
| 267 } | |
| 268 else if (list_id == MSN_LIST_RL) | |
| 269 { | |
| 9861 | 270 GaimConnection *gc; |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
271 GaimConversation *convo; |
| 9861 | 272 |
| 273 gc = gaim_account_get_connection(account); | |
| 9193 | 274 |
| 275 gaim_debug_info("msn", | |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
276 "%s has added you to his or her buddy list.\n", |
| 9193 | 277 passport); |
| 278 | |
| 11338 | 279 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, account); |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
280 if (convo) { |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
281 GaimBuddy *buddy; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
282 char *msg; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
283 |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
284 buddy = gaim_find_buddy(account, passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
285 msg = g_strdup_printf( |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
286 _("%s has added you to his or her buddy list."), |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
287 buddy ? gaim_buddy_get_contact_alias(buddy) : passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
288 gaim_conv_im_write(GAIM_CONV_IM(convo), passport, msg, |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
289 GAIM_MESSAGE_SYSTEM, time(NULL)); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
290 g_free(msg); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
291 } |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
292 |
| 10583 | 293 if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) |
|
9223
f46154d6de2b
[gaim-migrate @ 10019]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
294 { |
| 13827 | 295 /* |
| 296 * TODO: The friendly name was NULL for me when I | |
| 297 * looked at this. Maybe we should use the store | |
| 298 * name instead? --KingAnt | |
| 299 */ | |
| 9193 | 300 got_new_entry(gc, passport, friendly); |
|
9223
f46154d6de2b
[gaim-migrate @ 10019]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
301 } |
| 9193 | 302 } |
| 303 | |
| 304 user->list_op |= (1 << list_id); | |
| 305 /* gaim_user_add_list_id (user, list_id); */ | |
| 306 } | |
| 307 | |
| 308 void | |
| 309 msn_got_rem_user(MsnSession *session, MsnUser *user, | |
| 310 MsnListId list_id, int group_id) | |
| 311 { | |
| 312 GaimAccount *account; | |
| 313 const char *passport; | |
| 314 | |
| 315 account = session->account; | |
| 316 | |
| 317 passport = msn_user_get_passport(user); | |
| 318 | |
| 319 if (list_id == MSN_LIST_FL) | |
| 320 { | |
| 321 /* TODO: When is the user totally removed? */ | |
| 322 if (group_id >= 0) | |
| 323 { | |
| 324 msn_user_remove_group_id(user, group_id); | |
| 325 return; | |
| 326 } | |
| 327 else | |
| 328 { | |
| 329 /* session->sync->fl_users_count--; */ | |
| 330 } | |
| 331 } | |
| 332 else if (list_id == MSN_LIST_AL) | |
| 333 { | |
| 334 gaim_privacy_permit_remove(account, passport, TRUE); | |
| 335 } | |
| 336 else if (list_id == MSN_LIST_BL) | |
| 337 { | |
| 338 gaim_privacy_deny_remove(account, passport, TRUE); | |
| 339 } | |
| 340 else if (list_id == MSN_LIST_RL) | |
| 341 { | |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
342 GaimConversation *convo; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
343 |
| 9193 | 344 gaim_debug_info("msn", |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
345 "%s has removed you from his or her buddy list.\n", |
| 9193 | 346 passport); |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
347 |
| 11338 | 348 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, account); |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
349 if (convo) { |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
350 GaimBuddy *buddy; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
351 char *msg; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
352 |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
353 buddy = gaim_find_buddy(account, passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
354 msg = g_strdup_printf( |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
355 _("%s has removed you from his or her buddy list."), |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
356 buddy ? gaim_buddy_get_contact_alias(buddy) : passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
357 gaim_conv_im_write(GAIM_CONV_IM(convo), passport, msg, |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
358 GAIM_MESSAGE_SYSTEM, time(NULL)); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
359 g_free(msg); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
360 } |
| 9193 | 361 } |
| 362 | |
| 363 user->list_op &= ~(1 << list_id); | |
| 364 /* gaim_user_remove_list_id (user, list_id); */ | |
| 365 | |
| 366 if (user->list_op == 0) | |
| 367 { | |
| 368 gaim_debug_info("msn", "Buddy '%s' shall be deleted?.\n", | |
| 369 passport); | |
| 370 | |
| 371 } | |
| 372 } | |
| 373 | |
| 374 void | |
| 375 msn_got_lst_user(MsnSession *session, MsnUser *user, | |
| 376 int list_op, GSList *group_ids) | |
| 377 { | |
| 378 GaimConnection *gc; | |
| 379 GaimAccount *account; | |
| 380 const char *passport; | |
| 381 const char *store; | |
| 382 | |
| 383 account = session->account; | |
| 384 gc = gaim_account_get_connection(account); | |
| 385 | |
| 386 passport = msn_user_get_passport(user); | |
|
9211
74c81f56b0a5
[gaim-migrate @ 10006]
Christian Hammond <chipx86@chipx86.com>
parents:
9210
diff
changeset
|
387 store = msn_user_get_store_name(user); |
| 9193 | 388 |
| 389 if (list_op & MSN_LIST_FL_OP) | |
| 390 { | |
| 391 GSList *c; | |
| 392 for (c = group_ids; c != NULL; c = g_slist_next(c)) | |
| 393 { | |
| 394 int group_id; | |
| 395 group_id = GPOINTER_TO_INT(c->data); | |
| 396 msn_user_add_group_id(user, group_id); | |
| 397 } | |
| 398 | |
| 399 /* FIXME: It might be a real alias */ | |
| 13448 | 400 /* Umm, what? This might fix bug #1385130 */ |
| 401 serv_got_alias(gc, passport, store); | |
| 9193 | 402 } |
| 403 | |
| 404 if (list_op & MSN_LIST_AL_OP) | |
| 405 { | |
| 406 /* These are users who are allowed to see our status. */ | |
|
13692
ea77ce998dc7
[gaim-migrate @ 16095]
Richard Laager <rlaager@wiktel.com>
parents:
13448
diff
changeset
|
407 gaim_privacy_deny_remove(account, passport, TRUE); |
| 9193 | 408 gaim_privacy_permit_add(account, passport, TRUE); |
| 409 } | |
| 410 | |
| 411 if (list_op & MSN_LIST_BL_OP) | |
| 412 { | |
| 413 /* These are users who are not allowed to see our status. */ | |
|
13692
ea77ce998dc7
[gaim-migrate @ 16095]
Richard Laager <rlaager@wiktel.com>
parents:
13448
diff
changeset
|
414 gaim_privacy_permit_remove(account, passport, TRUE); |
| 9193 | 415 gaim_privacy_deny_add(account, passport, TRUE); |
| 416 } | |
| 417 | |
| 418 if (list_op & MSN_LIST_RL_OP) | |
| 419 { | |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
420 /* These are users who have us on their buddy list. */ |
| 13827 | 421 /* |
| 422 * TODO: What is store name set to when this happens? | |
| 423 * For one of my accounts "something@hotmail.com" | |
| 424 * the store name was "something." Maybe we | |
| 425 * should use the friendly name, instead? --KingAnt | |
| 426 */ | |
| 9193 | 427 |
| 10583 | 428 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) |
|
9225
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9223
diff
changeset
|
429 { |
| 9193 | 430 got_new_entry(gc, passport, store); |
|
9225
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9223
diff
changeset
|
431 } |
| 9193 | 432 } |
| 433 | |
| 434 user->list_op = list_op; | |
| 435 } | |
| 436 | |
| 437 /************************************************************************** | |
| 438 * UserList functions | |
| 439 **************************************************************************/ | |
| 440 | |
| 441 MsnUserList* | |
| 442 msn_userlist_new(MsnSession *session) | |
| 443 { | |
| 444 MsnUserList *userlist; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
445 |
| 9193 | 446 userlist = g_new0(MsnUserList, 1); |
| 447 | |
| 448 userlist->session = session; | |
| 9860 | 449 userlist->buddy_icon_requests = g_queue_new(); |
| 13125 | 450 |
| 451 /* buddy_icon_window is the number of allowed simultaneous buddy icon requests. | |
| 452 * XXX With smarter rate limiting code, we could allow more at once... 5 was the limit set when | |
| 453 * we weren't retrieiving any more than 5 per MSN session. */ | |
| 454 userlist->buddy_icon_window = 1; | |
| 9193 | 455 |
| 456 return userlist; | |
| 457 } | |
| 458 | |
| 459 void | |
| 460 msn_userlist_destroy(MsnUserList *userlist) | |
| 461 { | |
| 462 GList *l; | |
| 463 | |
| 464 for (l = userlist->users; l != NULL; l = l->next) | |
| 465 { | |
| 466 msn_user_destroy(l->data); | |
| 467 } | |
| 468 | |
| 469 g_list_free(userlist->users); | |
| 470 | |
| 471 for (l = userlist->groups; l != NULL; l = l->next) | |
| 472 { | |
| 473 msn_group_destroy(l->data); | |
| 474 } | |
| 475 | |
| 476 g_list_free(userlist->groups); | |
| 9895 | 477 |
| 478 g_queue_free(userlist->buddy_icon_requests); | |
| 13125 | 479 |
| 480 if (userlist->buddy_icon_request_timer) | |
| 481 gaim_timeout_remove(userlist->buddy_icon_request_timer); | |
| 482 | |
| 9857 | 483 g_free(userlist); |
| 9193 | 484 } |
| 485 | |
| 486 void | |
| 487 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) | |
| 488 { | |
| 489 userlist->users = g_list_append(userlist->users, user); | |
| 490 } | |
| 491 | |
| 492 void | |
| 493 msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user) | |
| 494 { | |
| 495 userlist->users = g_list_remove(userlist->users, user); | |
| 496 } | |
| 497 | |
| 498 MsnUser * | |
| 499 msn_userlist_find_user(MsnUserList *userlist, const char *passport) | |
| 500 { | |
| 501 GList *l; | |
| 502 | |
| 503 g_return_val_if_fail(passport != NULL, NULL); | |
| 504 | |
| 505 for (l = userlist->users; l != NULL; l = l->next) | |
| 506 { | |
| 507 MsnUser *user = (MsnUser *)l->data; | |
| 508 | |
| 509 g_return_val_if_fail(user->passport != NULL, NULL); | |
| 510 | |
| 511 if (!strcmp(passport, user->passport)) | |
| 512 return user; | |
| 513 } | |
| 514 | |
| 515 return NULL; | |
| 516 } | |
| 517 | |
| 518 void | |
| 519 msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group) | |
| 520 { | |
| 521 userlist->groups = g_list_append(userlist->groups, group); | |
| 522 } | |
| 523 | |
| 524 void | |
| 525 msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group) | |
| 526 { | |
| 527 userlist->groups = g_list_remove(userlist->groups, group); | |
| 528 } | |
| 529 | |
| 530 MsnGroup * | |
| 531 msn_userlist_find_group_with_id(MsnUserList *userlist, int id) | |
| 532 { | |
| 533 GList *l; | |
| 534 | |
| 535 g_return_val_if_fail(userlist != NULL, NULL); | |
| 536 g_return_val_if_fail(id >= 0, NULL); | |
| 537 | |
| 538 for (l = userlist->groups; l != NULL; l = l->next) | |
| 539 { | |
| 540 MsnGroup *group = l->data; | |
| 541 | |
| 542 if (group->id == id) | |
| 543 return group; | |
| 544 } | |
| 545 | |
| 546 return NULL; | |
| 547 } | |
| 548 | |
| 549 MsnGroup * | |
| 550 msn_userlist_find_group_with_name(MsnUserList *userlist, const char *name) | |
| 551 { | |
| 552 GList *l; | |
| 553 | |
| 554 g_return_val_if_fail(userlist != NULL, NULL); | |
| 555 g_return_val_if_fail(name != NULL, NULL); | |
| 556 | |
| 557 for (l = userlist->groups; l != NULL; l = l->next) | |
| 558 { | |
| 559 MsnGroup *group = l->data; | |
| 560 | |
| 561 if ((group->name != NULL) && !g_ascii_strcasecmp(name, group->name)) | |
| 562 return group; | |
| 563 } | |
| 564 | |
| 565 return NULL; | |
| 566 } | |
| 567 | |
| 568 int | |
| 569 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) | |
| 570 { | |
| 571 MsnGroup *group; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
572 |
| 9193 | 573 group = msn_userlist_find_group_with_name(userlist, group_name); |
| 574 | |
| 575 if (group != NULL) | |
| 576 return msn_group_get_id(group); | |
| 577 else | |
| 578 return -1; | |
| 579 } | |
| 580 | |
| 581 const char * | |
| 582 msn_userlist_find_group_name(MsnUserList *userlist, int group_id) | |
| 583 { | |
| 584 MsnGroup *group; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
585 |
| 9193 | 586 group = msn_userlist_find_group_with_id(userlist, group_id); |
| 587 | |
| 588 if (group != NULL) | |
| 589 return msn_group_get_name(group); | |
| 590 else | |
| 591 return NULL; | |
| 592 } | |
| 593 | |
| 594 void | |
| 595 msn_userlist_rename_group_id(MsnUserList *userlist, int group_id, | |
| 596 const char *new_name) | |
| 597 { | |
| 598 MsnGroup *group; | |
| 599 | |
| 600 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 601 | |
| 602 if (group != NULL) | |
| 603 msn_group_set_name(group, new_name); | |
| 604 } | |
| 605 | |
| 606 void | |
| 607 msn_userlist_remove_group_id(MsnUserList *userlist, int group_id) | |
| 608 { | |
| 609 MsnGroup *group; | |
| 610 | |
| 611 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 612 | |
| 613 if (group != NULL) | |
| 10533 | 614 { |
| 9193 | 615 msn_userlist_remove_group(userlist, group); |
| 10533 | 616 msn_group_destroy(group); |
| 617 } | |
| 9193 | 618 } |
| 619 | |
| 620 void | |
| 621 msn_userlist_rem_buddy(MsnUserList *userlist, | |
| 622 const char *who, int list_id, const char *group_name) | |
| 623 { | |
| 624 MsnUser *user; | |
| 625 int group_id; | |
| 626 const char *list; | |
| 627 | |
| 628 user = msn_userlist_find_user(userlist, who); | |
| 629 group_id = -1; | |
| 630 | |
| 631 if (group_name != NULL) | |
| 632 { | |
| 633 group_id = msn_userlist_find_group_id(userlist, group_name); | |
| 634 | |
| 635 if (group_id < 0) | |
| 636 { | |
| 637 /* Whoa, there is no such group. */ | |
| 638 gaim_debug_error("msn", "Group doesn't exist: %s\n", group_name); | |
| 639 return; | |
| 640 } | |
| 641 } | |
| 642 | |
| 643 /* First we're going to check if not there. */ | |
| 644 if (!(user_is_there(user, list_id, group_id))) | |
| 645 { | |
| 646 list = lists[list_id]; | |
| 647 gaim_debug_error("msn", "User '%s' is not there: %s\n", | |
| 648 who, list); | |
| 649 return; | |
| 650 } | |
| 651 | |
| 652 /* Then request the rem to the server. */ | |
| 653 list = lists[list_id]; | |
| 654 | |
| 655 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); | |
| 656 } | |
| 657 | |
| 658 void | |
| 659 msn_userlist_add_buddy(MsnUserList *userlist, | |
| 660 const char *who, int list_id, | |
| 661 const char *group_name) | |
| 662 { | |
| 663 MsnUser *user; | |
| 664 int group_id; | |
| 665 const char *list; | |
| 666 const char *store_name; | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
667 |
| 9193 | 668 group_id = -1; |
| 669 | |
|
11057
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
670 if (!gaim_email_is_valid(who)) |
|
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
671 { |
| 11638 | 672 /* only notify the user about problems adding to the friends list |
| 673 * maybe we should do something else for other lists, but it probably | |
| 674 * won't cause too many problems if we just ignore it */ | |
| 675 if (list_id == MSN_LIST_FL) | |
| 676 { | |
| 677 char *str = g_strdup_printf(_("Unable to add \"%s\"."), who); | |
| 678 gaim_notify_error(NULL, NULL, str, | |
| 679 _("The screen name specified is invalid.")); | |
| 680 g_free(str); | |
| 681 } | |
| 682 | |
|
11057
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
683 return; |
|
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
684 } |
|
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
685 |
| 9193 | 686 if (group_name != NULL) |
| 687 { | |
| 688 group_id = msn_userlist_find_group_id(userlist, group_name); | |
| 689 | |
| 690 if (group_id < 0) | |
| 691 { | |
| 692 /* Whoa, we must add that group first. */ | |
| 693 msn_request_add_group(userlist, who, NULL, group_name); | |
| 694 return; | |
| 695 } | |
| 696 } | |
| 697 | |
| 698 user = msn_userlist_find_user(userlist, who); | |
| 699 | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
700 /* First we're going to check if it's already there. */ |
| 9193 | 701 if (user_is_there(user, list_id, group_id)) |
| 702 { | |
| 703 list = lists[list_id]; | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
704 gaim_debug_error("msn", "User '%s' is already there: %s\n", who, list); |
| 9193 | 705 return; |
| 706 } | |
| 707 | |
| 708 store_name = (user != NULL) ? get_store_name(user) : who; | |
| 709 | |
| 710 /* Then request the add to the server. */ | |
| 711 list = lists[list_id]; | |
| 712 | |
| 713 msn_notification_add_buddy(userlist->session->notification, list, who, | |
| 714 store_name, group_id); | |
| 715 } | |
| 716 | |
| 717 void | |
| 718 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, | |
| 719 const char *old_group_name, const char *new_group_name) | |
| 720 { | |
| 721 int new_group_id; | |
| 722 | |
| 723 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); | |
| 724 | |
| 725 if (new_group_id < 0) | |
| 726 { | |
| 727 msn_request_add_group(userlist, who, old_group_name, new_group_name); | |
| 728 return; | |
| 729 } | |
| 730 | |
| 10568 | 731 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); |
| 9193 | 732 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name); |
| 733 } |
