mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Apply updates correctly.
This commit is contained in:
parent
2e6790c45c
commit
9f548b523e
6 changed files with 82 additions and 9 deletions
|
@ -166,7 +166,7 @@ Main::Session &Stories::session() const {
|
|||
}
|
||||
|
||||
void Stories::apply(const MTPDupdateStories &data) {
|
||||
pushToFront(parse(data.vstories()));
|
||||
applyChanges(parse(data.vstories()));
|
||||
_allChanged.fire({});
|
||||
}
|
||||
|
||||
|
@ -402,14 +402,42 @@ void Stories::applyDeleted(FullStoryId id) {
|
|||
session().changes().storyUpdated(
|
||||
story.get(),
|
||||
UpdateFlag::Destroyed);
|
||||
removeDependencyStory(story.get());
|
||||
if (i->second.empty()) {
|
||||
_stories.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto j = ranges::find(_all, id.peer, [](const StoriesList &list) {
|
||||
return list.user->id;
|
||||
});
|
||||
if (j != end(_all)) {
|
||||
const auto till = ranges::remove(j->ids, id.story);
|
||||
const auto removed = int(std::distance(till, end(j->ids)));
|
||||
if (till != end(j->ids)) {
|
||||
j->ids.erase(till, end(j->ids));
|
||||
j->total = std::max(j->total - removed, 0);
|
||||
if (j->ids.empty()) {
|
||||
_all.erase(j);
|
||||
}
|
||||
_allChanged.fire({});
|
||||
}
|
||||
}
|
||||
_deleted.emplace(id);
|
||||
}
|
||||
|
||||
void Stories::removeDependencyStory(not_null<Story*> story) {
|
||||
const auto i = _dependentMessages.find(story);
|
||||
if (i != end(_dependentMessages)) {
|
||||
const auto items = std::move(i->second);
|
||||
_dependentMessages.erase(i);
|
||||
|
||||
for (const auto &dependent : items) {
|
||||
dependent->dependencyStoryRemoved(story);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<StoriesList> &Stories::all() {
|
||||
return _all;
|
||||
}
|
||||
|
@ -465,12 +493,21 @@ void Stories::pushToBack(StoriesList &&list) {
|
|||
}
|
||||
}
|
||||
|
||||
void Stories::pushToFront(StoriesList &&list) {
|
||||
void Stories::applyChanges(StoriesList &&list) {
|
||||
const auto i = ranges::find(_all, list.user, &StoriesList::user);
|
||||
if (i != end(_all)) {
|
||||
*i = std::move(list);
|
||||
ranges::rotate(begin(_all), i, i + 1);
|
||||
} else {
|
||||
auto added = false;
|
||||
for (const auto id : list.ids) {
|
||||
if (!ranges::contains(i->ids, id)) {
|
||||
i->ids.insert(begin(i->ids), id);
|
||||
++i->total;
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
if (added) {
|
||||
ranges::rotate(begin(_all), i, i + 1);
|
||||
}
|
||||
} else if (!list.ids.empty()) {
|
||||
_all.insert(begin(_all), std::move(list));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,8 +123,9 @@ private:
|
|||
void finalizeResolve(FullStoryId id);
|
||||
|
||||
void pushToBack(StoriesList &&list);
|
||||
void pushToFront(StoriesList &&list);
|
||||
void applyChanges(StoriesList &&list);
|
||||
void applyDeleted(FullStoryId id);
|
||||
void removeDependencyStory(not_null<Story*> story);
|
||||
|
||||
const not_null<Session*> _owner;
|
||||
base::flat_map<
|
||||
|
|
|
@ -725,6 +725,18 @@ void HistoryItem::dependencyItemRemoved(not_null<HistoryItem*> dependency) {
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryItem::dependencyStoryRemoved(
|
||||
not_null<Data::Story*> dependency) {
|
||||
if (const auto reply = Get<HistoryMessageReply>()) {
|
||||
const auto documentId = reply->replyToDocumentId;
|
||||
reply->storyRemoved(this, dependency);
|
||||
if (documentId != reply->replyToDocumentId
|
||||
&& generateLocalEntitiesByReply()) {
|
||||
_history->owner().requestItemTextRefresh(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryItem::updateDependencyItem() {
|
||||
if (const auto reply = Get<HistoryMessageReply>()) {
|
||||
const auto documentId = reply->replyToDocumentId;
|
||||
|
|
|
@ -57,6 +57,7 @@ class MessageReactions;
|
|||
class ForumTopic;
|
||||
class Thread;
|
||||
struct SponsoredFrom;
|
||||
class Story;
|
||||
} // namespace Data
|
||||
|
||||
namespace Main {
|
||||
|
@ -185,6 +186,7 @@ public:
|
|||
};
|
||||
|
||||
void dependencyItemRemoved(not_null<HistoryItem*> dependency);
|
||||
void dependencyStoryRemoved(not_null<Data::Story*> dependency);
|
||||
void updateDependencyItem();
|
||||
[[nodiscard]] MsgId dependencyMsgId() const;
|
||||
[[nodiscard]] bool notificationReady() const;
|
||||
|
|
|
@ -369,7 +369,14 @@ void HistoryMessageReply::clearData(not_null<HistoryItem*> holder) {
|
|||
replyToMsg.get());
|
||||
replyToMsg = nullptr;
|
||||
}
|
||||
if (replyToStory) {
|
||||
holder->history()->owner().stories().unregisterDependentMessage(
|
||||
holder,
|
||||
replyToStory.get());
|
||||
replyToStory = nullptr;
|
||||
}
|
||||
replyToMsgId = 0;
|
||||
replyToStoryId = 0;
|
||||
refreshReplyToMedia();
|
||||
}
|
||||
|
||||
|
@ -466,14 +473,23 @@ void HistoryMessageReply::resize(int width) const {
|
|||
}
|
||||
|
||||
void HistoryMessageReply::itemRemoved(
|
||||
HistoryItem *holder,
|
||||
HistoryItem *removed) {
|
||||
not_null<HistoryItem*> holder,
|
||||
not_null<HistoryItem*> removed) {
|
||||
if (replyToMsg.get() == removed) {
|
||||
clearData(holder);
|
||||
holder->history()->owner().requestItemResize(holder);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryMessageReply::storyRemoved(
|
||||
not_null<HistoryItem*> holder,
|
||||
not_null<Data::Story*> removed) {
|
||||
if (replyToStory.get() == removed) {
|
||||
clearData(holder);
|
||||
holder->history()->owner().requestItemResize(holder);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryMessageReply::paint(
|
||||
Painter &p,
|
||||
not_null<const HistoryView::Element*> holder,
|
||||
|
|
|
@ -249,7 +249,12 @@ struct HistoryMessageReply
|
|||
[[nodiscard]] bool isNameUpdated(not_null<HistoryItem*> holder) const;
|
||||
void updateName(not_null<HistoryItem*> holder) const;
|
||||
void resize(int width) const;
|
||||
void itemRemoved(HistoryItem *holder, HistoryItem *removed);
|
||||
void itemRemoved(
|
||||
not_null<HistoryItem*> holder,
|
||||
not_null<HistoryItem*> removed);
|
||||
void storyRemoved(
|
||||
not_null<HistoryItem*> holder,
|
||||
not_null<Data::Story*> removed);
|
||||
|
||||
void paint(
|
||||
Painter &p,
|
||||
|
|
Loading…
Add table
Reference in a new issue