Try to request dependent messages on demand.

This commit is contained in:
John Preston 2024-01-18 19:25:51 +04:00
parent a38f731265
commit ce6fc19b84
7 changed files with 91 additions and 38 deletions

View file

@ -880,13 +880,14 @@ void HistoryItem::updateDependentServiceText() {
} }
} }
bool HistoryItem::updateServiceDependent(bool force) { void HistoryItem::updateServiceDependent(bool force) {
auto dependent = GetServiceDependentData(); auto dependent = GetServiceDependentData();
Assert(dependent != nullptr); Assert(dependent != nullptr);
if (!force) { if (!force) {
if (!dependent->msgId || dependent->msg) { if (!dependent->msgId || dependent->msg) {
return true; dependent->pendingResolve = false;
return;
} }
} }
@ -930,7 +931,12 @@ bool HistoryItem::updateServiceDependent(bool force) {
if (force && gotDependencyItem) { if (force && gotDependencyItem) {
Core::App().notifications().checkDelayed(); 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 { MsgId HistoryItem::dependencyMsgId() const {
@ -948,9 +954,49 @@ void HistoryItem::checkBuyButton() {
} }
} }
void HistoryItem::resolveDependent(
not_null<HistoryServiceDependentData*> 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<HistoryMessageReply*> 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<HistoryMessageReply>()) {
resolveDependent(reply);
}
}
bool HistoryItem::notificationReady() const { bool HistoryItem::notificationReady() const {
if (const auto dependent = GetServiceDependentData()) { if (const auto dependent = GetServiceDependentData()) {
return (dependent->msg || !dependent->msgId); if (dependent->msg || !dependent->msgId) {
return true;
}
const_cast<HistoryItem*>(this)->resolveDependent(
const_cast<HistoryServiceDependentData*>(dependent));
} }
return true; return true;
} }
@ -3146,6 +3192,8 @@ TextWithEntities HistoryItem::notificationText(
ItemPreview HistoryItem::toPreview(ToPreviewOptions options) const { ItemPreview HistoryItem::toPreview(ToPreviewOptions options) const {
if (isService()) { if (isService()) {
const_cast<HistoryItem*>(this)->resolveDependent();
// Don't show small media for service messages (chat photo changed). // Don't show small media for service messages (chat photo changed).
// Because larger version is shown exactly to the left of the small. // Because larger version is shown exactly to the left of the small.
//auto media = _media ? _media->toPreview(options) : ItemPreview(); //auto media = _media ? _media->toPreview(options) : ItemPreview();
@ -3306,19 +3354,7 @@ void HistoryItem::createComponents(CreateConfig &&config) {
if (const auto reply = Get<HistoryMessageReply>()) { if (const auto reply = Get<HistoryMessageReply>()) {
reply->set(std::move(config.reply)); reply->set(std::move(config.reply));
if (!reply->updateData(this)) { 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());
}
}
} }
if (const auto via = Get<HistoryMessageVia>()) { if (const auto via = Get<HistoryMessageVia>()) {
via->create(&_history->owner(), config.viaBotId); 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->topId = data.vreply_to_top_id().value_or(id);
dependent->topicPost = data.is_forum_topic() dependent->topicPost = data.is_forum_topic()
|| Has<HistoryServiceTopicInfo>(); || Has<HistoryServiceTopicInfo>();
if (!updateServiceDependent()) { updateServiceDependent();
RequestDependentMessageItem(
this,
(dependent->peerId
? dependent->peerId
: _history->peer->id),
dependent->msgId);
}
} }
} }
}, [](const MTPDmessageReplyStoryHeader &data) { }, [](const MTPDmessageReplyStoryHeader &data) {

View file

@ -195,6 +195,8 @@ public:
void checkStoryForwardInfo(); void checkStoryForwardInfo();
void checkBuyButton(); void checkBuyButton();
void resolveDependent();
void updateServiceText(PreparedServiceText &&text); void updateServiceText(PreparedServiceText &&text);
void updateStoryMentionText(); void updateStoryMentionText();
@ -587,7 +589,7 @@ private:
[[nodiscard]] auto GetServiceDependentData() const [[nodiscard]] auto GetServiceDependentData() const
-> const HistoryServiceDependentData *; -> const HistoryServiceDependentData *;
void updateDependentServiceText(); void updateDependentServiceText();
bool updateServiceDependent(bool force = false); void updateServiceDependent(bool force = false);
void setServiceText(PreparedServiceText &&prepared); void setServiceText(PreparedServiceText &&prepared);
void setStoryFields(not_null<Data::Story*> story); void setStoryFields(not_null<Data::Story*> story);
@ -603,6 +605,9 @@ private:
bool used); bool used);
void setSelfDestruct(HistorySelfDestructType type, MTPint mtpTTLvalue); void setSelfDestruct(HistorySelfDestructType type, MTPint mtpTTLvalue);
void resolveDependent(not_null<HistoryServiceDependentData*> dependent);
void resolveDependent(not_null<HistoryMessageReply*> reply);
[[nodiscard]] TextWithEntities fromLinkText() const; [[nodiscard]] TextWithEntities fromLinkText() const;
[[nodiscard]] ClickHandlerPtr fromLink() const; [[nodiscard]] ClickHandlerPtr fromLink() const;

View file

@ -384,13 +384,14 @@ HistoryMessageReply::~HistoryMessageReply() {
_fields.externalMedia = nullptr; _fields.externalMedia = nullptr;
} }
bool HistoryMessageReply::updateData( void HistoryMessageReply::updateData(
not_null<HistoryItem*> holder, not_null<HistoryItem*> holder,
bool force) { bool force) {
const auto guard = gsl::finally([&] { refreshReplyToMedia(); }); const auto guard = gsl::finally([&] { refreshReplyToMedia(); });
if (!force) { if (!force) {
if (resolvedMessage || resolvedStory || _unavailable) { if (resolvedMessage || resolvedStory || _unavailable) {
return true; _pendingResolve = 0;
return;
} }
} }
const auto peerId = _fields.externalPeerId const auto peerId = _fields.externalPeerId
@ -449,10 +450,15 @@ bool HistoryMessageReply::updateData(
} }
holder->history()->owner().requestItemResize(holder); holder->history()->owner().requestItemResize(holder);
} }
return resolvedMessage if (resolvedMessage
|| resolvedStory || resolvedStory
|| (!_fields.messageId && !_fields.storyId && external()) || (!_fields.messageId && !_fields.storyId && external())
|| _unavailable; || _unavailable) {
_pendingResolve = 0;
} else if (!force) {
_pendingResolve = 1;
_requestedResolve = 0;
}
} }
void HistoryMessageReply::set(ReplyFields fields) { void HistoryMessageReply::set(ReplyFields fields) {
@ -468,12 +474,7 @@ void HistoryMessageReply::updateFields(
if ((_fields.messageId != messageId) if ((_fields.messageId != messageId)
&& !IsServerMsgId(_fields.messageId)) { && !IsServerMsgId(_fields.messageId)) {
_fields.messageId = messageId; _fields.messageId = messageId;
if (!updateData(holder)) { updateData(holder);
RequestDependentMessageItem(
holder,
_fields.externalPeerId,
_fields.messageId);
}
} }
if ((_fields.topMessageId != topMessageId) if ((_fields.topMessageId != topMessageId)
&& !IsServerMsgId(_fields.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) { void HistoryMessageReply::setTopMessageId(MsgId topMessageId) {
_fields.topMessageId = topMessageId; _fields.topMessageId = topMessageId;
} }

View file

@ -271,7 +271,7 @@ struct HistoryMessageReply
MsgId messageId, MsgId messageId,
MsgId topMessageId, MsgId topMessageId,
bool topicPost); bool topicPost);
bool updateData(not_null<HistoryItem*> holder, bool force = false); void updateData(not_null<HistoryItem*> holder, bool force = false);
// Must be called before destructor. // Must be called before destructor.
void clearData(not_null<HistoryItem*> holder); void clearData(not_null<HistoryItem*> holder);
@ -317,6 +317,8 @@ struct HistoryMessageReply
return _multiline; return _multiline;
} }
[[nodiscard]] bool acquireResolve();
void setTopMessageId(MsgId topMessageId); void setTopMessageId(MsgId topMessageId);
void refreshReplyToMedia(); void refreshReplyToMedia();
@ -331,6 +333,8 @@ private:
uint8 _unavailable : 1 = 0; uint8 _unavailable : 1 = 0;
uint8 _displaying : 1 = 0; uint8 _displaying : 1 = 0;
uint8 _multiline : 1 = 0; uint8 _multiline : 1 = 0;
uint8 _pendingResolve : 1 = 0;
uint8 _requestedResolve : 1 = 0;
}; };
@ -562,6 +566,8 @@ struct HistoryServiceDependentData {
MsgId msgId = 0; MsgId msgId = 0;
MsgId topId = 0; MsgId topId = 0;
bool topicPost = false; bool topicPost = false;
bool pendingResolve = false;
bool requestedResolve = false;
}; };
struct HistoryServicePinned struct HistoryServicePinned

View file

@ -3877,6 +3877,8 @@ int Message::resizeContentGetHeight(int newWidth) {
const auto mediaDisplayed = media ? media->isDisplayed() : false; const auto mediaDisplayed = media ? media->isDisplayed() : false;
const auto bubble = drawBubble(); const auto bubble = drawBubble();
item->resolveDependent();
// This code duplicates countGeometry() but also resizes media. // This code duplicates countGeometry() but also resizes media.
const auto centeredView = item->isFakeAboutView() const auto centeredView = item->isFakeAboutView()
|| (context() == Context::Replies && item->isDiscussionPost()); || (context() == Context::Replies && item->isDiscussionPost());

View file

@ -432,6 +432,8 @@ QSize Service::performCountCurrentSize(int newWidth) {
newHeight += bar->height(); newHeight += bar->height();
} }
data()->resolveDependent();
if (isHidden()) { if (isHidden()) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} }

View file

@ -302,7 +302,6 @@ void SetupPrivacy(
tr::lng_settings_profile_photo_privacy(), tr::lng_settings_profile_photo_privacy(),
Key::ProfilePhoto, Key::ProfilePhoto,
[] { return std::make_unique<ProfilePhotoPrivacyController>(); }); [] { return std::make_unique<ProfilePhotoPrivacyController>(); });
AddMessagesPrivacyButton(controller, container);
add( add(
tr::lng_settings_bio_privacy(), tr::lng_settings_bio_privacy(),
Key::About, Key::About,
@ -326,6 +325,7 @@ void SetupPrivacy(
tr::lng_settings_voices_privacy(), tr::lng_settings_voices_privacy(),
Key::Voices, Key::Voices,
[=] { return std::make_unique<VoicesPrivacyController>(session); }); [=] { return std::make_unique<VoicesPrivacyController>(session); });
AddMessagesPrivacyButton(controller, container);
session->api().userPrivacy().reload(Api::UserPrivacy::Key::AddedByPhone); session->api().userPrivacy().reload(Api::UserPrivacy::Key::AddedByPhone);