Fix crash in viewed shared story deletion.

This commit is contained in:
John Preston 2023-07-21 13:44:43 +04:00
parent 9d8d039886
commit 863313531d
2 changed files with 12 additions and 5 deletions

View file

@ -692,10 +692,10 @@ void Stories::applyDeleted(FullStoryId id) {
if (i != end(_stories)) { if (i != end(_stories)) {
const auto j = i->second.find(id.story); const auto j = i->second.find(id.story);
if (j != end(i->second)) { if (j != end(i->second)) {
// Duplicated in Stories::apply(peer, const MTPUserStories*). const auto &story = _deletingStories[id] = std::move(j->second);
auto story = std::move(j->second);
_expiring.remove(story->expires(), story->fullId()); _expiring.remove(story->expires(), story->fullId());
i->second.erase(j); i->second.erase(j);
session().changes().storyUpdated( session().changes().storyUpdated(
story.get(), story.get(),
UpdateFlag::Destroyed); UpdateFlag::Destroyed);
@ -736,6 +736,7 @@ void Stories::applyDeleted(FullStoryId id) {
if (i->second.empty()) { if (i->second.empty()) {
_stories.erase(i); _stories.erase(i);
} }
_deletingStories.remove(id);
} }
} }
} }
@ -1628,9 +1629,14 @@ bool Stories::registerPolling(FullStoryId id, Polling polling) {
} }
void Stories::unregisterPolling(FullStoryId id, Polling polling) { void Stories::unregisterPolling(FullStoryId id, Polling polling) {
const auto maybeStory = lookup(id); if (const auto maybeStory = lookup(id)) {
Assert(maybeStory.has_value()); unregisterPolling(*maybeStory, polling);
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 { int Stories::pollingInterval(const PollingSettings &settings) const {

View file

@ -299,6 +299,7 @@ private:
std::unordered_map< std::unordered_map<
PeerId, PeerId,
base::flat_map<StoryId, std::unique_ptr<Story>>> _stories; base::flat_map<StoryId, std::unique_ptr<Story>>> _stories;
base::flat_map<FullStoryId, std::unique_ptr<Story>> _deletingStories;
std::unordered_map< std::unordered_map<
PeerId, PeerId,
base::flat_map<StoryId, std::weak_ptr<HistoryItem>>> _items; base::flat_map<StoryId, std::weak_ptr<HistoryItem>>> _items;