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)) {
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 {

View File

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