Add suggested contacts query

This commit is contained in:
vysheng 2013-11-07 02:46:17 +04:00
parent a9062675e7
commit 9361621c53
3 changed files with 47 additions and 0 deletions

View File

@ -254,6 +254,7 @@ char *commands[] = {
"mark_read",
"visualize_key",
"create_secret_chat",
"suggested_contacts",
0 };
int commands_flags[] = {
@ -283,6 +284,7 @@ int commands_flags[] = {
072,
075,
071,
07,
};
int get_complete_mode (void) {
@ -752,6 +754,8 @@ void interpreter (char *line UU) {
} else if (IS_WORD ("create_secret_chat")) {
GET_PEER;
do_create_secret_chat (id);
} else if (IS_WORD ("suggested_contacts")) {
do_get_suggested ();
}
#undef IS_WORD
#undef RET

View File

@ -2388,6 +2388,48 @@ void do_visualize_key (peer_id_t id) {
}
/* }}} */
/* {{{ Get suggested */
int get_suggested_on_answer (struct query *q UU) {
assert (fetch_int () == CODE_contacts_suggested);
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
logprintf ("n = %d\n", n);
assert (n <= 200);
int l[400];
int i;
for (i = 0; i < n; i++) {
assert (fetch_int () == CODE_contact_suggested);
l[2 * i] = fetch_int ();
l[2 * i + 1] = fetch_int ();
}
assert (fetch_int () == CODE_vector);
int m = fetch_int ();
assert (n == m);
print_start ();
push_color (COLOR_YELLOW);
for (i = 0; i < m; i++) {
peer_t *U = (void *)fetch_alloc_user ();
assert (get_peer_id (U->id) == l[2 * i]);
print_user_name (U->id, U);
printf ("phone %s: %d mutual friends\n", U->user.phone, l[2 * i + 1]);
}
pop_color ();
print_end ();
return 0;
}
struct query_methods get_suggested_methods = {
.on_answer = get_suggested_on_answer
};
void do_get_suggested (void) {
clear_packet ();
out_int (CODE_contacts_get_suggested);
out_int (100);
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &get_suggested_methods, 0);
}
/* }}} */
/* {{{ Create secret chat */
char *create_print_name (peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);

View File

@ -83,6 +83,7 @@ void do_rename_chat (peer_id_t id, char *name);
void do_load_encr_video (struct encr_video *V, int next);
void do_create_encr_chat_request (struct secret_chat *E);
void do_create_secret_chat (peer_id_t id);
void do_get_suggested (void);
struct photo;
struct video;