diff --git a/interface.c b/interface.c index 412ab04..279280e 100644 --- a/interface.c +++ b/interface.c @@ -256,6 +256,8 @@ char *commands[] = { "create_secret_chat", "suggested_contacts", "global_search", + "chat_add_user", + "chat_del_user", 0 }; int commands_flags[] = { @@ -287,6 +289,8 @@ int commands_flags[] = { 071, 07, 07, + 0724, + 0724, }; int get_complete_mode (void) { @@ -658,6 +662,16 @@ void interpreter (char *line UU) { GET_PEER; int limit = next_token_int (); do_get_history (id, limit > 0 ? limit : 40); + } else if (IS_WORD ("chat_add_user")) { + GET_PEER_CHAT; + peer_id_t chat_id = id; + GET_PEER_USER; + do_add_user_to_chat (chat_id, id, 100); + } else if (IS_WORD ("chat_del_user")) { + GET_PEER_CHAT; + peer_id_t chat_id = id; + GET_PEER_USER; + do_del_user_from_chat (chat_id, id); } else if (IS_WORD ("add_contact")) { int phone_len, first_name_len, last_name_len; char *phone, *first_name, *last_name; diff --git a/interface.h b/interface.h index c9529a6..3764446 100644 --- a/interface.h +++ b/interface.h @@ -56,6 +56,7 @@ void push_color (const char *color); void print_start (void); void print_end (void); void print_date_full (long t); +void print_date (long t); void update_prompt (void); #endif diff --git a/mtproto-client.c b/mtproto-client.c index 2106e2d..5fddd67 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -728,7 +728,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { fetch_pts (); print_start (); push_color (COLOR_YELLOW); - printf ("%d messages marked as read\n", n); + print_date (time (0)); + printf (" %d messages marked as read\n", n); pop_color (); print_end (); } @@ -739,7 +740,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_t *U = user_chat_get (id); print_start (); push_color (COLOR_YELLOW); - printf ("User "); + print_date (time (0)); + printf (" User "); print_user_name (id, U); printf (" is typing....\n"); pop_color (); @@ -754,7 +756,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_t *U = user_chat_get (id); print_start (); push_color (COLOR_YELLOW); - printf ("User "); + print_date (time (0)); + printf (" User "); print_user_name (id, U); printf (" is typing in chat "); print_chat_name (chat_id, C); @@ -771,7 +774,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { fetch_user_status (&U->user.status); print_start (); push_color (COLOR_YELLOW); - printf ("User "); + print_date (time (0)); + printf (" User "); print_user_name (user_id, U); printf (" is now "); printf ("%s\n", (U->user.status.online > 0) ? "online" : "offline"); @@ -791,7 +795,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { struct user *U = &UC->user; print_start (); push_color (COLOR_YELLOW); - printf ("User "); + print_date (time (0)); + printf (" User "); print_user_name (user_id, UC); if (U->first_name) { free (U->first_name); } if (U->last_name) { free (U->last_name); } @@ -835,7 +840,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { print_start (); push_color (COLOR_YELLOW); - printf ("User "); + print_date (time (0)); + printf (" User "); print_user_name (user_id, UC); printf (" updated profile photo\n"); pop_color (); @@ -867,7 +873,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { int n = fetch_int (); print_start (); push_color (COLOR_YELLOW); - printf ("Restored %d messages\n", n); + print_date (time (0)); + printf (" Restored %d messages\n", n); pop_color (); print_end (); fetch_skip (n); @@ -880,7 +887,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { int n = fetch_int (); print_start (); push_color (COLOR_YELLOW); - printf ("Deleted %d messages\n", n); + print_date (time (0)); + printf (" Deleted %d messages\n", n); pop_color (); print_end (); fetch_skip (n); @@ -899,7 +907,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_t *C = user_chat_get (chat_id); print_start (); push_color (COLOR_YELLOW); - printf ("Chat "); + print_date (time (0)); + printf (" Chat "); print_chat_name (chat_id, C); printf (" changed list: now %d members\n", n); pop_color (); @@ -913,7 +922,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { fetch_int (); // date print_start (); push_color (COLOR_YELLOW); - printf ("User "); + print_date (time (0)); + printf (" User "); print_user_name (user_id, U); printf (" registered\n"); pop_color (); @@ -926,7 +936,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_t *U = user_chat_get (user_id); print_start (); push_color (COLOR_YELLOW); - printf ("Updated link with user "); + print_date (time (0)); + printf (" Updated link with user "); print_user_name (user_id, U); printf ("\n"); pop_color (); @@ -949,7 +960,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_t *U = user_chat_get (user_id); print_start (); push_color (COLOR_YELLOW); - printf ("User "); + print_date (time (0)); + printf (" User "); print_user_name (user_id, U); printf (" activated\n"); pop_color (); @@ -964,7 +976,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { char *location = fetch_str_dup (); print_start (); push_color (COLOR_YELLOW); - printf ("New autorization: device='%s' location='%s'\n", + print_date (time (0)); + printf (" New autorization: device='%s' location='%s'\n", s, location); pop_color (); print_end (); @@ -994,27 +1007,28 @@ void work_update (struct connection *c UU, long long msg_id UU) { struct secret_chat *E = fetch_alloc_encrypted_chat (); print_start (); push_color (COLOR_YELLOW); + print_date (time (0)); switch (E->state) { case sc_none: assert (0); break; case sc_waiting: - printf ("Encrypted chat "); + printf (" Encrypted chat "); print_encr_chat_name (E->id, (void *)E); printf (" is now in wait state\n"); break; case sc_request: - printf ("Encrypted chat "); + printf (" Encrypted chat "); print_encr_chat_name (E->id, (void *)E); printf (" is now in request state. Sending request ok\n"); break; case sc_ok: - printf ("Encrypted chat "); + printf (" Encrypted chat "); print_encr_chat_name (E->id, (void *)E); printf (" is now in ok state\n"); break; case sc_deleted: - printf ("Encrypted chat "); + printf (" Encrypted chat "); print_encr_chat_name (E->id, (void *)E); printf (" is now in deleted state\n"); break; @@ -1033,15 +1047,16 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_t *P = user_chat_get (id); print_start (); push_color (COLOR_YELLOW); + print_date (time (0)); if (P) { - printf ("User "); + printf (" User "); peer_id_t user_id = MK_USER (P->encr_chat.user_id); print_user_name (user_id, user_chat_get (user_id)); printf (" typing in secret chat "); print_encr_chat_name (id, P); printf ("\n"); } else { - printf ("Some user is typing in unknown secret chat\n"); + printf (" Some user is typing in unknown secret chat\n"); } pop_color (); print_end (); @@ -1067,7 +1082,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { } print_start (); push_color (COLOR_YELLOW); - printf ("Encrypted chat "); + print_date (time (0)); + printf (" Encrypted chat "); print_encr_chat_name_full (id, user_chat_get (id)); printf (": %d messages marked read \n", x); pop_color (); diff --git a/queries.c b/queries.c index 6bf88a3..f78e6bd 100644 --- a/queries.c +++ b/queries.c @@ -2438,6 +2438,50 @@ void do_get_suggested (void) { } /* }}} */ +/* {{{ Add user to chat */ + +struct query_methods add_user_to_chat_methods = { + .on_answer = fwd_msg_on_answer +}; + +void do_add_user_to_chat (peer_id_t chat_id, peer_id_t id, int limit) { + clear_packet (); + out_int (CODE_messages_add_chat_user); + out_int (get_peer_id (chat_id)); + + assert (get_peer_type (id) == PEER_USER); + peer_t *U = user_chat_get (id); + if (U && U->user.access_hash) { + out_int (CODE_input_user_foreign); + out_int (get_peer_id (id)); + out_long (U->user.access_hash); + } else { + out_int (CODE_input_user_contact); + out_int (get_peer_id (id)); + } + out_int (limit); + send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &add_user_to_chat_methods, 0); +} + +void do_del_user_from_chat (peer_id_t chat_id, peer_id_t id) { + clear_packet (); + out_int (CODE_messages_delete_chat_user); + out_int (get_peer_id (chat_id)); + + assert (get_peer_type (id) == PEER_USER); + peer_t *U = user_chat_get (id); + if (U && U->user.access_hash) { + out_int (CODE_input_user_foreign); + out_int (get_peer_id (id)); + out_long (U->user.access_hash); + } else { + out_int (CODE_input_user_contact); + out_int (get_peer_id (id)); + } + send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &add_user_to_chat_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); diff --git a/queries.h b/queries.h index 18f65d1..e651d66 100644 --- a/queries.h +++ b/queries.h @@ -103,5 +103,7 @@ void do_get_difference (void); void do_mark_read (peer_id_t id); 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); #endif