From 8193960ccf0a36711feebd5ff025c9fcfc61baac Mon Sep 17 00:00:00 2001 From: vysheng Date: Sat, 9 Nov 2013 13:51:07 +0400 Subject: [PATCH] Added queries online/offline/contacts_search --- interface.c | 18 +++++++++++++++++ queries.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ queries.h | 2 ++ 3 files changed, 76 insertions(+) diff --git a/interface.c b/interface.c index 279280e..9e71d9e 100644 --- a/interface.c +++ b/interface.c @@ -258,6 +258,9 @@ char *commands[] = { "global_search", "chat_add_user", "chat_del_user", + "status_online", + "status_offline", + "contacts_search", 0 }; int commands_flags[] = { @@ -291,6 +294,9 @@ int commands_flags[] = { 07, 0724, 0724, + 07, + 07, + 07, }; int get_complete_mode (void) { @@ -789,6 +795,18 @@ void interpreter (char *line UU) { do_create_secret_chat (id); } else if (IS_WORD ("suggested_contacts")) { do_get_suggested (); + } else if (IS_WORD ("status_online")) { + do_update_status (1); + } else if (IS_WORD ("status_offline")) { + do_update_status (0); + } else if (IS_WORD ("contacts_search")) { + int t; + char *s = next_token (&t); + if (!s) { + printf ("Empty search query\n"); + RET; + } + do_contacts_search (100, s); } #undef IS_WORD #undef RET diff --git a/queries.c b/queries.c index bd7de57..e50bc44 100644 --- a/queries.c +++ b/queries.c @@ -1988,6 +1988,46 @@ void do_msg_search (peer_id_t id, int from, int to, int limit, const char *s) { } /* }}} */ +/* {{{ Contacts search */ +int contacts_search_on_answer (struct query *q UU) { + assert (fetch_int () == CODE_contacts_found); + assert (fetch_int () == CODE_vector); + int n = fetch_int (); + int i; + for (i = 0; i < n; i++) { + assert (fetch_int () == (int)CODE_contact_found); + fetch_int (); + } + assert (fetch_int () == CODE_vector); + n = fetch_int (); + print_start (); + push_color (COLOR_YELLOW); + for (i = 0; i < n; i++) { + struct user *U = fetch_alloc_user (); + printf ("User "); + push_color (COLOR_RED); + printf ("%s %s", U->first_name, U->last_name); + pop_color (); + printf (". Phone %s\n", U->phone); + } + pop_color (); + print_end (); + return 0; +} + +struct query_methods contacts_search_methods = { + .on_answer = contacts_search_on_answer +}; + +void do_contacts_search (int limit, const char *s) { + clear_packet (); + out_int (CODE_contacts_search); + out_string (s); + out_int (limit); + send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &contacts_search_methods, 0); +} +/* }}} */ + /* {{{ Encr accept */ int send_encr_accept_on_answer (struct query *q UU) { struct secret_chat *E = fetch_alloc_encrypted_chat (); @@ -2499,3 +2539,19 @@ void do_create_secret_chat (peer_id_t id) { do_create_encr_chat_request (&P->encr_chat); } /* }}} */ + +int update_status_on_answer (struct query *q UU) { + fetch_bool (); + return 0; +} + +struct query_methods update_status_methods = { + .on_answer = update_status_on_answer +}; + +void do_update_status (int online UU) { + clear_packet (); + out_int (CODE_account_update_status); + out_int (online ? CODE_bool_false : CODE_bool_true); + send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &update_status_methods, 0); +} diff --git a/queries.h b/queries.h index e651d66..ef727ab 100644 --- a/queries.h +++ b/queries.h @@ -105,5 +105,7 @@ void do_visualize_key (peer_id_t id); void do_create_keys_end (struct secret_chat *U); void do_add_user_to_chat (peer_id_t chat_id, peer_id_t id, int limit); void do_del_user_from_chat (peer_id_t chat_id, peer_id_t id); +void do_update_status (int online UU); +void do_contacts_search (int limit, const char *s); #endif