From ed2be5498b801d4b905947d69a428bd33ccaa01d Mon Sep 17 00:00:00 2001 From: Vysheng Date: Wed, 3 Sep 2014 17:05:48 +0400 Subject: [PATCH] Mark read messages from not peers --- binlog.c | 12 ++++++++++++ queries.c | 13 ++++--------- tgl.h | 1 + 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/binlog.c b/binlog.c index 67f9893..2577f6d 100644 --- a/binlog.c +++ b/binlog.c @@ -1128,6 +1128,12 @@ static int fetch_comb_binlog_msg_seq_update (void *extra) { tgl_state.seq ++; vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "seq %d=>%d\n", tgl_state.seq - 1, tgl_state.seq); + if (!(M->flags & FLAG_ENCRYPTED)) { + if (tgl_state.max_msg_id < M->id) { + tgl_state.max_msg_id = M->id; + } + } + if (tgl_state.callback.msg_receive) { tgl_state.callback.msg_receive (M); } @@ -1137,6 +1143,12 @@ static int fetch_comb_binlog_msg_seq_update (void *extra) { static int fetch_comb_binlog_msg_update (void *extra) { struct tgl_message *M = tgl_message_get (fetch_long ()); assert (M); + + if (!(M->flags & FLAG_ENCRYPTED)) { + if (tgl_state.max_msg_id < M->id) { + tgl_state.max_msg_id = M->id; + } + } if (tgl_state.callback.msg_receive) { tgl_state.callback.msg_receive (M); diff --git a/queries.c b/queries.c index 4d2f789..8aedc81 100644 --- a/queries.c +++ b/queries.c @@ -1104,21 +1104,16 @@ void tgl_do_messages_mark_read_encr (tgl_peer_id_t id, long long access_hash, in } void tgl_do_mark_read (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success), void *callback_extra) { + if (tgl_get_peer_type (id) == TGL_PEER_USER || tgl_get_peer_type (id) == TGL_PEER_CHAT) { + tgl_do_messages_mark_read (id, tgl_state.max_msg_id, callback, callback_extra); + return; + } tgl_peer_t *P = tgl_peer_get (id); if (!P) { vlogprintf (E_WARNING, "Unknown peer\n"); callback (callback_extra, 0); return; } - if (tgl_get_peer_type (id) == TGL_PEER_USER || tgl_get_peer_type (id) == TGL_PEER_CHAT) { - if (!P->last) { - vlogprintf (E_WARNING, "Unknown last peer message\n"); - callback (callback_extra, 0); - return; - } - tgl_do_messages_mark_read (id, P->last->id, callback, callback_extra); - return; - } assert (tgl_get_peer_type (id) == TGL_PEER_ENCR_CHAT); if (P->last) { tgl_do_messages_mark_read_encr (id, P->encr_chat.access_hash, P->last->date, callback, callback_extra); diff --git a/tgl.h b/tgl.h index a6b40bd..1088964 100644 --- a/tgl.h +++ b/tgl.h @@ -132,6 +132,7 @@ struct tgl_state { int verbosity; int unread_messages; int active_queries; + int max_msg_id; long long locks; struct tgl_dc *DC_list[TGL_MAX_DC_NUM];