2017-09-13 17:01:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-13 17:01:23 +00:00
|
|
|
*/
|
|
|
|
#include "info/info_memento.h"
|
|
|
|
|
2017-09-24 15:46:37 +00:00
|
|
|
#include "info/profile/info_profile_widget.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "info/media/info_media_widget.h"
|
2017-11-17 13:23:36 +00:00
|
|
|
#include "info/members/info_members_widget.h"
|
2018-02-22 17:38:00 +00:00
|
|
|
#include "info/channels/info_channels_widget.h"
|
2017-11-03 15:52:53 +00:00
|
|
|
#include "info/common_groups/info_common_groups_widget.h"
|
2018-01-22 19:51:38 +00:00
|
|
|
#include "info/feed/info_feed_profile_widget.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "info/settings/info_settings_widget.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "info/info_section_widget.h"
|
|
|
|
#include "info/info_layer_widget.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-11-17 13:23:36 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
2019-01-18 12:27:37 +00:00
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "auth_session.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
Memento::Memento(PeerId peerId)
|
|
|
|
: Memento(peerId, Section::Type::Profile) {
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
Memento::Memento(PeerId peerId, Section section)
|
2017-11-03 18:26:14 +00:00
|
|
|
: Memento(DefaultStack(peerId, section)) {
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
Memento::Memento(not_null<Data::Feed*> feed, Section section)
|
|
|
|
: Memento(DefaultStack(feed, section)) {
|
|
|
|
}
|
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
Memento::Memento(Settings::Tag settings, Section section)
|
|
|
|
: Memento(DefaultStack(settings, section)) {
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:26:14 +00:00
|
|
|
Memento::Memento(std::vector<std::unique_ptr<ContentMemento>> stack)
|
|
|
|
: _stack(std::move(stack)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<ContentMemento>> Memento::DefaultStack(
|
|
|
|
PeerId peerId,
|
|
|
|
Section section) {
|
|
|
|
auto result = std::vector<std::unique_ptr<ContentMemento>>();
|
2017-12-05 14:07:01 +00:00
|
|
|
result.push_back(DefaultContent(peerId, section));
|
2017-11-03 18:26:14 +00:00
|
|
|
return result;
|
2017-10-03 13:05:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
std::vector<std::unique_ptr<ContentMemento>> Memento::DefaultStack(
|
|
|
|
not_null<Data::Feed*> feed,
|
|
|
|
Section section) {
|
|
|
|
auto result = std::vector<std::unique_ptr<ContentMemento>>();
|
|
|
|
result.push_back(DefaultContent(feed, section));
|
|
|
|
return result;
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
std::vector<std::unique_ptr<ContentMemento>> Memento::DefaultStack(
|
|
|
|
Settings::Tag settings,
|
|
|
|
Section section) {
|
|
|
|
auto result = std::vector<std::unique_ptr<ContentMemento>>();
|
|
|
|
result.push_back(std::make_unique<Settings::Memento>(
|
|
|
|
settings.self,
|
|
|
|
section.settingsType()));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
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(Dialogs::Key key) {
|
|
|
|
if (const auto peer = key.peer()) {
|
|
|
|
return Memento(peer->id, DefaultSection(key));
|
|
|
|
}
|
|
|
|
return Memento(key.feed(), DefaultSection(key));
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<ContentMemento> Memento::DefaultContent(
|
2017-09-13 17:01:23 +00:00
|
|
|
PeerId peerId,
|
|
|
|
Section section) {
|
2017-10-31 18:25:22 +00:00
|
|
|
Expects(peerId != 0);
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
auto peer = Auth().data().peer(peerId);
|
2017-10-31 18:25:22 +00:00
|
|
|
if (auto to = peer->migrateTo()) {
|
|
|
|
peer = to;
|
|
|
|
}
|
|
|
|
auto migrated = peer->migrateFrom();
|
|
|
|
peerId = peer->id;
|
|
|
|
auto migratedPeerId = migrated ? migrated->id : PeerId(0);
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
switch (section.type()) {
|
|
|
|
case Section::Type::Profile:
|
2017-10-31 18:25:22 +00:00
|
|
|
return std::make_unique<Profile::Memento>(
|
|
|
|
peerId,
|
|
|
|
migratedPeerId);
|
2017-09-13 17:01:23 +00:00
|
|
|
case Section::Type::Media:
|
|
|
|
return std::make_unique<Media::Memento>(
|
|
|
|
peerId,
|
2017-10-31 18:25:22 +00:00
|
|
|
migratedPeerId,
|
2017-09-13 17:01:23 +00:00
|
|
|
section.mediaType());
|
|
|
|
case Section::Type::CommonGroups:
|
|
|
|
Assert(peerIsUser(peerId));
|
|
|
|
return std::make_unique<CommonGroups::Memento>(
|
|
|
|
peerToUser(peerId));
|
2017-11-17 13:23:36 +00:00
|
|
|
case Section::Type::Members:
|
|
|
|
return std::make_unique<Members::Memento>(
|
|
|
|
peerId,
|
|
|
|
migratedPeerId);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
2017-12-05 14:07:01 +00:00
|
|
|
Unexpected("Wrong section type in Info::Memento::DefaultContent()");
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
std::unique_ptr<ContentMemento> Memento::DefaultContent(
|
|
|
|
not_null<Data::Feed*> feed,
|
|
|
|
Section section) {
|
|
|
|
switch (section.type()) {
|
|
|
|
case Section::Type::Profile:
|
|
|
|
return std::make_unique<FeedProfile::Memento>(feed);
|
2018-02-22 17:38:00 +00:00
|
|
|
case Section::Type::Channels:
|
|
|
|
return std::make_unique<Channels::Memento>(feed);
|
2018-01-22 19:51:38 +00:00
|
|
|
}
|
|
|
|
Unexpected("Wrong feed section in Info::Memento::DefaultContent()");
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
object_ptr<Window::SectionWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::Controller*> controller,
|
2017-09-16 16:53:41 +00:00
|
|
|
Window::Column column,
|
2017-09-13 17:01:23 +00:00
|
|
|
const QRect &geometry) {
|
2017-09-30 18:26:45 +00:00
|
|
|
auto wrap = (column == Window::Column::Third)
|
|
|
|
? Wrap::Side
|
|
|
|
: Wrap::Narrow;
|
|
|
|
auto result = object_ptr<SectionWidget>(
|
2017-09-13 17:01:23 +00:00
|
|
|
parent,
|
|
|
|
controller,
|
2017-09-30 18:26:45 +00:00
|
|
|
wrap,
|
2017-09-13 17:01:23 +00:00
|
|
|
this);
|
2017-09-30 18:26:45 +00:00
|
|
|
result->setGeometry(geometry);
|
|
|
|
return std::move(result);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Window::LayerWidget> Memento::createLayer(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
const QRect &geometry) {
|
|
|
|
if (geometry.width() >= LayerWidget::MinimalSupportedWidth()) {
|
|
|
|
return object_ptr<LayerWidget>(controller, this);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
2017-09-30 18:26:45 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:26:14 +00:00
|
|
|
std::vector<std::unique_ptr<ContentMemento>> Memento::takeStack() {
|
|
|
|
return std::move(_stack);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
Memento::~Memento() = default;
|
|
|
|
|
|
|
|
MoveMemento::MoveMemento(object_ptr<WrapWidget> content)
|
|
|
|
: _content(std::move(content)) {
|
2018-12-04 07:19:28 +00:00
|
|
|
_content->hide();
|
|
|
|
_content->setParent(nullptr);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<Window::SectionWidget> MoveMemento::createWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::Controller*> controller,
|
2017-09-16 16:53:41 +00:00
|
|
|
Window::Column column,
|
2017-09-15 17:34:41 +00:00
|
|
|
const QRect &geometry) {
|
2017-09-30 18:26:45 +00:00
|
|
|
auto wrap = (column == Window::Column::Third)
|
|
|
|
? Wrap::Side
|
|
|
|
: Wrap::Narrow;
|
|
|
|
auto result = object_ptr<SectionWidget>(
|
|
|
|
parent,
|
|
|
|
controller,
|
|
|
|
wrap,
|
|
|
|
this);
|
|
|
|
result->setGeometry(geometry);
|
|
|
|
return std::move(result);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Window::LayerWidget> MoveMemento::createLayer(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
const QRect &geometry) {
|
|
|
|
if (geometry.width() < LayerWidget::MinimalSupportedWidth()) {
|
|
|
|
return nullptr;
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
2017-09-30 18:26:45 +00:00
|
|
|
return object_ptr<LayerWidget>(controller, this);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<WrapWidget> MoveMemento::takeContent(
|
2017-09-15 17:34:41 +00:00
|
|
|
QWidget *parent,
|
|
|
|
Wrap wrap) {
|
|
|
|
Ui::AttachParentChild(parent, _content);
|
|
|
|
_content->setWrap(wrap);
|
|
|
|
return std::move(_content);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
} // namespace Info
|