Commit 8193960c authored by vysheng's avatar vysheng

Added queries online/offline/contacts_search

parent c04a0f5d
......@@ -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
......
......@@ -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);
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment