Add a RequestDependentMessageData method.

This commit is contained in:
John Preston 2021-11-08 12:32:25 +04:00
parent 213d7875ba
commit 6eaeb306d6
3 changed files with 29 additions and 25 deletions

View File

@ -347,15 +347,23 @@ void FastShareMessage(not_null<HistoryItem*> item) {
.navigation = App::wnd()->sessionController() })); .navigation = App::wnd()->sessionController() }));
} }
Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback( void RequestDependentMessageData(
not_null<HistoryItem*> item) { not_null<HistoryItem*> item,
const auto session = &item->history()->session(); PeerId peerId,
const auto dependent = item->fullId(); MsgId msgId) {
return [=](ChannelData *channel, MsgId msgId) { const auto fullId = item->fullId();
if (const auto item = session->data().message(dependent)) { const auto history = item->history();
item->updateDependencyItem(); 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<PeerData*> peer) { MessageFlags NewMessageFlags(not_null<PeerData*> peer) {
@ -1094,13 +1102,10 @@ void HistoryMessage::createComponents(CreateConfig &&config) {
reply->replyToMsgId = config.replyTo; reply->replyToMsgId = config.replyTo;
reply->replyToMsgTop = isScheduled() ? 0 : config.replyToTop; reply->replyToMsgTop = isScheduled() ? 0 : config.replyToTop;
if (!reply->updateData(this)) { if (!reply->updateData(this)) {
history()->session().api().requestMessageData( RequestDependentMessageData(
(peerIsChannel(reply->replyToPeerId) this,
? history()->owner().channel( reply->replyToPeerId,
peerToChannel(reply->replyToPeerId)).get() reply->replyToMsgId);
: history()->peer->asChannel()),
reply->replyToMsgId,
HistoryDependentItemCallback(this));
} }
} }
if (const auto via = Get<HistoryMessageVia>()) { if (const auto via = Get<HistoryMessageVia>()) {

View File

@ -23,8 +23,10 @@ struct HistoryMessageReply;
struct HistoryMessageViews; struct HistoryMessageViews;
struct HistoryMessageMarkupData; struct HistoryMessageMarkupData;
[[nodiscard]] Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback( void RequestDependentMessageData(
not_null<HistoryItem*> item); not_null<HistoryItem*> item,
PeerId peerId,
MsgId msgId);
[[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer); [[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
[[nodiscard]] bool ShouldSendSilent( [[nodiscard]] bool ShouldSendSilent(
not_null<PeerData*> peer, not_null<PeerData*> peer,

View File

@ -1153,13 +1153,10 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) {
: 0; : 0;
dependent->msgId = data.vreply_to_msg_id().v; dependent->msgId = data.vreply_to_msg_id().v;
if (!updateDependent()) { if (!updateDependent()) {
history()->session().api().requestMessageData( RequestDependentMessageData(
(peerIsChannel(dependent->peerId) this,
? history()->owner().channel( dependent->peerId,
peerToChannel(dependent->peerId)).get() dependent->msgId);
: history()->peer->asChannel()),
dependent->msgId,
HistoryDependentItemCallback(this));
} }
} }
}); });