Wrapped raw SectionMemento with unique_ptr.

This commit is contained in:
23rd 2020-11-22 01:37:05 +03:00 committed by John Preston
parent de6b460754
commit c8643aa1ee
25 changed files with 67 additions and 63 deletions

View File

@ -3412,7 +3412,7 @@ void ApiWrap::jumpToHistoryDate(not_null<PeerData*> peer, const QDate &date) {
// requestMessageAfterDate(feed, date, [=](Data::MessagePosition result) {
// Ui::hideLayer();
// App::wnd()->sessionController()->showSection(
// HistoryFeed::Memento(feed, result));
// std::make_unique<HistoryFeed::Memento>(feed, result));
// });
//}

View File

@ -1000,13 +1000,15 @@ void Controller::fillManageSection() {
st::infoIconBlacklist);
}
if (hasRecentActions) {
auto callback = [=] {
_navigation->showSection(
std::make_unique<AdminLog::SectionMemento>(channel));
};
AddButtonWithCount(
_controls.buttonsLayout,
tr::lng_manage_peer_recent_actions(),
rpl::single(QString()), //Empty count.
[=] {
_navigation->showSection(AdminLog::SectionMemento(channel));
},
std::move(callback),
st::infoIconRecentActions);
}

View File

@ -1591,7 +1591,7 @@ void UpdateApplication() {
if (const auto window = App::wnd()) {
if (const auto controller = window->sessionController()) {
controller->showSection(
Info::Memento(
std::make_unique<Info::Memento>(
Info::Settings::Tag{ controller->session().user() },
Info::Section::SettingsType::Advanced),
Window::SectionShow());

View File

@ -56,7 +56,7 @@ void SharedMediaShowOverview(
return;
}
}
windows.front()->showSection(Info::Memento(
windows.front()->showSection(std::make_unique<Info::Memento>(
history->peer,
Info::Section(type)));
}

View File

@ -1776,7 +1776,7 @@ bool Widget::onCancelSearch() {
if (const auto peer = _searchInChat.peer()) {
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
//} else if (const auto feed = _searchInChat.feed()) { // #feed
// controller()->showSection(HistoryFeed::Memento(feed));
// controller()->showSection(std::make_unique<HistoryFeed::Memento>(feed));
} else {
Unexpected("Empty key in onCancelSearch().");
}
@ -1800,7 +1800,7 @@ void Widget::onCancelSearchInChat() {
if (const auto peer = _searchInChat.peer()) {
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
//} else if (const auto feed = _searchInChat.feed()) { // #feed
// controller()->showSection(HistoryFeed::Memento(feed));
// controller()->showSection(std::make_unique<HistoryFeed::Memento>(feed));
} else {
Unexpected("Empty key in onCancelSearchInPeer().");
}

View File

@ -687,7 +687,7 @@ HistoryWidget::HistoryWidget(
cancelReply(lastKeyboardUsed);
crl::on_main(this, [=, history = action.history]{
controller->showSection(
HistoryView::ScheduledMemento(history));
std::make_unique<HistoryView::ScheduledMemento>(history));
});
} else {
fastShowAtEnd(action.history);
@ -1505,7 +1505,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U
} else if (to.section == Section::Scheduled) {
history->setDraft(Data::DraftKey::Scheduled(), std::move(draft));
controller()->showSection(
HistoryView::ScheduledMemento(history));
std::make_unique<HistoryView::ScheduledMemento>(history));
} else {
history->setLocalDraft(std::move(draft));
if (history == _history) {
@ -2073,7 +2073,7 @@ void HistoryWidget::refreshScheduledToggle() {
_scheduled->show();
_scheduled->addClickHandler([=] {
controller()->showSection(
HistoryView::ScheduledMemento(_history));
std::make_unique<HistoryView::ScheduledMemento>(_history));
});
orderWidgets(); // Raise drag areas to the top.
} else if (_scheduled && !has) {
@ -3883,7 +3883,7 @@ bool HistoryWidget::pushTabbedSelectorToThirdSection(
Core::App().settings().setTabbedReplacedWithInfo(false);
controller()->resizeForThirdSection();
controller()->showSection(
ChatHelpers::TabbedMemento(),
std::make_unique<ChatHelpers::TabbedMemento>(),
params.withThirdColumn());
return true;
}
@ -5382,7 +5382,7 @@ void HistoryWidget::refreshPinnedBarButton(bool many) {
const auto id = _pinnedTracker->currentMessageId();
if (id.message) {
controller()->showSection(
HistoryView::PinnedMemento(
std::make_unique<HistoryView::PinnedMemento>(
_history,
((!_migrated || id.message.channel)
? id.message.msg

View File

@ -1736,7 +1736,7 @@ bool ComposeControls::pushTabbedSelectorToThirdSection(
&st::historyRecordVoiceRippleBgActive);
_window->resizeForThirdSection();
_window->showSection(
ChatHelpers::TabbedMemento(),
std::make_unique<ChatHelpers::TabbedMemento>(),
params.withThirdColumn());
return true;
}

View File

@ -493,15 +493,15 @@ void TopBarWidget::infoClicked() {
} else if (key.folder()) {
_controller->closeFolder();
//} else if (const auto feed = _activeChat.feed()) { // #feed
// _controller->showSection(Info::Memento(
// _controller->showSection(std::make_unique<Info::Memento>(
// feed,
// Info::Section(Info::Section::Type::Profile)));
} else if (key.peer()->isSelf()) {
_controller->showSection(Info::Memento(
_controller->showSection(std::make_unique<Info::Memento>(
key.peer(),
Info::Section(Storage::SharedMediaType::Photo)));
} else if (key.peer()->isRepliesChat()) {
_controller->showSection(Info::Memento(
_controller->showSection(std::make_unique<Info::Memento>(
key.peer(),
Info::Section(Storage::SharedMediaType::Photo)));
} else {

View File

@ -281,7 +281,7 @@ void Channels::showChannelsWithSearch(bool withSearch) {
auto mementoStack = std::vector<std::unique_ptr<ContentMemento>>();
mementoStack.push_back(std::move(contentMemento));
_controller->showSection(
Info::Memento(std::move(mementoStack)));
std::make_unique<Info::Memento>(std::move(mementoStack)));
}
void Channels::visibleTopBottomUpdated(

View File

@ -84,7 +84,7 @@ void Cover::refreshStatusText() {
}();
_status->setRichText(textcmdLink(1, statusText));
_status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
_controller->showSection(Info::Memento(
_controller->showSection(std::make_unique<Info::Memento>(
_feed,
Section::Type::Channels));
}));

View File

@ -123,7 +123,7 @@ PollData *AbstractController::poll() const {
}
void AbstractController::showSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const Window::SectionShow &params) {
return parentController()->showSection(std::move(memento), params);
}
@ -170,7 +170,7 @@ void Controller::setupMigrationViewer() {
const auto section = _section;
InvokeQueued(_widget, [=] {
window->showSection(
Memento(peer, section),
std::make_unique<Memento>(peer, section),
Window::SectionShow(
Window::SectionShow::Way::Backward,
anim::type::instant,
@ -261,9 +261,9 @@ void Controller::saveSearchState(not_null<ContentMemento*> memento) {
}
void Controller::showSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const Window::SectionShow &params) {
if (!_widget->showInternal(&memento, params)) {
if (!_widget->showInternal(memento.get(), params)) {
AbstractController::showSection(std::move(memento), params);
}
}

View File

@ -136,7 +136,7 @@ public:
virtual rpl::producer<QString> mediaSourceQueryValue() const;
void showSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const Window::SectionShow &params = Window::SectionShow()) override;
void showBackFromStack(
const Window::SectionShow &params = Window::SectionShow()) override;
@ -202,7 +202,7 @@ public:
void saveSearchState(not_null<ContentMemento*> memento);
void showSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const Window::SectionShow &params = Window::SectionShow()) override;
void showBackFromStack(
const Window::SectionShow &params = Window::SectionShow()) override;

View File

@ -106,7 +106,7 @@ void LayerWidget::parentResized() {
Ui::FocusPersister persister(this);
restoreFloatPlayerDelegate();
auto memento = MoveMemento(std::move(_content));
auto memento = std::make_unique<MoveMemento>(std::move(_content));
// We want to call hideSpecialLayer synchronously to avoid glitches,
// but we can't destroy LayerStackWidget from its' resizeEvent,

View File

@ -101,8 +101,8 @@ Section Memento::DefaultSection(not_null<PeerData*> peer) {
// return Section(Section::Type::Profile);
//}
Memento Memento::Default(not_null<PeerData*> peer) {
return Memento(peer, DefaultSection(peer));
std::unique_ptr<Memento> Memento::Default(not_null<PeerData*> peer) {
return std::make_unique<Memento>(peer, DefaultSection(peer));
}
// // #feed
//Memento Memento::Default(Dialogs::Key key) {

View File

@ -62,7 +62,7 @@ public:
static Section DefaultSection(not_null<PeerData*> peer);
//static Section DefaultSection(Dialogs::Key key); // #feed
static Memento Default(not_null<PeerData*> peer);
static std::unique_ptr<Memento> Default(not_null<PeerData*> peer);
//static Memento Default(Dialogs::Key key); // #feed
~Memento();

View File

@ -92,7 +92,7 @@ inline auto AddButton(
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
Info::Memento(peer, Section(type)));
std::make_unique<Info::Memento>(peer, Section(type)));
});
return result;
};
@ -111,7 +111,7 @@ inline auto AddCommonGroupsButton(
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
Info::Memento(user, Section::Type::CommonGroups));
std::make_unique<Info::Memento>(user, Section::Type::CommonGroups));
});
return result;
};

View File

@ -843,7 +843,7 @@ object_ptr<Ui::RpWidget> SetupChannelMembers(
lt_count_decimal,
MembersCountValue(channel) | tr::to_count());
auto membersCallback = [=] {
controller->showSection(Info::Memento(
controller->showSection(std::make_unique<Info::Memento>(
channel,
Section::Type::Members));
};

View File

@ -81,7 +81,8 @@ object_ptr<Ui::RpWidget> InnerWidget::setupContent(
_controller->parentController()));
_cover->showSection(
) | rpl::start_with_next([=](Section section) {
_controller->showSection(Info::Memento(_peer, section));
_controller->showSection(
std::make_unique<Info::Memento>(_peer, section));
}, _cover->lifetime());
_cover->setOnlineCount(rpl::single(0));
auto details = SetupDetails(_controller, parent, _peer);

View File

@ -349,7 +349,7 @@ void Members::showMembersWithSearch(bool withSearch) {
auto mementoStack = std::vector<std::unique_ptr<ContentMemento>>();
mementoStack.push_back(std::move(contentMemento));
_controller->showSection(
Info::Memento(std::move(mementoStack)));
std::make_unique<Info::Memento>(std::move(mementoStack)));
}
//void Members::toggleSearch(anim::type animated) {

View File

@ -192,8 +192,8 @@ public:
StackItemType type() const override {
return SectionStackItem;
}
Window::SectionMemento *memento() const {
return _memento.get();
std::unique_ptr<Window::SectionMemento> takeMemento() {
return std::move(_memento);
}
private:
@ -1599,10 +1599,10 @@ void MainWidget::saveSectionInStack() {
}
void MainWidget::showSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const SectionShow &params) {
if (_mainSection && _mainSection->showInternal(
&memento,
memento.get(),
params)) {
if (const auto entry = _mainSection->activeChat(); entry.key) {
_controller->setActiveChatEntry(entry);
@ -1720,7 +1720,7 @@ Window::SectionSlideParams MainWidget::prepareDialogsAnimation() {
}
void MainWidget::showNewSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const SectionShow &params) {
using Column = Window::Column;
@ -1732,7 +1732,7 @@ void MainWidget::showNewSection(
st::columnMinimalWidthThird,
height() - thirdSectionTop);
auto newThirdSection = (Adaptive::ThreeColumn() && params.thirdColumn)
? memento.createWidget(
? memento->createWidget(
this,
_controller,
Column::Third,
@ -1741,7 +1741,7 @@ void MainWidget::showNewSection(
const auto layerRect = parentWidget()->rect();
if (newThirdSection) {
saveInStack = false;
} else if (auto layer = memento.createLayer(_controller, layerRect)) {
} else if (auto layer = memento->createLayer(_controller, layerRect)) {
if (params.activation != anim::activation::background) {
Ui::hideLayer(anim::type::instant);
}
@ -1766,7 +1766,7 @@ void MainWidget::showNewSection(
height() - mainSectionTop);
auto newMainSection = newThirdSection
? nullptr
: memento.createWidget(
: memento->createWidget(
this,
_controller,
Adaptive::OneColumn() ? Column::First : Column::Second,
@ -1777,7 +1777,7 @@ void MainWidget::showNewSection(
if (_a_show.animating()
|| Core::App().passcodeLocked()
|| (params.animated == anim::type::instant)
|| memento.instant()) {
|| memento->instant()) {
return false;
}
if (!Adaptive::OneColumn() && params.way == SectionShow::Way::ClearStack) {
@ -1908,12 +1908,12 @@ void MainWidget::showBackFromStack(
} else if (item->type() == SectionStackItem) {
auto sectionItem = static_cast<StackItemSection*>(item.get());
showNewSection(
std::move(*sectionItem->memento()),
sectionItem->takeMemento(),
params.withWay(SectionShow::Way::Backward));
}
if (_thirdSectionFromStack && _thirdSection) {
_controller->showSection(
std::move(*base::take(_thirdSectionFromStack)),
base::take(_thirdSectionFromStack),
SectionShow(
SectionShow::Way::ClearStack,
anim::type::instant,
@ -2455,7 +2455,7 @@ void MainWidget::updateThirdColumnToCurrentChat(
}
_controller->showSection(
std::move(*thirdSectionForCurrentMainSection(key)),
thirdSectionForCurrentMainSection(key),
params.withThirdColumn());
};
auto switchTabbedFast = [&](not_null<PeerData*> peer) {

View File

@ -134,7 +134,7 @@ public:
int backgroundFromY() const;
void showSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const SectionShow &params);
void updateColumnLayout();
bool stackIsEmpty() const;
@ -271,7 +271,7 @@ private:
Window::SectionSlideParams prepareShowAnimation(
bool willHaveTopBarShadow);
void showNewSection(
Window::SectionMemento &&memento,
std::unique_ptr<Window::SectionMemento> &&memento,
const SectionShow &params);
void dropMainSection(Window::SectionWidget *widget);

View File

@ -650,7 +650,7 @@ void Manager::openNotificationMessage(
Ui::showPeerHistory(history, messageId);
//} else if (messageFeed) { // #feed
// App::wnd()->sessionController()->showSection(
// HistoryFeed::Memento(messageFeed));
// std::make_unique<HistoryFeed::Memento>(messageFeed));
} else {
Ui::showPeerHistory(history, ShowAtUnreadMsgId);
}

View File

@ -714,7 +714,7 @@ void Filler::addTogglesForArchive() {
// const auto controller = _controller;
// const auto feed = _feed;
// _addAction(tr::lng_context_view_feed_info(tr::now), [=] {
// controller->showSection(Info::Memento(
// controller->showSection(std::make_unique<Info::Memento>(
// feed,
// Info::Section(Info::Section::Type::Profile)));
// });

View File

@ -253,12 +253,12 @@ void SessionNavigation::showRepliesForMessage(
const auto channelId = history->channelId();
//const auto item = _session->data().message(channelId, rootId);
//if (!commentId && (!item || !item->repliesAreComments())) {
// showSection(HistoryView::RepliesMemento(history, rootId));
// showSection(std::make_unique<HistoryView::RepliesMemento>(history, rootId));
// return;
//} else if (const auto id = item ? item->commentsItemId() : FullMsgId()) {
// if (const auto commentsItem = _session->data().message(id)) {
// showSection(
// HistoryView::RepliesMemento(commentsItem));
// std::make_unique<HistoryView::RepliesMemento>(commentsItem));
// return;
// }
//}
@ -314,8 +314,9 @@ void SessionNavigation::showRepliesForMessage(
post->setRepliesOutboxReadTill(readTill->v);
}
}
showSection(
HistoryView::RepliesMemento(item, commentId));
showSection(std::make_unique<HistoryView::RepliesMemento>(
item,
commentId));
}
});
}).fail([=](const RPCError &error) {
@ -341,7 +342,7 @@ void SessionNavigation::showPeerInfo(
// Core::App().settings().setThirdSectionInfoEnabled(true);
// Core::App().saveSettingsDelayed();
//}
showSection(Info::Memento(peer), params);
showSection(std::make_unique<Info::Memento>(peer), params);
}
void SessionNavigation::showPeerInfo(
@ -374,7 +375,7 @@ void SessionNavigation::showSettings(
Settings::Type type,
const SectionShow &params) {
showSection(
Info::Memento(
std::make_unique<Info::Memento>(
Info::Settings::Tag{ _session->user() },
Info::Section(type)),
params);
@ -388,7 +389,7 @@ void SessionNavigation::showPollResults(
not_null<PollData*> poll,
FullMsgId contextId,
const SectionShow &params) {
showSection(Info::Memento(poll, contextId), params);
showSection(std::make_unique<Info::Memento>(poll, contextId), params);
}
SessionController::SessionController(
@ -639,9 +640,9 @@ bool SessionController::jumpToChatListEntry(Dialogs::RowDescriptor row) {
return true;
//} else if (const auto feed = row.key.feed()) { // #feed
// if (const auto item = session().data().message(row.fullId)) {
// showSection(HistoryFeed::Memento(feed, item->position()));
// showSection(std::make_unique<HistoryFeed::Memento>(feed, item->position()));
// } else {
// showSection(HistoryFeed::Memento(feed));
// showSection(std::make_unique<HistoryFeed::Memento>(feed));
// }
}
return false;
@ -1086,10 +1087,10 @@ void SessionController::showPeerHistory(
}
void SessionController::showSection(
SectionMemento &&memento,
std::unique_ptr<SectionMemento> &&memento,
const SectionShow &params) {
if (!params.thirdColumn && widget()->showSectionInExistingLayer(
&memento,
memento.get(),
params)) {
return;
}

View File

@ -132,7 +132,7 @@ public:
Main::Session &session() const;
virtual void showSection(
SectionMemento &&memento,
std::unique_ptr<SectionMemento> &&memento,
const SectionShow &params = SectionShow()) = 0;
virtual void showBackFromStack(
const SectionShow &params = SectionShow()) = 0;
@ -301,7 +301,7 @@ public:
bool confirmedLeaveOther = false);
void showSection(
SectionMemento &&memento,
std::unique_ptr<SectionMemento> &&memento,
const SectionShow &params = SectionShow()) override;
void showBackFromStack(
const SectionShow &params = SectionShow()) override;