From 863313531d7135af216939b8a48fcfbeacce1bfa Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 21 Jul 2023 13:44:43 +0400 Subject: [PATCH] Fix crash in viewed shared story deletion. --- Telegram/SourceFiles/data/data_stories.cpp | 16 +++++++++++----- Telegram/SourceFiles/data/data_stories.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/data/data_stories.cpp b/Telegram/SourceFiles/data/data_stories.cpp index 4768714ddf..085958ea28 100644 --- a/Telegram/SourceFiles/data/data_stories.cpp +++ b/Telegram/SourceFiles/data/data_stories.cpp @@ -692,10 +692,10 @@ void Stories::applyDeleted(FullStoryId id) { if (i != end(_stories)) { const auto j = i->second.find(id.story); if (j != end(i->second)) { - // Duplicated in Stories::apply(peer, const MTPUserStories*). - auto story = std::move(j->second); + const auto &story = _deletingStories[id] = std::move(j->second); _expiring.remove(story->expires(), story->fullId()); i->second.erase(j); + session().changes().storyUpdated( story.get(), UpdateFlag::Destroyed); @@ -736,6 +736,7 @@ void Stories::applyDeleted(FullStoryId id) { if (i->second.empty()) { _stories.erase(i); } + _deletingStories.remove(id); } } } @@ -1628,9 +1629,14 @@ bool Stories::registerPolling(FullStoryId id, Polling polling) { } void Stories::unregisterPolling(FullStoryId id, Polling polling) { - const auto maybeStory = lookup(id); - Assert(maybeStory.has_value()); - unregisterPolling(*maybeStory, polling); + if (const auto maybeStory = lookup(id)) { + unregisterPolling(*maybeStory, polling); + } else if (const auto i = _deletingStories.find(id) + ; i != end(_deletingStories)) { + unregisterPolling(i->second.get(), polling); + } else { + Unexpected("Couldn't find story for unregistering polling."); + } } int Stories::pollingInterval(const PollingSettings &settings) const { diff --git a/Telegram/SourceFiles/data/data_stories.h b/Telegram/SourceFiles/data/data_stories.h index 27eb0f7613..c4d55a1293 100644 --- a/Telegram/SourceFiles/data/data_stories.h +++ b/Telegram/SourceFiles/data/data_stories.h @@ -299,6 +299,7 @@ private: std::unordered_map< PeerId, base::flat_map>> _stories; + base::flat_map> _deletingStories; std::unordered_map< PeerId, base::flat_map>> _items;