Skip to content

Commit

Permalink
Correctly clear story instances on deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jul 21, 2023
1 parent 76f7a87 commit b737012
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Telegram/SourceFiles/data/data_stories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,16 @@ void Stories::applyDeleted(FullStoryId id) {
}
_owner->refreshStoryItemViews(id);
Assert(!_pollingSettings.contains(story.get()));
if (const auto j = _items.find(id.peer); j != end(_items)) {
const auto k = j->second.find(id.story);
if (k != end(j->second)) {
Assert(!k->second.lock());
j->second.erase(k);
if (j->second.empty()) {
_items.erase(j);
}
}
}
if (i->second.empty()) {
_stories.erase(i);
}
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/info/media/info_media_list_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ void ListWidget::refreshRows() {
resizeToWidth(width());
restoreScrollState();
mouseActionUpdate();
update();
}

bool ListWidget::preventAutoHide() const {
Expand Down Expand Up @@ -1942,6 +1943,7 @@ void ListWidget::applyDragSelection(SelectedMap &applyTo) const {

void ListWidget::refreshHeight() {
resize(width(), recountHeight());
update();
}

int ListWidget::recountHeight() {
Expand Down
19 changes: 15 additions & 4 deletions Telegram/SourceFiles/info/stories/info_stories_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For license and copyright information please follow this link:
#include "info/media/info_media_widget.h"
#include "info/media/info_media_list_section.h"
#include "info/info_controller.h"
#include "data/data_changes.h"
#include "data/data_document.h"
#include "data/data_media_types.h"
#include "data/data_session.h"
Expand Down Expand Up @@ -54,6 +55,14 @@ Provider::Provider(not_null<AbstractController*> controller)
layout.second.item->invalidateCache();
}
}, _lifetime);

_peer->session().changes().storyUpdates(
Data::StoryUpdate::Flag::Destroyed
) | rpl::filter([=](const Data::StoryUpdate &update) {
return update.story->peer() == _peer;
}) | rpl::start_with_next([=](const Data::StoryUpdate &update) {
storyRemoved(update.story);
}, _lifetime);
}

Provider::~Provider() {
Expand Down Expand Up @@ -253,15 +262,17 @@ bool Provider::isAfter(
return (a->id < b->id);
}

void Provider::itemRemoved(not_null<const HistoryItem*> item) {
const auto id = StoryIdFromMsgId(item->id);
if (const auto i = _layouts.find(id); i != end(_layouts)) {
void Provider::storyRemoved(not_null<Data::Story*> story) {
Expects(story->peer() == _peer);

if (const auto i = _layouts.find(story->id()); i != end(_layouts)) {
_peer->owner().stories().unregisterPolling(
{ _peer->id, id },
story,
Data::Stories::Polling::Chat);
_layoutRemoved.fire(i->second.item.get());
_layouts.erase(i);
}
_items.remove(story->id());
}

BaseLayout *Provider::getLayout(
Expand Down
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/info/stories/info_stories_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class HistoryItem;
class PeerData;
class History;

namespace Data {
class Story;
} // namespace Data

namespace Info {
class AbstractController;
} // namespace Info
Expand Down Expand Up @@ -97,7 +101,7 @@ class Provider final
not_null<const Media::BaseLayout*> item,
not_null<const Media::BaseLayout*> previous) override;

void itemRemoved(not_null<const HistoryItem*> item);
void storyRemoved(not_null<Data::Story*> story);
void markLayoutsStale();
void clearStaleLayouts();
void clear();
Expand Down

0 comments on commit b737012

Please sign in to comment.