From 5540b0bb8bac677123ff3ff030258eeae2ab7b59 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 7 Oct 2020 21:38:45 +0300 Subject: [PATCH] Fixed glitch for scheduled messages with elapsed date in channels. --- Telegram/SourceFiles/api/api_updates.cpp | 32 ++++++++++++------- .../data/data_scheduled_messages.cpp | 10 +++--- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 4322cf9355..28673ceacb 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -63,6 +63,22 @@ enum class DataIsLoadedResult { Ok = 3, }; +void ProcessScheduledMessageWithElapsedTime( + not_null session, + bool needToAdd, + const MTPDmessage &data) { + if (needToAdd && !data.is_from_scheduled()) { + // If we still need to add a new message, + // we should first check if this message is in + // the list of scheduled messages. + // This is necessary to correctly update the file reference. + // Note that when a message is scheduled until online + // while the recipient is already online, the server sends + // an ordinary new message with skipped "from_scheduled" flag. + session->data().scheduledMessages().checkEntitiesAndUpdate(data); + } +} + bool IsForceLogoutNotification(const MTPDupdateServiceNotification &data) { return qs(data.vtype()).startsWith(qstr("AUTH_KEY_DROP_")); } @@ -958,17 +974,7 @@ void Updates::applyUpdateNoPtsCheck(const MTPUpdate &update) { LOG(("Skipping message, because it is already in blocks!")); needToAdd = false; } - if (needToAdd && !data.is_from_scheduled()) { - // If we still need to add a new message, - // we should first check if this message is in - // the list of scheduled messages. - // This is necessary to correctly update the file reference. - // Note that when a message is scheduled until online - // while the recipient is already online, the server sends - // an ordinary new message with skipped "from_scheduled" flag. - _session->data().scheduledMessages().checkEntitiesAndUpdate( - data); - } + ProcessScheduledMessageWithElapsedTime(_session, needToAdd, data); } if (needToAdd) { _session->data().addNewMessage( @@ -1057,10 +1063,12 @@ void Updates::applyUpdateNoPtsCheck(const MTPUpdate &update) { auto &d = update.c_updateNewChannelMessage(); auto needToAdd = true; if (d.vmessage().type() == mtpc_message) { // index forwarded messages to links _overview - if (_session->data().checkEntitiesAndViewsUpdate(d.vmessage().c_message())) { // already in blocks + const auto &data = d.vmessage().c_message(); + if (_session->data().checkEntitiesAndViewsUpdate(data)) { // already in blocks LOG(("Skipping message, because it is already in blocks!")); needToAdd = false; } + ProcessScheduledMessageWithElapsedTime(_session, needToAdd, data); } if (needToAdd) { _session->data().addNewMessage( diff --git a/Telegram/SourceFiles/data/data_scheduled_messages.cpp b/Telegram/SourceFiles/data/data_scheduled_messages.cpp index 9970c811af..c77f95ca37 100644 --- a/Telegram/SourceFiles/data/data_scheduled_messages.cpp +++ b/Telegram/SourceFiles/data/data_scheduled_messages.cpp @@ -228,14 +228,12 @@ void ScheduledMessages::apply(const MTPDupdateNewScheduledMessage &update) { void ScheduledMessages::checkEntitiesAndUpdate(const MTPDmessage &data) { // When the user sends a message with a media scheduled until online - // while the recipient is already online, the server sends - // updateNewMessage to the client and the client calls this method. + // while the recipient is already online, or scheduled message + // is already due and is sent immediately, the server sends + // updateNewMessage or updateNewChannelMessage to the client + // and the client calls this method. const auto peer = peerFromMTP(data.vpeer_id()); - if (!peerIsUser(peer)) { - return; - } - const auto history = _session->data().historyLoaded(peer); if (!history) { return;