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