mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
Try to request dependent messages on demand.
This commit is contained in:
parent
a38f731265
commit
ce6fc19b84
7 changed files with 91 additions and 38 deletions
|
@ -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<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 {
|
||||
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;
|
||||
}
|
||||
|
@ -3146,6 +3192,8 @@ TextWithEntities HistoryItem::notificationText(
|
|||
|
||||
ItemPreview HistoryItem::toPreview(ToPreviewOptions options) const {
|
||||
if (isService()) {
|
||||
const_cast<HistoryItem*>(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<HistoryMessageReply>()) {
|
||||
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<HistoryMessageVia>()) {
|
||||
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<HistoryServiceTopicInfo>();
|
||||
if (!updateServiceDependent()) {
|
||||
RequestDependentMessageItem(
|
||||
this,
|
||||
(dependent->peerId
|
||||
? dependent->peerId
|
||||
: _history->peer->id),
|
||||
dependent->msgId);
|
||||
}
|
||||
updateServiceDependent();
|
||||
}
|
||||
}
|
||||
}, [](const MTPDmessageReplyStoryHeader &data) {
|
||||
|
|
|
@ -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<Data::Story*> story);
|
||||
|
@ -603,6 +605,9 @@ private:
|
|||
bool used);
|
||||
void setSelfDestruct(HistorySelfDestructType type, MTPint mtpTTLvalue);
|
||||
|
||||
void resolveDependent(not_null<HistoryServiceDependentData*> dependent);
|
||||
void resolveDependent(not_null<HistoryMessageReply*> reply);
|
||||
|
||||
[[nodiscard]] TextWithEntities fromLinkText() const;
|
||||
[[nodiscard]] ClickHandlerPtr fromLink() const;
|
||||
|
||||
|
|
|
@ -384,13 +384,14 @@ HistoryMessageReply::~HistoryMessageReply() {
|
|||
_fields.externalMedia = nullptr;
|
||||
}
|
||||
|
||||
bool HistoryMessageReply::updateData(
|
||||
void HistoryMessageReply::updateData(
|
||||
not_null<HistoryItem*> 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;
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ struct HistoryMessageReply
|
|||
MsgId messageId,
|
||||
MsgId topMessageId,
|
||||
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.
|
||||
void clearData(not_null<HistoryItem*> 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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -432,6 +432,8 @@ QSize Service::performCountCurrentSize(int newWidth) {
|
|||
newHeight += bar->height();
|
||||
}
|
||||
|
||||
data()->resolveDependent();
|
||||
|
||||
if (isHidden()) {
|
||||
return { newWidth, newHeight };
|
||||
}
|
||||
|
|
|
@ -302,7 +302,6 @@ void SetupPrivacy(
|
|||
tr::lng_settings_profile_photo_privacy(),
|
||||
Key::ProfilePhoto,
|
||||
[] { return std::make_unique<ProfilePhotoPrivacyController>(); });
|
||||
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<VoicesPrivacyController>(session); });
|
||||
AddMessagesPrivacyButton(controller, container);
|
||||
|
||||
session->api().userPrivacy().reload(Api::UserPrivacy::Key::AddedByPhone);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue