static void skypeweb_join_chat(PurpleConnection *pc, GHashTable *data) { SkypeWebAccount *sa = purple_connection_get_protocol_data(pc); gchar *chatname; gchar *post; GString *url; PurpleChatConversation *chatconv; chatname = (gchar *)g_hash_table_lookup(data, "chatname"); if (chatname == NULL) { return; } chatconv = purple_conversations_find_chat_with_account(chatname, sa->account); if (chatconv != NULL && !purple_chat_conversation_has_left(chatconv)) { purple_conversation_present(PURPLE_CONVERSATION(chatconv)); return; } url = g_string_new("/v1/threads/"); g_string_append_printf(url, "%s", purple_url_encode(chatname)); g_string_append(url, "/members/"); g_string_append_printf(url, "8:%s", purple_url_encode(sa->username)); post = "{\"role\":\"User\"}"; skypeweb_post_or_get(sa, SKYPEWEB_METHOD_PUT | SKYPEWEB_METHOD_SSL, sa->messages_host, url->str, post, NULL, NULL, TRUE); g_string_free(url, TRUE); skypeweb_get_conversation_history(sa, chatname); skypeweb_get_thread_users(sa, chatname); chatconv = purple_serv_got_joined_chat(pc, g_str_hash(chatname), chatname); purple_conversation_set_data(PURPLE_CONVERSATION(chatconv), "chatname", g_strdup(chatname)); purple_conversation_present(PURPLE_CONVERSATION(chatconv)); }
void yahoo_process_chat_join(PurpleConnection *gc, struct yahoo_packet *pkt) { PurpleAccount *account = purple_connection_get_account(gc); YahooData *yd = purple_connection_get_protocol_data(gc); PurpleChatConversation *c = NULL; GSList *l; GList *members = NULL; GList *roomies = NULL; char *room = NULL; char *topic = NULL; if (pkt->status == -1) { /* We can't join */ struct yahoo_pair *pair = pkt->hash->data; gchar const *failed_to_join = _("Failed to join chat"); switch (atoi(pair->value)) { case 0xFFFFFFFA: /* -6 */ purple_notify_error(gc, NULL, failed_to_join, _("Unknown room"), purple_request_cpar_from_connection(gc)); break; case 0xFFFFFFF1: /* -15 */ purple_notify_error(gc, NULL, failed_to_join, _("Maybe the room is full"), purple_request_cpar_from_connection(gc)); break; case 0xFFFFFFDD: /* -35 */ purple_notify_error(gc, NULL, failed_to_join, _("Not available"), purple_request_cpar_from_connection(gc)); break; default: purple_notify_error(gc, NULL, failed_to_join, _("Unknown error. You may need to " "logout and wait five minutes before " "being able to rejoin a chatroom"), purple_request_cpar_from_connection(gc)); } return; } for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 104: g_free(room); room = yahoo_string_decode(gc, pair->value, TRUE); break; case 105: g_free(topic); topic = yahoo_string_decode(gc, pair->value, TRUE); break; case 128: /* some id */ break; case 108: /* number of joiners */ break; case 129: /* some other id */ break; case 130: /* some base64 or hash or something */ break; case 126: /* some negative number */ break; case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */ break; case 61: /*this looks similar to 130 */ break; /* the previous section was just room info. this next section is info about individual room members, (including us) */ case 109: /* the yahoo id */ if (g_utf8_validate(pair->value, -1, NULL)) { members = g_list_append(members, pair->value); } else { purple_debug_warning("yahoo", "yahoo_process_chat_join " "got non-UTF-8 string for key %d\n", pair->key); } break; case 110: /* age */ break; case 141: /* nickname */ break; case 142: /* location */ break; case 113: /* bitmask */ break; } } if (room && yd->chat_name && purple_utf8_strcasecmp(room, yd->chat_name)) yahoo_chat_leave(gc, room, purple_connection_get_display_name(gc), FALSE); c = purple_conversations_find_chat(gc, YAHOO_CHAT_ID); if (room && (!c || purple_chat_conversation_has_left(c)) && members && (members->next || !g_ascii_strcasecmp(members->data, purple_connection_get_display_name(gc)))) { GList *l; GList *flags = NULL; for (l = members; l; l = l->next) flags = g_list_prepend(flags, GINT_TO_POINTER(PURPLE_CHAT_USER_NONE)); if (c && purple_chat_conversation_has_left(c)) { /* this might be a hack, but oh well, it should nicely */ char *tmpmsg; purple_conversation_set_name(PURPLE_CONVERSATION(c), room); c = purple_serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) { purple_chat_conversation_set_topic(c, NULL, topic); /* Also print the topic to the backlog so that the captcha link is clickable */ purple_conversation_write_system_message(PURPLE_CONVERSATION(c), topic, 0); } yd->in_chat = 1; yd->chat_name = g_strdup(room); purple_chat_conversation_add_users(c, members, NULL, flags, FALSE); tmpmsg = g_strdup_printf(_("You are now chatting in %s."), room); purple_conversation_write_system_message(PURPLE_CONVERSATION(c), tmpmsg, 0); g_free(tmpmsg); } else { c = purple_serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) { purple_chat_conversation_set_topic(c, NULL, topic); /* Also print the topic to the backlog so that the captcha link is clickable */ purple_conversation_write_system_message(PURPLE_CONVERSATION(c), topic, 0); } yd->in_chat = 1; yd->chat_name = g_strdup(room); purple_chat_conversation_add_users(c, members, NULL, flags, FALSE); } g_list_free(flags); } else if (c) { if (topic) { const char *cur_topic = purple_chat_conversation_get_topic(c); if (cur_topic == NULL || strcmp(cur_topic, topic) != 0) purple_chat_conversation_set_topic(c, NULL, topic); } yahoo_chat_add_users(c, members); } if (purple_account_privacy_get_denied(account) && c) { PurpleConversationUiOps *ops = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(c)); for (l = purple_account_privacy_get_denied(account); l != NULL; l = l->next) { for (roomies = members; roomies; roomies = roomies->next) { if (!purple_utf8_strcasecmp((char *)l->data, roomies->data)) { purple_debug_info("yahoo", "Ignoring room member %s in room %s\n" , (char *)roomies->data, room ? room : ""); purple_chat_conversation_ignore(c,roomies->data); ops->chat_update_user(purple_chat_conversation_find_user(c, roomies->data)); } } } } g_list_free(roomies); g_list_free(members); g_free(room); g_free(topic); }