libpurple/protocols/mxit/multimx.c

branch
soc.2013.gobjectification
changeset 34637
9cdc9e6eecce
parent 34625
03d62b1660fc
child 34670
9bd5bd903dc7
equal deleted inserted replaced
34636:cfbdf3297c99 34637:9cdc9e6eecce
177 * Another user has join the GroupChat, add them to the member-list. 177 * Another user has join the GroupChat, add them to the member-list.
178 * 178 *
179 * @param convo The Conversation object 179 * @param convo The Conversation object
180 * @param nickname The nickname of the user who joined the room 180 * @param nickname The nickname of the user who joined the room
181 */ 181 */
182 static void member_added(PurpleConversation* convo, const char* nickname) 182 static void member_added(PurpleChatConversation* chat, const char* nickname)
183 { 183 {
184 purple_debug_info(MXIT_PLUGIN_ID, "member_added: '%s'\n", nickname); 184 purple_debug_info(MXIT_PLUGIN_ID, "member_added: '%s'\n", nickname);
185 185
186 purple_chat_conversation_add_user(PURPLE_CONV_CHAT(convo), nickname, NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE); 186 purple_chat_conversation_add_user(chat, nickname, NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
187 } 187 }
188 188
189 189
190 /*------------------------------------------------------------------------ 190 /*------------------------------------------------------------------------
191 * Another user has left the GroupChat, remove them from the member-list. 191 * Another user has left the GroupChat, remove them from the member-list.
192 * 192 *
193 * @param convo The Conversation object 193 * @param convo The Conversation object
194 * @param nickname The nickname of the user who left the room 194 * @param nickname The nickname of the user who left the room
195 */ 195 */
196 static void member_removed(PurpleConversation* convo, const char* nickname) 196 static void member_removed(PurpleChatConversation* chat, const char* nickname)
197 { 197 {
198 purple_debug_info(MXIT_PLUGIN_ID, "member_removed: '%s'\n", nickname); 198 purple_debug_info(MXIT_PLUGIN_ID, "member_removed: '%s'\n", nickname);
199 199
200 purple_chat_conversation_remove_user(PURPLE_CONV_CHAT(convo), nickname, NULL); 200 purple_chat_conversation_remove_user(chat, nickname, NULL);
201 } 201 }
202 202
203 203
204 /*------------------------------------------------------------------------ 204 /*------------------------------------------------------------------------
205 * A user was kicked from the GroupChat, remove them from the member-list. 205 * A user was kicked from the GroupChat, remove them from the member-list.
206 * 206 *
207 * @param convo The Conversation object 207 * @param convo The Conversation object
208 * @param nickname The nickname of the user who was kicked 208 * @param nickname The nickname of the user who was kicked
209 */ 209 */
210 static void member_kicked(PurpleConversation* convo, const char* nickname) 210 static void member_kicked(PurpleChatConversation* chat, const char* nickname)
211 { 211 {
212 purple_debug_info(MXIT_PLUGIN_ID, "member_kicked: '%s'\n", nickname); 212 purple_debug_info(MXIT_PLUGIN_ID, "member_kicked: '%s'\n", nickname);
213 213
214 purple_chat_conversation_remove_user(PURPLE_CONV_CHAT(convo), nickname, _("was kicked")); 214 purple_chat_conversation_remove_user(chat, nickname, _("was kicked"));
215 } 215 }
216 216
217 217
218 /*------------------------------------------------------------------------ 218 /*------------------------------------------------------------------------
219 * You were kicked from the GroupChat. 219 * You were kicked from the GroupChat.
220 * 220 *
221 * @param convo The Conversation object 221 * @param convo The Conversation object
222 * @param session The MXit session object 222 * @param session The MXit session object
223 * @param multimx The MultiMX room object 223 * @param multimx The MultiMX room object
224 */ 224 */
225 static void you_kicked(PurpleConversation* convo, struct MXitSession* session, struct multimx* multimx) 225 static void you_kicked(PurpleChatConversation* chat, struct MXitSession* session, struct multimx* multimx)
226 { 226 {
227 purple_debug_info(MXIT_PLUGIN_ID, "you_kicked\n"); 227 purple_debug_info(MXIT_PLUGIN_ID, "you_kicked\n");
228 228
229 purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "MXit", _("You have been kicked from this MultiMX."), PURPLE_MESSAGE_SYSTEM, time(NULL)); 229 purple_conversation_write_message(PURPLE_CONVERSATION(chat), "MXit", _("You have been kicked from this MultiMX."), PURPLE_MESSAGE_SYSTEM, time(NULL));
230 purple_chat_conversation_clear_users(PURPLE_CONV_CHAT(convo)); 230 purple_chat_conversation_clear_users(chat);
231 serv_got_chat_left(session->con, multimx->chatid); 231 serv_got_chat_left(session->con, multimx->chatid);
232 } 232 }
233 233
234 234
235 /*------------------------------------------------------------------------ 235 /*------------------------------------------------------------------------
236 * Update the full GroupChat member list. 236 * Update the full GroupChat member list.
237 * 237 *
238 * @param convo The Conversation object 238 * @param convo The Conversation object
239 * @param data The nicknames of the users in the room (separated by \n) 239 * @param data The nicknames of the users in the room (separated by \n)
240 */ 240 */
241 static void member_update(PurpleConversation* convo, char* data) 241 static void member_update(PurpleChatConversation* chat, char* data)
242 { 242 {
243 gchar** userlist; 243 gchar** userlist;
244 int i = 0; 244 int i = 0;
245 245
246 purple_debug_info(MXIT_PLUGIN_ID, "member_update: '%s'\n", data); 246 purple_debug_info(MXIT_PLUGIN_ID, "member_update: '%s'\n", data);
247 247
248 /* Clear list */ 248 /* Clear list */
249 purple_chat_conversation_clear_users(PURPLE_CONV_CHAT(convo)); 249 purple_chat_conversation_clear_users(chat);
250 250
251 /* Add each member */ 251 /* Add each member */
252 data = g_strstrip(data); /* string leading & trailing whitespace */ 252 data = g_strstrip(data); /* string leading & trailing whitespace */
253 userlist = g_strsplit(data, "\n", 0); /* tokenize string */ 253 userlist = g_strsplit(data, "\n", 0); /* tokenize string */
254 while (userlist[i] != NULL) { 254 while (userlist[i] != NULL) {
255 purple_debug_info(MXIT_PLUGIN_ID, "member_update - adding: '%s'\n", userlist[i]); 255 purple_debug_info(MXIT_PLUGIN_ID, "member_update - adding: '%s'\n", userlist[i]);
256 purple_chat_conversation_add_user(PURPLE_CONV_CHAT(convo), userlist[i], NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, FALSE); 256 purple_chat_conversation_add_user(chat, userlist[i], NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, FALSE);
257 i++; 257 i++;
258 } 258 }
259 g_strfreev(userlist); 259 g_strfreev(userlist);
260 } 260 }
261 261
375 } 375 }
376 else { 376 else {
377 /* Must be a service message */ 377 /* Must be a service message */
378 char* ofs; 378 char* ofs;
379 379
380 PurpleConversation* convo = purple_conversations_find_chat_with_account(multimx->roomname, mx->session->acc); 380 PurpleChatConversation* chat = purple_conversations_find_chat_with_account(multimx->roomname, mx->session->acc);
381 if (convo == NULL) { 381 if (chat == NULL) {
382 purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname); 382 purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname);
383 return; 383 return;
384 } 384 }
385 385
386 /* Determine if somebody has joined or left - update member-list */ 386 /* Determine if somebody has joined or left - update member-list */
387 if ((ofs = strstr(msg, " has joined")) != NULL) { 387 if ((ofs = strstr(msg, " has joined")) != NULL) {
388 /* Somebody has joined */ 388 /* Somebody has joined */
389 *ofs = '\0'; 389 *ofs = '\0';
390 member_added(convo, msg); 390 member_added(chat, msg);
391 mx->processed = TRUE; 391 mx->processed = TRUE;
392 } 392 }
393 else if ((ofs = strstr(msg, " has left")) != NULL) { 393 else if ((ofs = strstr(msg, " has left")) != NULL) {
394 /* Somebody has left */ 394 /* Somebody has left */
395 *ofs = '\0'; 395 *ofs = '\0';
396 member_removed(convo, msg); 396 member_removed(chat, msg);
397 mx->processed = TRUE; 397 mx->processed = TRUE;
398 } 398 }
399 else if ((ofs = strstr(msg, " has been kicked")) != NULL) { 399 else if ((ofs = strstr(msg, " has been kicked")) != NULL) {
400 /* Somebody has been kicked */ 400 /* Somebody has been kicked */
401 *ofs = '\0'; 401 *ofs = '\0';
402 member_kicked(convo, msg); 402 member_kicked(chat, msg);
403 mx->processed = TRUE; 403 mx->processed = TRUE;
404 } 404 }
405 else if (strcmp(msg, "You have been kicked.") == 0) { 405 else if (strcmp(msg, "You have been kicked.") == 0) {
406 /* You have been kicked */ 406 /* You have been kicked */
407 you_kicked(convo, mx->session, multimx); 407 you_kicked(chat, mx->session, multimx);
408 mx->processed = TRUE; 408 mx->processed = TRUE;
409 } 409 }
410 else if (g_str_has_prefix(msg, "The following users are in this MultiMx:") == TRUE) { 410 else if (g_str_has_prefix(msg, "The following users are in this MultiMx:") == TRUE) {
411 member_update(convo, msg + strlen("The following users are in this MultiMx:") + 1); 411 member_update(chat, msg + strlen("The following users are in this MultiMx:") + 1);
412 mx->processed = TRUE; 412 mx->processed = TRUE;
413 } 413 }
414 else { 414 else {
415 /* Display server message in chat window */ 415 /* Display server message in chat window */
416 serv_got_chat_in(mx->session->con, multimx->chatid, "MXit", PURPLE_MESSAGE_SYSTEM, msg, mx->timestamp); 416 serv_got_chat_in(mx->session->con, multimx->chatid, "MXit", PURPLE_MESSAGE_SYSTEM, msg, mx->timestamp);
542 void mxit_chat_invite(PurpleConnection *gc, int id, const char *msg, const char *username) 542 void mxit_chat_invite(PurpleConnection *gc, int id, const char *msg, const char *username)
543 { 543 {
544 struct MXitSession* session = purple_connection_get_protocol_data(gc); 544 struct MXitSession* session = purple_connection_get_protocol_data(gc);
545 struct multimx* multimx = NULL; 545 struct multimx* multimx = NULL;
546 PurpleBuddy* buddy; 546 PurpleBuddy* buddy;
547 PurpleConversation *convo; 547 PurpleChatConversation *chat;
548 char* tmp; 548 char* tmp;
549 549
550 purple_debug_info(MXIT_PLUGIN_ID, "Groupchat invite to '%s'\n", username); 550 purple_debug_info(MXIT_PLUGIN_ID, "Groupchat invite to '%s'\n", username);
551 551
552 /* Find matching MultiMX group */ 552 /* Find matching MultiMX group */
564 if (!buddy) { 564 if (!buddy) {
565 purple_debug_warning(MXIT_PLUGIN_ID, "mxit_chat_invite: unable to find the buddy '%s'\n", username); 565 purple_debug_warning(MXIT_PLUGIN_ID, "mxit_chat_invite: unable to find the buddy '%s'\n", username);
566 return; 566 return;
567 } 567 }
568 568
569 convo = purple_conversations_find_chat_with_account(multimx->roomname, session->acc); 569 chat = purple_conversations_find_chat_with_account(multimx->roomname, session->acc);
570 if (convo == NULL) { 570 if (chat == NULL) {
571 purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname); 571 purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname);
572 return; 572 return;
573 } 573 }
574 574
575 /* Display system message in chat window */ 575 /* Display system message in chat window */
576 tmp = g_strdup_printf("%s: %s", _("You have invited"), purple_buddy_get_alias(buddy)); 576 tmp = g_strdup_printf("%s: %s", _("You have invited"), purple_buddy_get_alias(buddy));
577 purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "MXit", tmp, PURPLE_MESSAGE_SYSTEM, time(NULL)); 577 purple_conversation_write_message(PURPLE_CONVERSATION(chat), "MXit", tmp, PURPLE_MESSAGE_SYSTEM, time(NULL));
578 g_free(tmp); 578 g_free(tmp);
579 } 579 }
580 580
581 581
582 /*------------------------------------------------------------------------ 582 /*------------------------------------------------------------------------

mercurial