diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index bf473a19b..e82891a4f 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -880,13 +880,14 @@ void HistoryItem::updateDependentServiceText() { } } -bool HistoryItem::updateServiceDependent(bool force) { +void HistoryItem::updateServiceDependent(bool force) { auto dependent = GetServiceDependentData(); Assert(dependent != nullptr); if (!force) { if (!dependent->msgId || dependent->msg) { - return true; + dependent->pendingResolve = false; + return; } } @@ -930,7 +931,12 @@ bool HistoryItem::updateServiceDependent(bool force) { if (force && gotDependencyItem) { Core::App().notifications().checkDelayed(); } - return (dependent->msg || !dependent->msgId); + if (dependent->msg || !dependent->msgId || force) { + dependent->pendingResolve = false; + } else { + dependent->pendingResolve = true; + dependent->requestedResolve = false; + } } MsgId HistoryItem::dependencyMsgId() const { @@ -948,9 +954,49 @@ void HistoryItem::checkBuyButton() { } } +void HistoryItem::resolveDependent( + not_null dependent) { + if (!dependent->pendingResolve || dependent->requestedResolve) { + return; + } + dependent->requestedResolve = true; + RequestDependentMessageItem( + this, + (dependent->peerId ? dependent->peerId : _history->peer->id), + dependent->msgId); +} + +void HistoryItem::resolveDependent(not_null reply) { + if (!reply->acquireResolve()) { + return; + } else if (const auto messageId = reply->messageId()) { + RequestDependentMessageItem( + this, + reply->externalPeerId(), + reply->messageId()); + } else if (reply->storyId()) { + RequestDependentMessageStory( + this, + reply->externalPeerId(), + reply->storyId()); + } +} + +void HistoryItem::resolveDependent() { + if (const auto dependent = GetServiceDependentData()) { + resolveDependent(dependent); + } else if (const auto reply = Get()) { + resolveDependent(reply); + } +} + bool HistoryItem::notificationReady() const { if (const auto dependent = GetServiceDependentData()) { - return (dependent->msg || !dependent->msgId); + if (dependent->msg || !dependent->msgId) { + return true; + } + const_cast(this)->resolveDependent( + const_cast(dependent)); } return true; } @@ -3146,6 +3192,8 @@ TextWithEntities HistoryItem::notificationText( ItemPreview HistoryItem::toPreview(ToPreviewOptions options) const { if (isService()) { + const_cast(this)->resolveDependent(); + // Don't show small media for service messages (chat photo changed). // Because larger version is shown exactly to the left of the small. //auto media = _media ? _media->toPreview(options) : ItemPreview(); @@ -3306,19 +3354,7 @@ void HistoryItem::createComponents(CreateConfig &&config) { if (const auto reply = Get()) { reply->set(std::move(config.reply)); - if (!reply->updateData(this)) { - if (const auto messageId = reply->messageId()) { - RequestDependentMessageItem( - this, - reply->externalPeerId(), - reply->messageId()); - } else if (reply->storyId()) { - RequestDependentMessageStory( - this, - reply->externalPeerId(), - reply->storyId()); - } - } + reply->updateData(this); } if (const auto via = Get()) { via->create(&_history->owner(), config.viaBotId); @@ -3891,14 +3927,7 @@ void HistoryItem::createServiceFromMtp(const MTPDmessageService &message) { dependent->topId = data.vreply_to_top_id().value_or(id); dependent->topicPost = data.is_forum_topic() || Has(); - if (!updateServiceDependent()) { - RequestDependentMessageItem( - this, - (dependent->peerId - ? dependent->peerId - : _history->peer->id), - dependent->msgId); - } + updateServiceDependent(); } } }, [](const MTPDmessageReplyStoryHeader &data) { diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 93f1b44d1..3c5df4f25 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -195,6 +195,8 @@ public: void checkStoryForwardInfo(); void checkBuyButton(); + void resolveDependent(); + void updateServiceText(PreparedServiceText &&text); void updateStoryMentionText(); @@ -587,7 +589,7 @@ private: [[nodiscard]] auto GetServiceDependentData() const -> const HistoryServiceDependentData *; void updateDependentServiceText(); - bool updateServiceDependent(bool force = false); + void updateServiceDependent(bool force = false); void setServiceText(PreparedServiceText &&prepared); void setStoryFields(not_null story); @@ -603,6 +605,9 @@ private: bool used); void setSelfDestruct(HistorySelfDestructType type, MTPint mtpTTLvalue); + void resolveDependent(not_null dependent); + void resolveDependent(not_null reply); + [[nodiscard]] TextWithEntities fromLinkText() const; [[nodiscard]] ClickHandlerPtr fromLink() const; diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 956f6e644..26fca0b19 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -384,13 +384,14 @@ HistoryMessageReply::~HistoryMessageReply() { _fields.externalMedia = nullptr; } -bool HistoryMessageReply::updateData( +void HistoryMessageReply::updateData( not_null holder, bool force) { const auto guard = gsl::finally([&] { refreshReplyToMedia(); }); if (!force) { if (resolvedMessage || resolvedStory || _unavailable) { - return true; + _pendingResolve = 0; + return; } } const auto peerId = _fields.externalPeerId @@ -449,10 +450,15 @@ bool HistoryMessageReply::updateData( } holder->history()->owner().requestItemResize(holder); } - return resolvedMessage + if (resolvedMessage || resolvedStory || (!_fields.messageId && !_fields.storyId && external()) - || _unavailable; + || _unavailable) { + _pendingResolve = 0; + } else if (!force) { + _pendingResolve = 1; + _requestedResolve = 0; + } } void HistoryMessageReply::set(ReplyFields fields) { @@ -468,12 +474,7 @@ void HistoryMessageReply::updateFields( if ((_fields.messageId != messageId) && !IsServerMsgId(_fields.messageId)) { _fields.messageId = messageId; - if (!updateData(holder)) { - RequestDependentMessageItem( - holder, - _fields.externalPeerId, - _fields.messageId); - } + updateData(holder); } if ((_fields.topMessageId != topMessageId) && !IsServerMsgId(_fields.topMessageId)) { @@ -481,6 +482,14 @@ void HistoryMessageReply::updateFields( } } +bool HistoryMessageReply::acquireResolve() { + if (!_pendingResolve || _requestedResolve) { + return false; + } + _requestedResolve = 1; + return true; +} + void HistoryMessageReply::setTopMessageId(MsgId topMessageId) { _fields.topMessageId = topMessageId; } diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index b4a6981bb..bd0eb6a9d 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -271,7 +271,7 @@ struct HistoryMessageReply MsgId messageId, MsgId topMessageId, bool topicPost); - bool updateData(not_null holder, bool force = false); + void updateData(not_null holder, bool force = false); // Must be called before destructor. void clearData(not_null holder); @@ -317,6 +317,8 @@ struct HistoryMessageReply return _multiline; } + [[nodiscard]] bool acquireResolve(); + void setTopMessageId(MsgId topMessageId); void refreshReplyToMedia(); @@ -331,6 +333,8 @@ private: uint8 _unavailable : 1 = 0; uint8 _displaying : 1 = 0; uint8 _multiline : 1 = 0; + uint8 _pendingResolve : 1 = 0; + uint8 _requestedResolve : 1 = 0; }; @@ -562,6 +566,8 @@ struct HistoryServiceDependentData { MsgId msgId = 0; MsgId topId = 0; bool topicPost = false; + bool pendingResolve = false; + bool requestedResolve = false; }; struct HistoryServicePinned diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 04c2977e3..5234b53b3 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -3877,6 +3877,8 @@ int Message::resizeContentGetHeight(int newWidth) { const auto mediaDisplayed = media ? media->isDisplayed() : false; const auto bubble = drawBubble(); + item->resolveDependent(); + // This code duplicates countGeometry() but also resizes media. const auto centeredView = item->isFakeAboutView() || (context() == Context::Replies && item->isDiscussionPost()); diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index 319a2980a..acd5929f6 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -432,6 +432,8 @@ QSize Service::performCountCurrentSize(int newWidth) { newHeight += bar->height(); } + data()->resolveDependent(); + if (isHidden()) { return { newWidth, newHeight }; } diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index bcd7f46b0..feeb83a66 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -302,7 +302,6 @@ void SetupPrivacy( tr::lng_settings_profile_photo_privacy(), Key::ProfilePhoto, [] { return std::make_unique(); }); - AddMessagesPrivacyButton(controller, container); add( tr::lng_settings_bio_privacy(), Key::About, @@ -326,6 +325,7 @@ void SetupPrivacy( tr::lng_settings_voices_privacy(), Key::Voices, [=] { return std::make_unique(session); }); + AddMessagesPrivacyButton(controller, container); session->api().userPrivacy().reload(Api::UserPrivacy::Key::AddedByPhone);