added set_profile_name query
This commit is contained in:
parent
4604d4f374
commit
6132516d5a
@ -920,6 +920,11 @@ void do_set_profile_photo (int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
tgl_do_set_profile_photo (args[0].str, 0, 0);
|
||||
}
|
||||
|
||||
void do_set_profile_name (int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
assert (arg_num == 2);
|
||||
tgl_do_set_profile_name (args[0].str, args[1].str, print_user_gw, ev);
|
||||
}
|
||||
|
||||
void do_accept_secret_chat (int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
assert (arg_num == 1);
|
||||
tgl_do_accept_encr_chat_request (&args[0].P->encr_chat, 0, 0);
|
||||
@ -1071,6 +1076,7 @@ struct command commands[] = {
|
||||
{"create_group_chat", {ca_string, ca_user, ca_period, ca_none}, do_create_group_chat, "create_group_chat <name> <user>+\tCreates group chat with users"},
|
||||
{"chat_set_photo", {ca_chat, ca_file_name_end, ca_none}, do_chat_set_photo, "chat_set_photo <chat> <filename>\tSets chat photo. Photo will be cropped to square"},
|
||||
{"set_profile_photo", {ca_file_name_end, ca_none}, do_set_profile_photo, "set_profile_photo <filename>\tSets profile photo. Photo will be cropped to square"},
|
||||
{"set_profile_name", {ca_string, ca_string, ca_none}, do_set_profile_name, "set_profile_name <first-name> <last-name>\tSets profile name."},
|
||||
{"accept_secret_chat", {ca_secret_chat, ca_none}, do_accept_secret_chat, "accept_secret_chat <secret chat>\tAccepts secret chat. Only useful with -E option"},
|
||||
{"set_ttl", {ca_secret_chat, ca_number, ca_none}, do_set_ttl, "set_ttl <secret chat>\tSets secret chat ttl. Client itself ignores ttl"},
|
||||
{"export_card", {ca_none}, do_export_card, "export_card\tPrints card that can be imported by another user with import_card method"},
|
||||
|
1
loop.c
1
loop.c
@ -115,6 +115,7 @@ static void stdin_read_callback_all (int arg, short what, struct event *self) {
|
||||
//logprintf ("r = %d, size = %d, pos = %d, what = 0x%x, fd = %d\n", r, line_buffer_size, line_buffer_pos, (int)what, fd);
|
||||
if (r < 0) {
|
||||
perror ("read");
|
||||
delete_stdin_event = 1;
|
||||
break;
|
||||
}
|
||||
if (r == 0) {
|
||||
|
10
lua-tg.c
10
lua-tg.c
@ -464,6 +464,7 @@ enum lua_query_type {
|
||||
lq_send_photo,
|
||||
lq_chat_set_photo,
|
||||
lq_set_profile_photo,
|
||||
lq_set_profile_name,
|
||||
lq_send_video,
|
||||
lq_send_text,
|
||||
lq_fwd,
|
||||
@ -1041,6 +1042,14 @@ void lua_do_all (void) {
|
||||
free (s);
|
||||
p += 2;
|
||||
break;
|
||||
case lq_set_profile_name:
|
||||
s1 = lua_ptr[p + 1];
|
||||
s2 = lua_ptr[p + 1];
|
||||
tgl_do_set_profile_name (s1, s2, lua_user_cb, lua_ptr[p]);
|
||||
free (s1);
|
||||
free (s2);
|
||||
p += 3;
|
||||
break;
|
||||
case lq_create_secret_chat:
|
||||
tgl_do_create_secret_chat (((tgl_peer_t *)lua_ptr[p + 1])->id, lua_secret_chat_cb, lua_ptr[p]);
|
||||
p += 2;
|
||||
@ -1170,6 +1179,7 @@ struct lua_function functions[] = {
|
||||
{"msg_global_search", lq_global_search, { lfp_string, lfp_none }},
|
||||
{"mark_read", lq_mark_read, { lfp_peer, lfp_none }},
|
||||
{"set_profile_photo", lq_set_profile_photo, { lfp_string, lfp_none }},
|
||||
{"set_profile_name", lq_set_profile_name, { lfp_string, lfp_none }},
|
||||
{"create_secret_chat", lq_create_secret_chat, { lfp_user, lfp_none }},
|
||||
{"create_group_chat", lq_create_group_chat, { lfp_user, lfp_string, lfp_none }},
|
||||
{"delete_msg", lq_delete_msg, { lfp_msg, lfp_none }},
|
||||
|
130
queries.c
130
queries.c
@ -518,105 +518,6 @@ void tgl_do_phone_call (const char *user, const char *hash,void (*callback)(void
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Check phone */
|
||||
/*int check_phone_result;
|
||||
int cr_f (void) {
|
||||
return check_phone_result >= 0;
|
||||
}
|
||||
|
||||
int check_phone_on_answer (struct query *q UU) {
|
||||
assert (fetch_int () == (int)CODE_auth_checked_phone);
|
||||
check_phone_result = fetch_bool ();
|
||||
fetch_bool ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_phone_on_error (struct query *q UU, int error_code, int l, char *error) {
|
||||
int s = strlen ("PHONE_MIGRATE_");
|
||||
int s2 = strlen ("NETWORK_MIGRATE_");
|
||||
if (l >= s && !memcmp (error, "PHONE_MIGRATE_", s)) {
|
||||
int i = error[s] - '0';
|
||||
assert (DC_list[i]);
|
||||
|
||||
dc_working_num = i;
|
||||
tgl_state.DC_working = DC_list[i];
|
||||
write_auth_file ();
|
||||
|
||||
bl_do_set_working_dc (i);
|
||||
|
||||
check_phone_result = 1;
|
||||
} else if (l >= s2 && !memcmp (error, "NETWORK_MIGRATE_", s2)) {
|
||||
int i = error[s2] - '0';
|
||||
assert (DC_list[i]);
|
||||
dc_working_num = i;
|
||||
|
||||
bl_do_set_working_dc (i);
|
||||
|
||||
tgl_state.DC_working = DC_list[i];
|
||||
write_auth_file ();
|
||||
check_phone_result = 1;
|
||||
} else {
|
||||
logprintf ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
assert (0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct query_methods check_phone_methods = {
|
||||
.on_answer = check_phone_on_answer,
|
||||
.on_error = check_phone_on_error,
|
||||
.type = TYPE_TO_PARAM(auth_checked_phone)
|
||||
};
|
||||
|
||||
int tgl_do_auth_check_phone (const char *user) {
|
||||
suser = tstrdup (user);
|
||||
clear_packet ();
|
||||
out_int (CODE_auth_check_phone);
|
||||
out_string (user);
|
||||
check_phone_result = -1;
|
||||
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &check_phone_methods, 0);
|
||||
net_loop (0, cr_f);
|
||||
check_phone_result = -1;
|
||||
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &check_phone_methods, 0);
|
||||
net_loop (0, cr_f);
|
||||
return check_phone_result;
|
||||
}*/
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Nearest DC */
|
||||
/*int nearest_dc_num;
|
||||
int nr_f (void) {
|
||||
return nearest_dc_num >= 0;
|
||||
}
|
||||
|
||||
int nearest_dc_on_answer (struct query *q UU) {
|
||||
assert (fetch_int () == (int)CODE_nearest_dc);
|
||||
char *country = fetch_str_dup ();
|
||||
if (verbosity > 0) {
|
||||
logprintf ("Server thinks that you are in %s\n", country);
|
||||
}
|
||||
fetch_int (); // this_dc
|
||||
nearest_dc_num = fetch_int ();
|
||||
assert (nearest_dc_num >= 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct query_methods nearest_dc_methods = {
|
||||
.on_answer = nearest_dc_on_answer,
|
||||
.on_error = fail_on_error,
|
||||
.type = TYPE_TO_PARAM(nearest_dc)
|
||||
};
|
||||
|
||||
int tgl_do_get_nearest_dc (void) {
|
||||
clear_packet ();
|
||||
out_int (CODE_help_get_nearest_dc);
|
||||
nearest_dc_num = -1;
|
||||
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &nearest_dc_methods, 0);
|
||||
net_loop (0, nr_f);
|
||||
return nearest_dc_num;
|
||||
}*/
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Sign in / Sign up */
|
||||
static int sign_in_on_answer (struct query *q UU) {
|
||||
assert (fetch_int () == (int)CODE_auth_authorization);
|
||||
@ -1922,7 +1823,7 @@ void _tgl_do_send_photo (enum tgl_message_media_type type, tgl_peer_id_t to_id,
|
||||
f->part_num = 0;
|
||||
f->avatar = avatar;
|
||||
int tmp = ((size + 2999) / 3000);
|
||||
f->part_size = (1 << 10);
|
||||
f->part_size = (1 << 14);
|
||||
while (f->part_size < tmp) {
|
||||
f->part_size *= 2;
|
||||
}
|
||||
@ -1997,6 +1898,30 @@ void tgl_do_set_profile_photo (char *file_name, void (*callback)(void *callback_
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Profile name */
|
||||
|
||||
int set_profile_name_on_answer (struct query *q) {
|
||||
struct tgl_user *U = tglf_fetch_alloc_user ();
|
||||
if (q->callback) {
|
||||
((void (*)(void *, int, struct tgl_user *))q->callback) (q->callback_extra, 1, U);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct query_methods set_profile_name_methods = {
|
||||
.on_answer = set_profile_name_on_answer,
|
||||
.type = TYPE_TO_PARAM(user)
|
||||
};
|
||||
|
||||
void tgl_do_set_profile_name (char *first_name, char *last_name, void (*callback)(void *callback_extra, int success, struct tgl_user *U), void *callback_extra) {
|
||||
clear_packet ();
|
||||
out_int (CODE_account_update_profile);
|
||||
out_string (first_name);
|
||||
out_string (last_name);
|
||||
|
||||
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &set_profile_name_methods, 0, callback, callback_extra);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Forward */
|
||||
static int fwd_msg_on_answer (struct query *q UU) {
|
||||
@ -2435,6 +2360,7 @@ struct download {
|
||||
unsigned char *iv;
|
||||
unsigned char *key;
|
||||
int type;
|
||||
int refcnt;
|
||||
};
|
||||
|
||||
|
||||
@ -2502,11 +2428,14 @@ static int download_on_answer (struct query *q) {
|
||||
assert (write (D->fd, fetch_str (len), len) == len);
|
||||
}
|
||||
D->offset += len;
|
||||
D->refcnt --;
|
||||
if (D->offset < D->size) {
|
||||
load_next_part (D, q->callback, q->callback_extra);
|
||||
return 0;
|
||||
} else {
|
||||
if (!D->refcnt) {
|
||||
end_load (D, q->callback, q->callback_extra);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -2546,6 +2475,7 @@ static void load_next_part (struct download *D, void *callback, void *callback_e
|
||||
tgl_state.cur_downloaded_bytes += D->offset;
|
||||
//update_prompt ();
|
||||
}
|
||||
D->refcnt ++;
|
||||
clear_packet ();
|
||||
out_int (CODE_upload_get_file);
|
||||
if (!D->id) {
|
||||
|
1
tgl.h
1
tgl.h
@ -261,6 +261,7 @@ void tgl_do_get_dialog_list (void (*callback)(void *callback_extra, int success,
|
||||
void tgl_do_send_photo (enum tgl_message_media_type type, tgl_peer_id_t to_id, char *file_name, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
|
||||
void tgl_do_set_chat_photo (tgl_peer_id_t chat_id, char *file_name, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
|
||||
void tgl_do_set_profile_photo (char *file_name, void (*callback)(void *callback_extra, int success), void *callback_extra);
|
||||
void tgl_do_set_profile_name (char *first_name, char *last_name, void (*callback)(void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
|
||||
void tgl_do_forward_message (tgl_peer_id_t id, int n, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
|
||||
void tgl_do_rename_chat (tgl_peer_id_t id, char *name, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
|
||||
void tgl_do_get_chat_info (tgl_peer_id_t id, int offline_mode, void (*callback)(void *callback_extra, int success, struct tgl_chat *C), void *callback_extra);
|
||||
|
Loading…
Reference in New Issue
Block a user