diff --git a/telegram-purple.c b/telegram-purple.c index 8281d10..db5ee12 100644 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -389,7 +389,7 @@ static void create_chat_link_done (struct tgl_state *TLS, void *extra, int succe } } -static void create_chat_link (PurpleBlistNode *node, gpointer data) { +static void export_chat_link_checked_gw (PurpleBlistNode *node, gpointer data) { PurpleChat *chat = (PurpleChat*)node; export_chat_link_checked (pbn_get_data (node)->TLS, purple_chat_get_name (chat)); } @@ -408,6 +408,13 @@ void export_chat_link_checked (struct tgl_state *TLS, const char *name) { tgl_do_export_chat_link (TLS, C->id, create_chat_link_done, C); } +static void leave_and_delete_chat_gw (PurpleBlistNode *node, gpointer data) { + PurpleChat *C = (PurpleChat *)node; + g_return_if_fail(tgp_chat_has_id (C)); + + leave_and_delete_chat (pbn_get_data (node)->TLS, tgl_peer_get (pbn_get_data (node)->TLS, tgp_chat_get_id (C))); +} + void leave_and_delete_chat (struct tgl_state *TLS, tgl_peer_t *P) { g_return_if_fail (P); if (P && P->chat.users_num) { @@ -436,29 +443,38 @@ void import_chat_link_checked (struct tgl_state *TLS, const char *link) { static GList* tgprpl_blist_node_menu (PurpleBlistNode *node) { debug ("tgprpl_blist_node_menu()"); - // orphaned buddy in "old" format that didn't migrate - if (! tgp_blist_buddy_has_id ((PurpleBuddy *)node)) { + // skip orphaned buddies in "old" format that didn't migrate and don't have an ID + if (PURPLE_BLIST_NODE_IS_BUDDY(node) && ! tgp_blist_buddy_has_id ((PurpleBuddy *)node)) { + return NULL; + } + + // chats that dont have a proper ID arent usable + if (PURPLE_BLIST_NODE_IS_CHAT(node) && ! tgp_chat_has_id ((PurpleChat *)node)) { return NULL; } GList* menu = NULL; if (PURPLE_BLIST_NODE_IS_BUDDY(node) && tgl_get_peer_type (tgp_blist_buddy_get_id ((PurpleBuddy *)node)) == TGL_PEER_USER) { + // Add encrypted chat option to the right click menu of all buddies - PurpleBuddy* buddy = (PurpleBuddy*)node; + PurpleBuddy* buddy = (PurpleBuddy *)node; PurpleMenuAction* action = purple_menu_action_new (_("Start secret chat..."), PURPLE_CALLBACK(start_secret_chat), buddy, NULL); menu = g_list_append (menu, (gpointer)action); } if (PURPLE_BLIST_NODE_IS_CHAT(node)) { + // Generate Public Link - PurpleMenuAction* action = purple_menu_action_new (_("Invite users by link..."), PURPLE_CALLBACK(create_chat_link), - NULL, NULL); + PurpleMenuAction* action = purple_menu_action_new (_("Invite users by link..."), + PURPLE_CALLBACK(export_chat_link_checked_gw), NULL, NULL); menu = g_list_append (menu, (gpointer)action); } + if (PURPLE_BLIST_NODE_IS_CHAT(node)) { + // Delete self from chat - PurpleMenuAction* action = purple_menu_action_new (_("Delete and exit..."), PURPLE_CALLBACK(leave_and_delete_chat), + PurpleMenuAction* action = purple_menu_action_new (_("Delete and exit..."), PURPLE_CALLBACK(leave_and_delete_chat_gw), NULL, NULL); menu = g_list_append (menu, (gpointer)action); } diff --git a/tgp-chat.c b/tgp-chat.c index 5651311..49361c0 100644 --- a/tgp-chat.c +++ b/tgp-chat.c @@ -41,6 +41,17 @@ void p2tgl_chat_update (struct tgl_state *TLS, PurpleChat *chat, tgl_peer_id_t i g_hash_table_replace (ht, g_strdup ("subject"), g_strdup (subject)); } +int tgp_chat_has_id (PurpleChat *C) { + const char *id = g_hash_table_lookup (purple_chat_get_components (C), "id"); + return id && *id; +} + +tgl_peer_id_t tgp_chat_get_id (PurpleChat *C) { + const char *id = g_hash_table_lookup (purple_chat_get_components (C), "id"); + assert (id && *id); + return TGL_MK_CHAT(atoi (id)); +} + void tgp_chat_on_loaded_chat_full (struct tgl_state *TLS, struct tgl_chat *C) { PurpleChat *PC = tgp_blist_chat_find (TLS, C->id); if (!PC) { diff --git a/tgp-chat.h b/tgp-chat.h index 917c990..75593a9 100644 --- a/tgp-chat.h +++ b/tgp-chat.h @@ -25,6 +25,9 @@ PurpleChat *p2tgl_chat_new (struct tgl_state *TLS, struct tgl_chat *chat); +tgl_peer_id_t tgp_chat_get_id (PurpleChat *C); +int tgp_chat_has_id (PurpleChat *C); + void tgp_chat_on_loaded_chat_full (struct tgl_state *TLS, struct tgl_chat *C); PurpleConversation *tgp_chat_show (struct tgl_state *TLS, struct tgl_chat *C); void tgp_chat_users_update (struct tgl_state *TLS, struct tgl_chat *C);