Fix crash in topics disabling.

This commit is contained in:
John Preston 2023-01-21 09:42:57 +04:00
parent 37454b4ff4
commit 7caabb8f5a
8 changed files with 56 additions and 12 deletions

View file

@ -84,6 +84,10 @@ object_ptr<Window::SectionWidget> PinnedMemento::createWidget(
return result;
}
Data::ForumTopic *PinnedMemento::topicForRemoveRequests() const {
return _thread->asTopic();
}
PinnedWidget::PinnedWidget(
QWidget *parent,
not_null<Window::SessionController*> controller,

View file

@ -210,6 +210,8 @@ public:
return _highlightId;
}
Data::ForumTopic *topicForRemoveRequests() const override;
private:
const not_null<Data::Thread*> _thread;
const UniversalMsgId _highlightId = 0;

View file

@ -153,6 +153,11 @@ void RepliesMemento::setFromTopic(not_null<Data::ForumTopic*> topic) {
}
}
Data::ForumTopic *RepliesMemento::topicForRemoveRequests() const {
return _history->peer->forumTopicFor(_rootId);
}
void RepliesMemento::setReadInformation(
MsgId inboxReadTillId,
int unreadCount,

View file

@ -408,6 +408,8 @@ public:
return _replyReturns;
}
Data::ForumTopic *topicForRemoveRequests() const override;
[[nodiscard]] not_null<ListMemento*> list() {
return &_list;
}

View file

@ -112,8 +112,6 @@ public:
rpl::producer<int> desiredHeightValue() const override;
void updateInternalState(not_null<Memento*> memento);
// Float player interface.
bool floatPlayerHandleWheelEvent(QEvent *e) override;
QRect floatPlayerAvailableRect() override;

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h"
#include "data/data_document_media.h"
#include "data/data_document_resolver.h"
#include "data/data_forum_topic.h"
#include "data/data_wall_paper.h"
#include "data/data_web_page.h"
#include "data/data_game.h"
@ -150,13 +151,20 @@ public:
}
[[nodiscard]] virtual StackItemType type() const = 0;
[[nodiscard]] virtual rpl::producer<> removeRequests() const = 0;
[[nodiscard]] rpl::producer<> removeRequests() const {
return rpl::merge(
_thirdSectionRemoveRequests.events(),
sectionRemoveRequests());
}
virtual ~StackItem() = default;
private:
[[nodiscard]] virtual rpl::producer<> sectionRemoveRequests() const = 0;
PeerData *_peer = nullptr;
QPointer<Window::SectionWidget> _thirdSectionWeak;
std::shared_ptr<Window::SectionMemento> _thirdSectionMemento;
rpl::event_stream<> _thirdSectionRemoveRequests;
rpl::lifetime _lifetime;
@ -177,14 +185,16 @@ public:
StackItemType type() const override {
return HistoryStackItem;
}
rpl::producer<> removeRequests() const override {
return rpl::never<>();
}
not_null<History*> history;
MsgId msgId;
QVector<FullMsgId> replyReturns;
private:
rpl::producer<> sectionRemoveRequests() const override {
return rpl::never<>();
}
};
class StackItemSection : public StackItem {
@ -195,14 +205,13 @@ public:
StackItemType type() const override {
return SectionStackItem;
}
rpl::producer<> removeRequests() const override {
return _memento->removeRequests();
}
std::shared_ptr<Window::SectionMemento> takeMemento() {
return std::move(_memento);
}
private:
rpl::producer<> sectionRemoveRequests() const override;
std::shared_ptr<Window::SectionMemento> _memento;
};
@ -210,6 +219,10 @@ private:
void StackItem::setThirdSectionMemento(
std::shared_ptr<Window::SectionMemento> memento) {
_thirdSectionMemento = std::move(memento);
if (const auto memento = _thirdSectionMemento.get()) {
memento->removeRequests(
) | rpl::start_to_stream(_thirdSectionRemoveRequests, _lifetime);
}
}
StackItemSection::StackItemSection(
@ -218,6 +231,13 @@ StackItemSection::StackItemSection(
, _memento(std::move(memento)) {
}
rpl::producer<> StackItemSection::sectionRemoveRequests() const {
if (const auto topic = _memento->topicForRemoveRequests()) {
return rpl::merge(_memento->removeRequests(), topic->destroyed());
}
return _memento->removeRequests();
}
struct MainWidget::SettingBackground {
explicit SettingBackground(const Data::WallPaper &data);

View file

@ -11,6 +11,10 @@ namespace Ui {
class LayerWidget;
} // namespace Ui
namespace Data {
class ForumTopic;
} // namespace Data
namespace Window {
class SessionController;
@ -34,6 +38,9 @@ public:
return false;
}
[[nodiscard]] virtual Data::ForumTopic *topicForRemoveRequests() const {
return nullptr;
}
[[nodiscard]] virtual rpl::producer<> removeRequests() const {
return rpl::never<>();
}

View file

@ -1001,10 +1001,16 @@ void SessionController::showForum(
}
forum->destroyed(
) | rpl::start_with_next([=, history = forum->history()] {
const auto now = activeChatCurrent().owningHistory();
const auto showHistory = !now || (now == history);
closeForum();
showPeerHistory(
history,
{ anim::type::normal, anim::activation::background });
if (showHistory) {
showPeerHistory(history, {
SectionShow::Way::Backward,
anim::type::normal,
anim::activation::background,
});
}
}, _shownForumLifetime);
content()->showForum(forum, params);
}