From 6eaeb306d660c4d8de380b182149fd2bc466bea1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 8 Nov 2021 12:32:25 +0400 Subject: [PATCH] Add a RequestDependentMessageData method. --- .../SourceFiles/history/history_message.cpp | 37 +++++++++++-------- .../SourceFiles/history/history_message.h | 6 ++- .../SourceFiles/history/history_service.cpp | 11 ++---- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 19a422d725..858cf887a0 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -347,15 +347,23 @@ void FastShareMessage(not_null item) { .navigation = App::wnd()->sessionController() })); } -Fn HistoryDependentItemCallback( - not_null item) { - const auto session = &item->history()->session(); - const auto dependent = item->fullId(); - return [=](ChannelData *channel, MsgId msgId) { - if (const auto item = session->data().message(dependent)) { - item->updateDependencyItem(); - } - }; +void RequestDependentMessageData( + not_null item, + PeerId peerId, + MsgId msgId) { + const auto fullId = item->fullId(); + const auto history = item->history(); + const auto session = &history->session(); + history->session().api().requestMessageData( + (peerIsChannel(peerId) + ? history->owner().channel(peerToChannel(peerId)).get() + : history->peer->asChannel()), + msgId, + [=](ChannelData *channel, MsgId msgId) { + if (const auto item = session->data().message(fullId)) { + item->updateDependencyItem(); + } + }); } MessageFlags NewMessageFlags(not_null peer) { @@ -1094,13 +1102,10 @@ void HistoryMessage::createComponents(CreateConfig &&config) { reply->replyToMsgId = config.replyTo; reply->replyToMsgTop = isScheduled() ? 0 : config.replyToTop; if (!reply->updateData(this)) { - history()->session().api().requestMessageData( - (peerIsChannel(reply->replyToPeerId) - ? history()->owner().channel( - peerToChannel(reply->replyToPeerId)).get() - : history()->peer->asChannel()), - reply->replyToMsgId, - HistoryDependentItemCallback(this)); + RequestDependentMessageData( + this, + reply->replyToPeerId, + reply->replyToMsgId); } } if (const auto via = Get()) { diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index c06cccb87e..1c78886663 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -23,8 +23,10 @@ struct HistoryMessageReply; struct HistoryMessageViews; struct HistoryMessageMarkupData; -[[nodiscard]] Fn HistoryDependentItemCallback( - not_null item); +void RequestDependentMessageData( + not_null item, + PeerId peerId, + MsgId msgId); [[nodiscard]] MessageFlags NewMessageFlags(not_null peer); [[nodiscard]] bool ShouldSendSilent( not_null peer, diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index c378c72e73..0268b5d9ee 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -1153,13 +1153,10 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) { : 0; dependent->msgId = data.vreply_to_msg_id().v; if (!updateDependent()) { - history()->session().api().requestMessageData( - (peerIsChannel(dependent->peerId) - ? history()->owner().channel( - peerToChannel(dependent->peerId)).get() - : history()->peer->asChannel()), - dependent->msgId, - HistoryDependentItemCallback(this)); + RequestDependentMessageData( + this, + dependent->peerId, + dependent->msgId); } } });