Added add_contact/rename_contact queries
This commit is contained in:
parent
c4e3052db6
commit
f4dcc50946
53
interface.c
53
interface.c
@ -228,6 +228,8 @@ char *commands[] = {
|
||||
"view_video_thumb",
|
||||
"load_video",
|
||||
"view_video",
|
||||
"add_contact",
|
||||
"rename_contact",
|
||||
"show_license",
|
||||
0 };
|
||||
|
||||
@ -252,6 +254,8 @@ int commands_flags[] = {
|
||||
07,
|
||||
07,
|
||||
07,
|
||||
071,
|
||||
07,
|
||||
};
|
||||
|
||||
int get_complete_mode (void) {
|
||||
@ -607,6 +611,55 @@ void interpreter (char *line UU) {
|
||||
}
|
||||
int limit = next_token_int ();
|
||||
do_get_history (id, limit > 0 ? limit : 40);
|
||||
} else if (IS_WORD ("add_contact")) {
|
||||
int phone_len, first_name_len, last_name_len;
|
||||
char *phone, *first_name, *last_name;
|
||||
phone = next_token (&phone_len);
|
||||
if (!phone) {
|
||||
printf ("No phone number found\n");
|
||||
RET;
|
||||
}
|
||||
first_name = next_token (&first_name_len);
|
||||
if (!first_name_len) {
|
||||
printf ("No first name found\n");
|
||||
RET;
|
||||
}
|
||||
last_name = next_token (&last_name_len);
|
||||
if (!last_name_len) {
|
||||
printf ("No last name found\n");
|
||||
RET;
|
||||
}
|
||||
do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 0);
|
||||
} else if (IS_WORD ("rename_contact")) {
|
||||
int id = next_token_user ();
|
||||
if (id == NOT_FOUND) {
|
||||
printf ("Bad user\n");
|
||||
RET;
|
||||
}
|
||||
union user_chat *U = user_chat_get (id);
|
||||
if (!U) {
|
||||
printf ("No such user\n");
|
||||
RET;
|
||||
}
|
||||
if (!U->user.phone || !strlen (U->user.phone)) {
|
||||
printf ("User has no phone. Can not rename\n");
|
||||
RET;
|
||||
}
|
||||
int phone_len, first_name_len, last_name_len;
|
||||
char *phone, *first_name, *last_name;
|
||||
phone_len = strlen (U->user.phone);
|
||||
phone = U->user.phone;
|
||||
first_name = next_token (&first_name_len);
|
||||
if (!first_name_len) {
|
||||
printf ("No first name found\n");
|
||||
RET;
|
||||
}
|
||||
last_name = next_token (&last_name_len);
|
||||
if (!last_name_len) {
|
||||
printf ("No last name found\n");
|
||||
RET;
|
||||
}
|
||||
do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 1);
|
||||
} else if (IS_WORD ("help")) {
|
||||
//print_start ();
|
||||
push_color (COLOR_YELLOW);
|
||||
|
68
queries.c
68
queries.c
@ -1365,3 +1365,71 @@ void do_import_auth (int num) {
|
||||
send_query (DC_list[num], packet_ptr - packet_buffer, packet_buffer, &import_auth_methods, 0);
|
||||
net_loop (0, isn_export_auth_str);
|
||||
}
|
||||
|
||||
int add_contact_on_answer (struct query *q UU) {
|
||||
assert (fetch_int () == (int)CODE_contacts_imported_contacts);
|
||||
assert (fetch_int () == CODE_vector);
|
||||
int n = fetch_int ();
|
||||
if (n > 0) {
|
||||
logprintf ("Added successfully");
|
||||
} else {
|
||||
logprintf ("Not added");
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < n ; i++) {
|
||||
assert (fetch_int () == (int)CODE_imported_contact);
|
||||
fetch_int (); // uid
|
||||
fetch_long (); // client_id
|
||||
}
|
||||
assert (fetch_int () == CODE_vector);
|
||||
n = fetch_int ();
|
||||
for (i = 0; i < n ; i++) {
|
||||
struct user *U = fetch_alloc_user ();
|
||||
print_start ();
|
||||
push_color (COLOR_YELLOW);
|
||||
printf ("User #%d: ", U->id);
|
||||
print_user_name (U->id, (union user_chat *)U);
|
||||
push_color (COLOR_GREEN);
|
||||
printf (" (");
|
||||
printf ("%s", U->print_name);
|
||||
if (U->phone) {
|
||||
printf (" ");
|
||||
printf ("%s", U->phone);
|
||||
}
|
||||
printf (") ");
|
||||
pop_color ();
|
||||
if (U->status.online > 0) {
|
||||
printf ("online\n");
|
||||
} else {
|
||||
if (U->status.online < 0) {
|
||||
printf ("offline. Was online ");
|
||||
print_date_full (U->status.when);
|
||||
} else {
|
||||
printf ("offline permanent");
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
pop_color ();
|
||||
print_end ();
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct query_methods add_contact_methods = {
|
||||
.on_answer = add_contact_on_answer,
|
||||
};
|
||||
|
||||
void do_add_contact (const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, int force) {
|
||||
clear_packet ();
|
||||
out_int (CODE_contacts_import_contacts);
|
||||
out_int (CODE_vector);
|
||||
out_int (1);
|
||||
out_int (CODE_input_phone_contact);
|
||||
out_long (lrand48 () * (1ll << 32) + lrand48 ());
|
||||
out_cstring (phone, phone_len);
|
||||
out_cstring (first_name, first_name_len);
|
||||
out_cstring (last_name, last_name_len);
|
||||
out_int (force ? CODE_bool_true : CODE_bool_false);
|
||||
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &add_contact_methods, 0);
|
||||
}
|
||||
|
@ -90,5 +90,6 @@ int do_get_nearest_dc (void);
|
||||
int do_send_code_result_auth (const char *code, const char *first_name, const char *last_name);
|
||||
void do_import_auth (int num);
|
||||
void do_export_auth (int num);
|
||||
void do_add_contact (const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, int force);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user