diff --git a/telegram-base.c b/telegram-base.c index 1b575f3..1b1d4d2 100644 --- a/telegram-base.c +++ b/telegram-base.c @@ -544,8 +544,8 @@ PurpleConversation *chat_show (PurpleConnection *gc, int id) { PurpleConversation *convo = purple_find_chat(gc, id); if (! convo) { gchar *name = g_strdup_printf ("%d", id); - if (! g_hash_table_contains (conn->joining_chats, name)) { - g_hash_table_insert(conn->joining_chats, name, 0); + if (! g_hash_table_lookup (conn->joining_chats, name)) { + g_hash_table_insert (conn->joining_chats, name, (void *)1); tgl_do_get_chat_info (conn->TLS, TGL_MK_CHAT(id), 0, on_chat_get_info, NULL); } else { g_free(name); diff --git a/telegram-purple.c b/telegram-purple.c index e53a164..2b95215 100755 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -96,6 +96,23 @@ static char *format_img_full (int imgstore) { return g_strdup_printf ("%s",br, imgstore); } +static char *format_size (gint64 size) { + char *sizes[] = { + "b", + "Kb", + "Mb", + "Gb", + "Pb" + }; + int base = 0; + double s = (double) size; + while (s > 1024 && base < 4) { + s /= 1024; + ++ base; + } + return g_strdup_printf ("%.1f %s, ", s, sizes[base]); +} + static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) { assert (M && M->service); @@ -218,7 +235,7 @@ static char *format_print_name (struct tgl_state *TLS, tgl_peer_id_t id, const c } static char *format_document_desc (char *type, char *caption, gint64 size) { - char *s = g_format_size (size); + char *s = format_size (size); char *msg = g_strdup_printf ("[%s] %s %s", type, caption, s); g_free (s); return msg; @@ -768,7 +785,7 @@ static void tgprpl_tooltip_text (PurpleBuddy * buddy, PurpleNotifyUserInfo * inf tgl_peer_id_t *peer = purple_buddy_get_protocol_data(buddy); if (!peer) { - purple_notify_user_info_add_pair_plaintext(info, "Status", "Offline"); + purple_notify_user_info_add_pair (info, "Status", "Offline"); return; } tgl_peer_t *P = tgl_peer_get (get_conn_from_buddy (buddy)->TLS, *peer); @@ -776,8 +793,8 @@ static void tgprpl_tooltip_text (PurpleBuddy * buddy, PurpleNotifyUserInfo * inf warning ("tgprpl_tooltip_text: warning peer with id %d not found in tree.\n", peer->id); return; } - purple_notify_user_info_add_pair_plaintext (info, "Status", format_status(&P->user.status)); - purple_notify_user_info_add_pair_plaintext (info, "Last seen: ", format_time(P->user.status.when)); + purple_notify_user_info_add_pair (info, "Status", format_status(&P->user.status)); + purple_notify_user_info_add_pair (info, "Last seen: ", format_time(P->user.status.when)); } static GList *tgprpl_status_types (PurpleAccount * acct) { diff --git a/tgp-structs.c b/tgp-structs.c index 138e777..2588108 100644 --- a/tgp-structs.c +++ b/tgp-structs.c @@ -90,6 +90,16 @@ static void used_image_free (gpointer data) debug ("used_image: unref %d", id); } +static void queue_free_full (GQueue *queue, GDestroyNotify free_func) +{ + void *entry; + + while ((entry = g_queue_pop_head(queue))) { + free_func (entry); + } + g_queue_free (queue); +} + void used_images_add (connection_data *data, gint imgid) { data->used_images = g_list_append (data->used_images, GINT_TO_POINTER(imgid)); @@ -104,15 +114,15 @@ connection_data *connection_data_init (struct tgl_state *TLS, PurpleConnection * conn->pa = pa; conn->new_messages = g_queue_new (); conn->pending_reads = g_queue_new (); - conn->joining_chats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + conn->joining_chats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); return conn; } void *connection_data_free (connection_data *conn) { purple_timeout_remove(conn->timer); - g_queue_free_full (conn->pending_reads, pending_reads_free_cb); - g_queue_free_full (conn->new_messages, message_text_free); + queue_free_full (conn->pending_reads, pending_reads_free_cb); + queue_free_full (conn->new_messages, message_text_free); g_hash_table_destroy (conn->joining_chats); g_list_free_full (conn->used_images, used_image_free); tgl_free_all (conn->TLS);