Skip to content

Commit 3177582

Browse files
committed
Fix stories polling and downloads layouts on item removal.
1 parent 0f755bd commit 3177582

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎Telegram/SourceFiles/info/downloads/info_downloads_provider.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ void Provider::remove(not_null<const HistoryItem*> item) {
247247
_elements.erase(ranges::remove_if(_elements, proj), end(_elements));
248248
if (const auto i = _layouts.find(item); i != end(_layouts)) {
249249
_layoutRemoved.fire(i->second.item.get());
250-
_layouts.erase(i);
250+
// The list widget handles layoutRemoved() synchronously and may
251+
// refresh its height from there, which can reach refreshViewer()
252+
// -> refreshRows() -> fillSections() -> clearStaleLayouts() before
253+
// we get back here, erasing this very entry, so look it up again.
254+
if (const auto j = _layouts.find(item); j != end(_layouts)) {
255+
_layouts.erase(j);
256+
}
251257
}
252258
refreshPostponed(false);
253259
}

‎Telegram/SourceFiles/info/stories/info_stories_provider.cpp‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,17 @@ void Provider::storyRemoved(not_null<Data::Story*> story) {
286286

287287
const auto id = story->id();
288288
if (const auto i = _layouts.find(id); i != end(_layouts)) {
289-
_peer->owner().stories().unregisterPolling(
290-
story,
291-
Data::Stories::Polling::Chat);
292289
_layoutRemoved.fire(i->second.item.get());
293290
// The list widget handles layoutRemoved() synchronously and may
294291
// refresh its height from there, which can reach refreshViewer()
295292
// -> refreshRows() -> fillSections() -> clearStaleLayouts() before
296-
// we get back here, erasing this very entry, so look it up again.
293+
// we get back here, erasing this very entry (and unregistering
294+
// its polling), so look it up again and unregister only if we
295+
// are the ones erasing it.
297296
if (const auto j = _layouts.find(id); j != end(_layouts)) {
297+
_peer->owner().stories().unregisterPolling(
298+
story,
299+
Data::Stories::Polling::Chat);
298300
_layouts.erase(j);
299301
}
300302
}

0 commit comments

Comments
 (0)