From d289aeb897a61263a511a57635d59bcb882095ff Mon Sep 17 00:00:00 2001 From: Vysheng Date: Wed, 23 Oct 2013 19:18:44 +0400 Subject: [PATCH] Mark messages as read after history query --- queries.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/queries.c b/queries.c index d73393e..bfcd33f 100644 --- a/queries.c +++ b/queries.c @@ -541,6 +541,39 @@ void do_send_text (union user_chat *U, char *file_name) { } } +int mark_read_on_receive (struct query *q UU) { + assert (fetch_int () == (int)CODE_messages_affected_history); + fetch_int (); // pts + fetch_int (); // seq + fetch_int (); // offset + return 0; +} + +struct query_methods mark_read_methods = { + .on_answer = mark_read_on_receive +}; + +void do_messages_mark_read (union user_chat *U, int max_id) { + clear_packet (); + out_int (CODE_messages_read_history); + if (U->id < 0) { + out_int (CODE_input_peer_chat); + out_int (-U->id); + } else { + if (U->user.access_hash) { + out_int (CODE_input_peer_foreign); + out_int (U->id); + out_long (U->user.access_hash); + } else { + out_int (CODE_input_peer_contact); + out_int (U->id); + } + } + out_int (max_id); + out_int (0); + send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &mark_read_methods, 0); +} + int get_history_on_answer (struct query *q UU) { static struct message *ML[10000]; int i; @@ -560,6 +593,7 @@ int get_history_on_answer (struct query *q UU) { } } if (n > 10000) { n = 10000; } + int sn = n; for (i = n - 1; i >= 0; i--) { print_message (ML[i]); } @@ -573,6 +607,9 @@ int get_history_on_answer (struct query *q UU) { for (i = 0; i < n; i++) { fetch_alloc_user (); } + if (sn > 0) { + do_messages_mark_read (q->extra, ML[0]->id); + } return 0; } @@ -600,7 +637,7 @@ void do_get_history (union user_chat *U, int limit) { out_int (0); out_int (0); out_int (limit); - send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &get_history_methods, 0); + send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &get_history_methods, U); } int get_dialogs_on_answer (struct query *q UU) {