Commit a6c00cde authored by vvaltman's avatar vvaltman

Added support for layer 18

parent d564c653
......@@ -326,6 +326,20 @@ static int fetch_comb_binlog_user_set_name (void *extra) {
return 0;
}
static int fetch_comb_binlog_user_set_username (void *extra) {
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (id);
assert (U);
if (U->user.username) { tfree_str (U->user.username); }
U->user.username = fetch_str_dup ();
if (tgl_state.callback.user_update) {
tgl_state.callback.user_update ((void *)U, TGL_UPDATE_USERNAME);
}
return 0;
}
static int fetch_comb_binlog_user_set_photo (void *extra) {
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (id);
......@@ -1270,6 +1284,7 @@ static void replay_log_event (void) {
FETCH_COMBINATOR_FUNCTION (binlog_user_set_full_photo)
FETCH_COMBINATOR_FUNCTION (binlog_user_set_blocked)
FETCH_COMBINATOR_FUNCTION (binlog_user_set_name)
FETCH_COMBINATOR_FUNCTION (binlog_user_set_username)
FETCH_COMBINATOR_FUNCTION (binlog_user_set_photo)
FETCH_COMBINATOR_FUNCTION (binlog_user_set_real_name)
......@@ -1567,6 +1582,18 @@ void bl_do_user_set_name (struct tgl_user *U, const char *f, int fl, const char
add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer));
}
void bl_do_user_set_username (struct tgl_user *U, const char *f, int l) {
if ((U->username && (int)strlen (U->username) == l && !strncmp (U->username, f, l)) ||
(!l && !U->username)) {
return;
}
clear_packet ();
out_int (CODE_binlog_user_set_username);
out_int (tgl_get_peer_id (U->id));
out_cstring (f, l);
add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer));
}
void bl_do_user_set_access_hash (struct tgl_user *U, long long access_token) {
if (U->access_hash == access_token) { return; }
int *ev = alloc_log_event (16);
......
......@@ -32,6 +32,7 @@ void bl_do_user_add (int id, const char *f, int fl, const char *l, int ll, long
void bl_do_user_delete (struct tgl_user *U);
void bl_do_set_user_profile_photo (struct tgl_user *U, long long photo_id, struct tgl_file_location *big, struct tgl_file_location *small);
void bl_do_user_set_name (struct tgl_user *U, const char *f, int fl, const char *l, int ll);
void bl_do_user_set_username (struct tgl_user *U, const char *f, int l);
void bl_do_user_set_access_hash (struct tgl_user *U, long long access_token);
void bl_do_user_set_phone (struct tgl_user *U, const char *p, int pl);
void bl_do_user_set_friend (struct tgl_user *U, int friend);
......
......@@ -27,6 +27,7 @@ binlog.userSetBlocked id:int blocked:int = binlog.Update;
binlog.userSetRealName id:int real_first_name:string real_last_name:string = binlog.Update;
binlog.userSetName id:int first_name:string last_name:string = binlog.Update;
binlog.userSetPhoto id:int photo:UserProfilePhoto = binlog.Update;
binlog.userSetUsername id:int username:string = binlog.Update;
binlog.encrChatDelete id:int = binlog.Update;
binlog.encrChatRequested id:int hash:long date:int admin:int user:int key:64*[int] nonce:64*[int] = binlog.Update;
......
......@@ -925,6 +925,16 @@ void do_set_profile_name (int arg_num, struct arg args[], struct in_ev *ev) {
tgl_do_set_profile_name (args[0].str, args[1].str, print_user_gw, ev);
}
void do_set_username (int arg_num, struct arg args[], struct in_ev *ev) {
assert (arg_num == 1);
tgl_do_set_username (args[0].str, print_user_gw, ev);
}
void do_contact_search (int arg_num, struct arg args[], struct in_ev *ev) {
assert (arg_num == 2);
tgl_do_contact_search (args[0].str, args[1].num == NOT_FOUND ? args[1].num : 10, print_user_list_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);
......@@ -1061,6 +1071,7 @@ struct command commands[] = {
{"show_license", {ca_none}, do_show_license, "show_license\tPrints contents of GPL license"},
{"search", {ca_peer | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_string_end}, do_search, "search [peer] [limit] [from] [to] [offset] pattern\tSearch for pattern in messages from date from to date to (unixtime) in messages with peer (if peer not present, in all messages)"},
{"mark_read", {ca_peer, ca_none}, do_mark_read, "mark_read <peer>\tMarks messages with peer as read"},
{"contact_search", {ca_string, ca_number | ca_optional, ca_none}, do_contact_search, "contact_search username [limit]\tSearches contacts by username"},
{"visualize_key", {ca_secret_chat, ca_none}, do_visualize_key, "visualize_key <secret chat>\tPrints visualization of encryption key (first 16 bytes sha1 of it in fact}"},
{"create_secret_chat", {ca_user, ca_none}, do_create_secret_chat, "create_secret_chat <user>\tStarts creation of secret chat"},
{"chat_add_user", {ca_chat, ca_user, ca_number | ca_optional, ca_none}, do_chat_add_user, "chat_add_user <chat> <user> [msgs-to-forward]\tAdds user to chat. Sends him last msgs-to-forward message from this chat. Default 100"},
......@@ -1077,6 +1088,7 @@ struct command commands[] = {
{"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."},
{"set_username", {ca_string, ca_none}, do_set_username, "set_username <name>\tSets username."},
{"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"},
......@@ -1460,6 +1472,9 @@ void print_user_info_gw (void *extra, int success, struct tgl_user *U) {
mpush_color (ev, COLOR_YELLOW);
mprintf (ev, "User ");
print_user_name (ev, U->id, C);
if (U->username) {
mprintf (ev, " @%s", U->username);
}
mprintf (ev, " (#%d):\n", tgl_get_peer_id (U->id));
mprintf (ev, "\treal name: %s %s\n", U->real_first_name, U->real_last_name);
mprintf (ev, "\tphone: %s\n", U->phone);
......@@ -1766,6 +1781,9 @@ void print_peer_updates (struct in_ev *ev, int flags) {
if (flags & TGL_UPDATE_ACCESS_HASH) {
mprintf (ev, " access_hash");
}
if (flags & TGL_UPDATE_USERNAME) {
mprintf (ev, " username");
}
}
void user_update_gw (struct tgl_user *U, unsigned flags) {
......
......@@ -184,6 +184,9 @@ void push_update_types (unsigned flags) {
if (flags & TGL_UPDATE_ACCESS_HASH) {
lua_add_string_field_arr (cc++, "access_hash");
}
if (flags & TGL_UPDATE_USERNAME) {
lua_add_string_field_arr (cc++, "username");
}
}
......
......@@ -337,7 +337,8 @@ static void out_random (int n) {
int allow_send_linux_version;
void tgl_do_insert_header (void) {
out_int (CODE_invoke_with_layer17);
out_int (CODE_invoke_with_layer18);
//out_int (0x50858a19);
out_int (CODE_init_connection);
out_int (TG_APP_ID);
if (allow_send_linux_version) {
......@@ -1921,6 +1922,55 @@ void tgl_do_set_profile_name (char *first_name, char *last_name, void (*callback
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &set_profile_name_methods, 0, callback, callback_extra);
}
void tgl_do_set_username (char *name, void (*callback)(void *callback_extra, int success, struct tgl_user *U), void *callback_extra) {
clear_packet ();
out_int (CODE_account_update_username);
out_string (name);
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &set_profile_name_methods, 0, callback, callback_extra);
}
/* }}} */
/* {{{ Contacts search */
int contact_search_on_answer (struct query *q) {
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 ();
struct tgl_user **UL = talloc (sizeof (void *) * n);
for (i = 0; i < n; i++) {
UL[i] = tglf_fetch_alloc_user ();
}
if (q->callback) {
((void (*)(void *, int, int, struct tgl_user **))q->callback) (q->callback_extra, 1, n, UL);
}
tfree (UL, sizeof (void *) * n);
return 0;
}
static struct query_methods contact_search_methods = {
.on_answer = contact_search_on_answer,
.type = TYPE_TO_PARAM(contacts_found)
};
void tgl_do_contact_search (char *name, int limit, void (*callback)(void *callback_extra, int success, int cnt, struct tgl_user *U[]), void *callback_extra) {
clear_packet ();
out_int (CODE_contacts_search);
out_string (name);
out_int (limit);
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &contact_search_methods, 0, callback, callback_extra);
}
/* }}} */
/* {{{ Forward */
......
scheme17.tl
\ No newline at end of file
scheme18.tl
\ No newline at end of file
This diff is collapsed.
......@@ -218,9 +218,13 @@ int tglf_fetch_user (struct tgl_user *U) {
int l2 = prefetch_strlen ();
assert (l2 >= 0);
char *s2 = fetch_str (l2);
int l3 = prefetch_strlen ();
char *s3 = fetch_str (l3);
if (x == CODE_user_deleted && !(U->flags & FLAG_DELETED)) {
bl_do_user_add (tgl_get_peer_id (U->id), s1, l1, s2, l2, 0, 0, 0, 0);
bl_do_user_set_username (U, s3, l3);
bl_do_user_delete (U);
}
if (x != CODE_user_deleted) {
......@@ -236,6 +240,7 @@ int tglf_fetch_user (struct tgl_user *U) {
phone = fetch_str (phone_len);
}
bl_do_user_add (tgl_get_peer_id (U->id), s1, l1, s2, l2, access_hash, phone, phone_len, x == CODE_user_contact);
bl_do_user_set_username (U, s3, l3);
assert (tglf_fetch_user_photo (U) >= 0);
assert (tglf_fetch_user_status (&U->status) >= 0);
......@@ -250,6 +255,10 @@ int tglf_fetch_user (struct tgl_user *U) {
char *s2 = fetch_str (l2);
bl_do_user_set_name (U, s1, l1, s2, l2);
int l3 = prefetch_strlen ();
char *s3 = fetch_str (l3);
bl_do_user_set_username (U, s3, l3);
if (x == CODE_user_deleted && !(U->flags & FLAG_DELETED)) {
bl_do_user_delete (U);
......
......@@ -254,6 +254,7 @@ struct tgl_user {
int blocked;
char *real_first_name;
char *real_last_name;
char *username;
};
struct tgl_chat_user {
......
......@@ -61,6 +61,7 @@ struct tgl_dc;
#define TGL_UPDATE_ADMIN 4096
#define TGL_UPDATE_MEMBERS 8192
#define TGL_UPDATE_ACCESS_HASH 16384
#define TGL_UPDATE_USERNAME (1 << 15)
struct tgl_allocator {
void *(*alloc)(size_t size);
......@@ -262,6 +263,7 @@ void tgl_do_send_photo (enum tgl_message_media_type type, tgl_peer_id_t to_id, c
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_set_username (char *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);
......@@ -276,7 +278,7 @@ void tgl_do_load_encr_video (struct tgl_encr_video *V, void (*callback)(void *ca
void tgl_do_export_auth (int num, void (*callback) (void *callback_extra, int success), void *callback_extra);
void tgl_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, void (*callback)(void *callback_extra, int success, int size, struct tgl_user *users[]), void *callback_extra);
void tgl_do_msg_search (tgl_peer_id_t id, int from, int to, int limit, int offset, const char *s, void (*callback)(void *callback_extra, int success, int size, struct tgl_message *list[]), void *callback_extra);
void tgl_do_contacts_search (int limit, const char *s, void (*callback) (void *callback_extra, int success, int size, struct tgl_user *users[]), void *callback_extra);
//void tgl_do_contacts_search (int limit, const char *s, void (*callback) (void *callback_extra, int success, int size, struct tgl_user *users[]), void *callback_extra);
void tgl_do_create_encr_chat_request (int user_id, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
void tgl_do_create_secret_chat (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
void tgl_do_accept_encr_chat_request (struct tgl_secret_chat *E, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
......@@ -297,6 +299,7 @@ void tgl_do_forward_media (tgl_peer_id_t id, int n, void (*callback)(void *callb
void tgl_do_del_contact (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success), void *callback_extra);
void tgl_do_set_encr_chat_ttl (struct tgl_secret_chat *E, int ttl, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
void tgl_do_send_location(tgl_peer_id_t id, double latitude, double longitude, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
void tgl_do_contact_search (char *name, int limit, void (*callback)(void *callback_extra, int success, int cnt, struct tgl_user *U[]), void *callback_extra);
void tgl_do_visualize_key (tgl_peer_id_t id, unsigned char buf[16]);
......
......@@ -152,9 +152,13 @@ void tglu_work_update (struct connection *c, long long msg_id) {
char *l = fetch_str (l2);
struct tgl_user *U = &UC->user;
bl_do_user_set_real_name (U, f, l1, l, l2);
int l3 = prefetch_strlen ();
f = fetch_str (l3);
bl_do_user_set_username (U, f, l3);
} else {
fetch_skip_str ();
fetch_skip_str ();
fetch_skip_str ();
}
}
break;
......@@ -404,6 +408,17 @@ void tglu_work_update (struct connection *c, long long msg_id) {
assert (skip_type_any (TYPE_TO_PARAM (peer_notify_settings)) >= 0);
}
break;
case CODE_update_service_notification:
{
int l1 = prefetch_strlen ();
char *type = fetch_str (l1);
int l2 = prefetch_strlen ();
char *message = fetch_str (l2);
skip_type_message_media (TYPE_TO_PARAM(message_media));
fetch_bool ();
vlogprintf (E_ERROR, "Notification %.*s: %.*s\n", l1, type, l2, message);
}
break;
default:
vlogprintf (E_ERROR, "Unknown update type %08x\n", op);
;
......
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