diff options
author | Vysheng <mail@vysheng.ru> | 2014-09-10 18:13:52 +0400 |
---|---|---|
committer | Vysheng <mail@vysheng.ru> | 2014-09-10 18:13:52 +0400 |
commit | ba10513786280290d973a4df1bebe634300ccc1e (patch) | |
tree | 64225db08b64c4152ae5ffe24c82f1bbc3c644b8 | |
parent | dd4e757ea58924fa81dd7c1e8b92eede57688639 (diff) |
del_contact query
-rw-r--r-- | interface.c | 4 | ||||
-rw-r--r-- | lua-tg.c | 5 | ||||
-rw-r--r-- | queries.c | 38 | ||||
-rw-r--r-- | tgl.h | 1 |
4 files changed, 48 insertions, 0 deletions
diff --git a/interface.c b/interface.c index 0369f87..bbcd0bc 100644 --- a/interface.c +++ b/interface.c @@ -379,6 +379,7 @@ struct command commands[] = { {"load_document_thumb", {ca_number, ca_none}}, {"view_document_thumb", {ca_number, ca_none}}, {"add_contact", {ca_string, ca_string, ca_string, ca_none}}, + {"del_contact", {ca_user, ca_none}}, {"rename_contact", {ca_user, ca_string, ca_string, ca_none}}, {"show_license", {ca_none}}, {"search", {ca_peer, ca_string_end}}, @@ -1339,6 +1340,9 @@ void interpreter (char *line UU) { RET; } tgl_do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 0, print_user_list_gw, 0); + } else if (IS_WORD ("del_contact")) { + GET_PEER_USER; + tgl_do_del_contact (id, 0, 0); } else if (IS_WORD ("send_contact")) { GET_PEER; int phone_len, first_name_len, last_name_len; @@ -474,6 +474,7 @@ enum lua_query_type { lq_chat_add_user, lq_chat_del_user, lq_add_contact, + lq_del_contact, lq_rename_contact, lq_search, lq_global_search, @@ -968,6 +969,9 @@ void lua_do_all (void) { free (s3); p += 4; break; + case lq_del_contact: + tgl_do_del_contact (((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]); + break; case lq_rename_contact: s1 = lua_ptr[p + 1]; s2 = lua_ptr[p + 2]; @@ -1108,6 +1112,7 @@ struct lua_function functions[] = { {"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }}, {"chat_del_user", lq_chat_del_user, { lfp_chat, lfp_user, lfp_none }}, {"add_contact", lq_add_contact, { lfp_string, lfp_string, lfp_string, lfp_none }}, + {"del_contact", lq_del_contact, { lfp_user, lfp_none }}, {"rename_contact", lq_rename_contact, { lfp_string, lfp_string, lfp_string, lfp_none }}, {"msg_search", lq_search, { lfp_peer, lfp_string, lfp_none }}, {"msg_global_search", lq_global_search, { lfp_string, lfp_none }}, @@ -2600,6 +2600,44 @@ void tgl_do_add_contact (const char *phone, int phone_len, const char *first_nam } /* }}} */ +/* {{{ Add contact */ +static int del_contact_on_answer (struct query *q UU) { + assert (skip_type_contacts_link (TYPE_TO_PARAM(contacts_link)) >= 0); + + if (q->callback) { + ((void (*)(void *, int))q->callback) (q->callback_extra, 1); + } + return 0; +} + +static struct query_methods del_contact_methods = { + .on_answer = del_contact_on_answer, + .type = TYPE_TO_PARAM(contacts_link) +}; + +void tgl_do_del_contact (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success), void *callback_extra) { + if (tgl_get_peer_type (id) != TGL_PEER_USER) { + if (callback) { + callback (callback_extra, 0); + } + return; + } + clear_packet (); + out_int (CODE_contacts_delete_contact); + + tgl_peer_t *U = tgl_peer_get (id); + if (U && U->user.access_hash) { + out_int (CODE_input_user_foreign); + out_int (tgl_get_peer_id (id)); + out_long (U->user.access_hash); + } else { + out_int (CODE_input_user_contact); + out_int (tgl_get_peer_id (id)); + } + tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &del_contact_methods, 0, callback, callback_extra); +} + /* }}} */ + /* {{{ Msg search */ static int msg_search_on_answer (struct query *q UU) { return get_history_on_answer (q); @@ -281,6 +281,7 @@ void tgl_do_export_card (void (*callback)(void *callback_extra, int success, int void tgl_do_import_card (int size, int *card, void (*callback)(void *callback_extra, int success, struct tgl_user *U), void *callback_extra); void tgl_do_send_contact (tgl_peer_id_t id, const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra); void tgl_do_forward_media (tgl_peer_id_t id, int n, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra); +void tgl_do_del_contact (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success), void *callback_extra); void tgl_do_visualize_key (tgl_peer_id_t id, unsigned char buf[16]); |