| 75 | |
| 76 | Memento::Memento(std::vector<std::shared_ptr<ContentMemento>> stack) |
| 77 | : _stack(std::move(stack)) { |
| 78 | auto topics = base::flat_set<not_null<Data::ForumTopic*>>(); |
| 79 | auto sublists = base::flat_set<not_null<Data::SavedSublist*>>(); |
| 80 | for (auto &entry : _stack) { |
| 81 | if (const auto topic = entry->topic()) { |
| 82 | topics.emplace(topic); |
| 83 | } else if (const auto sublist = entry->sublist()) { |
| 84 | sublists.emplace(sublist); |
| 85 | } |
| 86 | } |
| 87 | for (const auto &topic : topics) { |
| 88 | topic->destroyed( |
| 89 | ) | rpl::on_next([=] { |
| 90 | for (auto i = begin(_stack); i != end(_stack);) { |
| 91 | if (i->get()->topic() == topic) { |
| 92 | i = _stack.erase(i); |
| 93 | } else { |
| 94 | ++i; |
| 95 | } |
| 96 | } |
| 97 | if (_stack.empty()) { |
| 98 | _removeRequests.fire({}); |
| 99 | } |
| 100 | }, _lifetime); |
| 101 | } |
| 102 | for (const auto &sublist : sublists) { |
| 103 | sublist->destroyed( |
| 104 | ) | rpl::on_next([=] { |
| 105 | for (auto i = begin(_stack); i != end(_stack);) { |
| 106 | if (i->get()->sublist() == sublist) { |
| 107 | i = _stack.erase(i); |
| 108 | } else { |
| 109 | ++i; |
| 110 | } |
| 111 | } |
| 112 | if (_stack.empty()) { |
| 113 | _removeRequests.fire({}); |
| 114 | } |
| 115 | }, _lifetime); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | std::vector<std::shared_ptr<ContentMemento>> Memento::DefaultStack( |
| 120 | not_null<PeerData*> peer, |