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