Support leaving and deleting chats

This commit is contained in:
mjentsch 2015-09-06 17:07:58 +02:00
parent 791b048eb1
commit abd316a659
5 changed files with 54 additions and 7 deletions

View file

@ -132,6 +132,13 @@
action:@selector(addUserByLink)
keyEquivalent:@""
tag:0];
[menu addItemWithTitle:@"Delete and exit..."
target:self
action:@selector(deleteAndExitChat)
keyEquivalent:@""
tag:0];
return menu;
}
@ -144,6 +151,18 @@
}
}
- (void)deleteAndExitChat
{
connection_data *conn = purple_connection_get_protocol_data (purple_account_get_connection(account));
AIChat *chat = adium.interfaceController.activeChat;
if (chat) {
PurpleChat *purpleChat = purple_blist_find_chat (conn->pa, [chat.name UTF8String]);
if (purpleChat) {
leave_and_delete_chat ((PurpleBlistNode *)purpleChat, NULL);
}
}
}
#pragma mark File transfer
- (BOOL)canSendOfflineMessageToContact:(AIListContact *)inContact
{

View file

@ -510,6 +510,19 @@ 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);
}
void leave_and_delete_chat (PurpleBlistNode *node, gpointer data) {
PurpleChat *PC = (PurpleChat*)node;
connection_data *conn = purple_connection_get_protocol_data (
purple_account_get_connection (purple_chat_get_account (PC)));
tgl_peer_t *P = tgl_peer_get (conn->TLS, p2tgl_chat_get_id (PC));
if (P && P->chat.users_num) {
tgl_do_del_user_from_chat (conn->TLS, P->id, TGL_MK_USER(conn->TLS->our_id),
tgp_notify_on_error_gw, NULL);
}
purple_blist_remove_chat (PC);
}
static void import_chat_link_done (struct tgl_state *TLS, void *extra, int success) {
if (! success) {
tgp_notify_on_error_gw (TLS, NULL, success);
@ -529,16 +542,21 @@ static GList* tgprpl_blist_node_menu (PurpleBlistNode *node) {
if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
// Add encrypted chat option to the right click menu of all buddies
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);
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);
menu = g_list_append(menu, (gpointer)action);
PurpleMenuAction* action = purple_menu_action_new ("Invite users by link ...",
PURPLE_CALLBACK(create_chat_link), 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), NULL, NULL);
menu = g_list_append (menu, (gpointer)action);
}
return menu;
}

View file

@ -66,5 +66,6 @@ extern const char *config_dir;
extern PurplePlugin *_telegram_protocol;
void export_chat_link_checked (struct tgl_state *TLS, const char *name);
void import_chat_link_checked (struct tgl_state *TLS, const char *link);
void leave_and_delete_chat (PurpleBlistNode *node, gpointer data);
#endif

View file

@ -299,6 +299,14 @@ PurpleChat *p2tgl_chat_new (struct tgl_state *TLS, struct tgl_chat *chat) {
return C;
}
tgl_chat_id_t p2tgl_chat_get_id (PurpleChat *PC) {
char *name = g_hash_table_lookup (purple_chat_get_components (PC), "id");
if (! atoi (name)) {
warning ("p2tgl_chat_id_get: no id found in chat %s", PC->alias);
}
return TGL_MK_CHAT(atoi (name));
}
PurpleChat *p2tgl_chat_find (struct tgl_state *TLS, tgl_peer_id_t id) {
char *name = p2tgl_strdup_id(id);
PurpleChat *c = blist_find_chat_by_hasht_cond(tg_get_conn(TLS), hasht_cmp_id, name);

View file

@ -53,6 +53,7 @@ void p2tgl_got_typing (struct tgl_state *TLS, tgl_peer_id_t name, int timeout);
PurpleBuddy *p2tgl_buddy_find (struct tgl_state *TLS, tgl_peer_id_t user);
PurpleBuddy *p2tgl_buddy_new (struct tgl_state *TLS, tgl_peer_t *user);
tgl_chat_id_t p2tgl_chat_get_id (PurpleChat *PC);
void p2tgl_buddy_add_data (struct tgl_state *TLS, tgl_peer_id_t user, void *data);
void p2tgl_prpl_got_user_status (struct tgl_state *TLS, tgl_peer_id_t user, struct tgl_user_status *status);
void p2tgl_prpl_got_set_status_mobile (struct tgl_state *TLS, tgl_peer_id_t user);