Esempio n. 1
0
void flist_get_profile(PurpleConnection *pc, const char *who) {
    FListAccount *fla;
    FListProfiles *flp;
    GString *link_str;
    gchar *link;
    FListCharacter *character;

    g_return_if_fail((fla = pc->proto_data));
    flp = _flist_profiles(fla);

    if(flp->character) g_free(flp->character);
    flp->character = NULL;
    if(flp->profile_info) purple_notify_user_info_destroy(flp->profile_info);
    flp->profile_info = NULL;
    if(flp->table) g_hash_table_destroy(flp->table);
    flp->table = NULL;
    if(flp->profile_request) {
        flist_web_request_cancel(flp->profile_request);
        flp->profile_request = NULL;
    }

    flp->character = g_strdup(who);
    flp->profile_info = purple_notify_user_info_new();

    link_str = g_string_new(NULL);
    g_string_append_printf(link_str, "http://www.f-list.net/c/%s", purple_url_encode(who));
    link = g_string_free(link_str, FALSE);

    character = flist_get_character(fla, who);
    if(!character) {
        purple_notify_user_info_add_pair(flp->profile_info, "Status", "Offline");
    } else {
        gchar *clean_message = flist_html_unescape_utf8(character->status_message);
        gchar *parsed_message = flist_bbcode_to_html(fla, NULL, clean_message);
        purple_notify_user_info_add_pair(flp->profile_info, "Status", flist_format_status(character->status));
        purple_notify_user_info_add_pair(flp->profile_info, "Gender", flist_format_gender(character->gender));
        purple_notify_user_info_add_pair(flp->profile_info, "Message", parsed_message);
        g_free(parsed_message);
        g_free(clean_message);
    }
    purple_notify_user_info_add_pair(flp->profile_info, "Link", link);
    purple_notify_userinfo(pc, flp->character, flp->profile_info, NULL, NULL);

    if(!character) {
        //The character is offline. There's nothing more we should do.
        g_free(flp->character); flp->character = NULL;
        purple_notify_user_info_destroy(flp->profile_info); flp->profile_info = NULL;
    } else if(flp->category_table) { /* Try to get the profile through the website API first. */
        GHashTable *args = flist_web_request_args(fla);
        g_hash_table_insert(args, "name", g_strdup(flp->character));
        flp->profile_request = flist_web_request(JSON_CHARACTER_INFO, args, NULL, TRUE, fla->secure, flist_get_profile_cb, fla);
        g_hash_table_destroy(args);
    } else { /* Try to get the profile through F-Chat. */
        JsonObject *json = json_object_new();
        json_object_set_string_member(json, "character", flp->character);
        flist_request(pc, "PRO", json);
        json_object_unref(json);
    }
    g_free(link);
}
Esempio n. 2
0
void flist_channel_show_message(FListAccount *fla, const gchar *channel) {
    PurpleConvChat *chat;
    gchar *to_print, *to_print_formatted;
    gboolean show_chat, show_ads;
    show_ads = flist_get_channel_show_ads(fla, channel);
    show_chat = flist_get_channel_show_chat(fla, channel);
    
    chat = PURPLE_CONV_CHAT(purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, channel, fla->pa));
    if(!chat) return;
    
    to_print = g_strdup_printf("We are currently [i]%s[/i] and [i]%s[/i].",
            show_chat ? "showing chat" : "[color=red]hiding chat[/color]",
            show_ads ? "showing ads" : "[color=red]hiding ads[/color]");
    to_print_formatted = flist_bbcode_to_html(fla, (PurpleConversation*) chat, to_print);
    purple_conv_chat_write(chat, "System", to_print_formatted, PURPLE_MESSAGE_SYSTEM, time(NULL));
    g_free(to_print);
    g_free(to_print_formatted);
}
Esempio n. 3
0
static void flist_sfc_confirm(PurpleConnection *pc, JsonObject *root) {
    FListAccount *fla = pc->proto_data;
    const gchar *moderator, *reporter;
    gchar *message, *escaped_message, *bbcode_message;
    gdouble timestamp;

    moderator = json_object_get_string_member(root, "moderator");
    reporter = json_object_get_string_member(root, "character");
    timestamp = json_object_get_double_member(root, "timestamp");

    g_return_if_fail(moderator);
    g_return_if_fail(reporter);

    message = g_strdup_printf("Alert Confirmed. [b]%s[/b] is handling [b]%s[/b]'s report.", moderator, reporter);
    escaped_message = purple_markup_escape_text(message, -1);
    bbcode_message = flist_bbcode_to_html(fla, NULL, escaped_message);
    serv_got_im(pc, GLOBAL_NAME, bbcode_message, PURPLE_MESSAGE_RECV, time(NULL));
    g_free(bbcode_message);
    g_free(escaped_message);
    g_free(message);
}