/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/info_memento.h" #include "info/profile/info_profile_widget.h" #include "info/media/info_media_widget.h" #include "info/members/info_members_widget.h" //#include "info/channels/info_channels_widget.h" // #feed #include "info/common_groups/info_common_groups_widget.h" //#include "info/feed/info_feed_profile_widget.h" // #feed #include "info/settings/info_settings_widget.h" #include "info/info_section_widget.h" #include "info/info_layer_widget.h" #include "info/info_controller.h" #include "boxes/peer_list_box.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_session.h" #include "auth_session.h" namespace Info { Memento::Memento(PeerId peerId) : Memento(peerId, Section::Type::Profile) { } Memento::Memento(PeerId peerId, Section section) : Memento(DefaultStack(peerId, section)) { } //Memento::Memento(not_null feed, Section section) // #feed //: Memento(DefaultStack(feed, section)) { //} // Memento::Memento(Settings::Tag settings, Section section) : Memento(DefaultStack(settings, section)) { } Memento::Memento(std::vector> stack) : _stack(std::move(stack)) { } std::vector> Memento::DefaultStack( PeerId peerId, Section section) { auto result = std::vector>(); result.push_back(DefaultContent(peerId, section)); return result; } //std::vector> Memento::DefaultStack( // #feed // not_null feed, // Section section) { // auto result = std::vector>(); // result.push_back(DefaultContent(feed, section)); // return result; //} // std::vector> Memento::DefaultStack( Settings::Tag settings, Section section) { auto result = std::vector>(); result.push_back(std::make_unique( settings.self, section.settingsType())); return result; } Section Memento::DefaultSection(not_null peer) { if (peer->isSelf()) { return Section(Section::MediaType::Photo); } return Section(Section::Type::Profile); } // // #feed //Section Memento::DefaultSection(Dialogs::Key key) { // if (const auto peer = key.peer()) { // if (peer->isSelf()) { // return Section(Section::MediaType::Photo); // } // } // return Section(Section::Type::Profile); //} Memento Memento::Default(not_null peer) { return Memento(peer->id, DefaultSection(peer)); } // // #feed //Memento Memento::Default(Dialogs::Key key) { // if (const auto peer = key.peer()) { // return Memento(peer->id, DefaultSection(key)); // } // return Memento(key.feed(), DefaultSection(key)); //} std::unique_ptr Memento::DefaultContent( PeerId peerId, Section section) { Expects(peerId != 0); auto peer = Auth().data().peer(peerId); if (auto to = peer->migrateTo()) { peer = to; } auto migrated = peer->migrateFrom(); peerId = peer->id; auto migratedPeerId = migrated ? migrated->id : PeerId(0); switch (section.type()) { case Section::Type::Profile: return std::make_unique( peerId, migratedPeerId); case Section::Type::Media: return std::make_unique( peerId, migratedPeerId, section.mediaType()); case Section::Type::CommonGroups: Assert(peerIsUser(peerId)); return std::make_unique( peerToUser(peerId)); case Section::Type::Members: return std::make_unique( peerId, migratedPeerId); } Unexpected("Wrong section type in Info::Memento::DefaultContent()"); } // //std::unique_ptr Memento::DefaultContent( // #feed // not_null feed, // Section section) { // switch (section.type()) { // case Section::Type::Profile: // return std::make_unique(feed); // case Section::Type::Channels: // return std::make_unique(feed); // } // Unexpected("Wrong feed section in Info::Memento::DefaultContent()"); //} object_ptr Memento::createWidget( QWidget *parent, not_null controller, Window::Column column, const QRect &geometry) { auto wrap = (column == Window::Column::Third) ? Wrap::Side : Wrap::Narrow; auto result = object_ptr( parent, controller, wrap, this); result->setGeometry(geometry); return std::move(result); } object_ptr Memento::createLayer( not_null controller, const QRect &geometry) { if (geometry.width() >= LayerWidget::MinimalSupportedWidth()) { return object_ptr(controller, this); } return nullptr; } std::vector> Memento::takeStack() { return std::move(_stack); } Memento::~Memento() = default; MoveMemento::MoveMemento(object_ptr content) : _content(std::move(content)) { _content->hide(); _content->setParent(nullptr); } object_ptr MoveMemento::createWidget( QWidget *parent, not_null controller, Window::Column column, const QRect &geometry) { auto wrap = (column == Window::Column::Third) ? Wrap::Side : Wrap::Narrow; auto result = object_ptr( parent, controller, wrap, this); result->setGeometry(geometry); return std::move(result); } object_ptr MoveMemento::createLayer( not_null controller, const QRect &geometry) { if (geometry.width() < LayerWidget::MinimalSupportedWidth()) { return nullptr; } return object_ptr(controller, this); } object_ptr MoveMemento::takeContent( QWidget *parent, Wrap wrap) { Ui::AttachParentChild(parent, _content); _content->setWrap(wrap); return std::move(_content); } } // namespace Info