2017-10-31 18:25:22 +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-10-31 18:25:22 +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-10-31 18:25:22 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <rpl/variable.h>
|
2017-11-06 07:31:18 +00:00
|
|
|
#include "data/data_search_controller.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "settings/settings_common.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class SearchFieldController;
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Info {
|
2018-09-05 19:05:49 +00:00
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
struct Tag {
|
|
|
|
explicit Tag(not_null<UserData*> self) : self(self) {
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<UserData*> self;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Settings
|
2017-10-31 18:25:22 +00:00
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
class Key {
|
|
|
|
public:
|
|
|
|
Key(not_null<PeerData*> peer);
|
2019-04-15 11:54:03 +00:00
|
|
|
//Key(not_null<Data::Feed*> feed); // #feed
|
2018-09-05 19:05:49 +00:00
|
|
|
Key(Settings::Tag settings);
|
2018-01-22 19:51:38 +00:00
|
|
|
|
|
|
|
PeerData *peer() const;
|
2019-04-15 11:54:03 +00:00
|
|
|
//Data::Feed *feed() const; // #feed
|
2018-09-05 19:05:49 +00:00
|
|
|
UserData *settingsSelf() const;
|
2018-01-22 19:51:38 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-05 19:05:49 +00:00
|
|
|
base::variant<
|
|
|
|
not_null<PeerData*>,
|
2019-04-15 11:54:03 +00:00
|
|
|
//not_null<Data::Feed*>, // #feed
|
2018-09-05 19:05:49 +00:00
|
|
|
Settings::Tag> _value;
|
2018-01-22 19:51:38 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
enum class Wrap;
|
|
|
|
class WrapWidget;
|
|
|
|
class Memento;
|
|
|
|
class ContentMemento;
|
|
|
|
|
|
|
|
class Section final {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
Profile,
|
|
|
|
Media,
|
|
|
|
CommonGroups,
|
2017-11-17 13:23:36 +00:00
|
|
|
Members,
|
2019-04-15 11:54:03 +00:00
|
|
|
//Channels, // #feed
|
2018-09-05 19:05:49 +00:00
|
|
|
Settings,
|
2017-10-31 18:25:22 +00:00
|
|
|
};
|
2018-09-05 19:05:49 +00:00
|
|
|
using SettingsType = ::Settings::Type;
|
2017-10-31 18:25:22 +00:00
|
|
|
using MediaType = Storage::SharedMediaType;
|
|
|
|
|
|
|
|
Section(Type type) : _type(type) {
|
2018-09-05 19:05:49 +00:00
|
|
|
Expects(type != Type::Media && type != Type::Settings);
|
2017-10-31 18:25:22 +00:00
|
|
|
}
|
|
|
|
Section(MediaType mediaType)
|
|
|
|
: _type(Type::Media)
|
|
|
|
, _mediaType(mediaType) {
|
|
|
|
}
|
2018-09-05 19:05:49 +00:00
|
|
|
Section(SettingsType settingsType)
|
|
|
|
: _type(Type::Settings)
|
|
|
|
, _settingsType(settingsType) {
|
|
|
|
}
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
Type type() const {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
MediaType mediaType() const {
|
|
|
|
Expects(_type == Type::Media);
|
2018-09-05 19:05:49 +00:00
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
return _mediaType;
|
|
|
|
}
|
2018-09-05 19:05:49 +00:00
|
|
|
SettingsType settingsType() const {
|
|
|
|
Expects(_type == Type::Settings);
|
|
|
|
|
|
|
|
return _settingsType;
|
|
|
|
}
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Type _type;
|
2018-09-05 19:05:49 +00:00
|
|
|
MediaType _mediaType = MediaType();
|
|
|
|
SettingsType _settingsType = SettingsType();
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
class AbstractController : public Window::SessionNavigation {
|
2017-12-09 15:13:06 +00:00
|
|
|
public:
|
2019-06-06 10:21:40 +00:00
|
|
|
AbstractController(not_null<Window::SessionController*> parent);
|
2017-12-09 15:13:06 +00:00
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
virtual Key key() const = 0;
|
2017-12-09 15:13:06 +00:00
|
|
|
virtual PeerData *migrated() const = 0;
|
|
|
|
virtual Section section() const = 0;
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
PeerId peerId() const;
|
|
|
|
PeerId migratedPeerId() const;
|
2019-04-15 11:54:03 +00:00
|
|
|
//Data::Feed *feed() const { // #feed
|
|
|
|
// return key().feed();
|
|
|
|
//}
|
2018-09-05 19:05:49 +00:00
|
|
|
UserData *settingsSelf() const {
|
|
|
|
return key().settingsSelf();
|
|
|
|
}
|
2017-12-09 15:13:06 +00:00
|
|
|
|
|
|
|
virtual void setSearchEnabledByContent(bool enabled) {
|
|
|
|
}
|
|
|
|
virtual rpl::producer<SparseIdsMergedSlice> mediaSource(
|
|
|
|
SparseIdsMergedSlice::UniversalMsgId aroundId,
|
|
|
|
int limitBefore,
|
|
|
|
int limitAfter) const;
|
|
|
|
virtual rpl::producer<QString> mediaSourceQueryValue() const;
|
|
|
|
|
|
|
|
void showSection(
|
|
|
|
Window::SectionMemento &&memento,
|
|
|
|
const Window::SectionShow ¶ms = Window::SectionShow()) override;
|
|
|
|
void showBackFromStack(
|
|
|
|
const Window::SectionShow ¶ms = Window::SectionShow()) override;
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> parentController() override {
|
2017-12-09 15:13:06 +00:00
|
|
|
return _parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> _parent;
|
2017-12-09 15:13:06 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Controller : public AbstractController {
|
2017-10-31 18:25:22 +00:00
|
|
|
public:
|
|
|
|
Controller(
|
|
|
|
not_null<WrapWidget*> widget,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> window,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<ContentMemento*> memento);
|
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
Key key() const override {
|
|
|
|
return _key;
|
2017-10-31 18:25:22 +00:00
|
|
|
}
|
2017-12-09 15:13:06 +00:00
|
|
|
PeerData *migrated() const override {
|
2017-10-31 18:25:22 +00:00
|
|
|
return _migrated;
|
|
|
|
}
|
2017-12-09 15:13:06 +00:00
|
|
|
Section section() const override {
|
2017-10-31 18:25:22 +00:00
|
|
|
return _section;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool validateMementoPeer(
|
|
|
|
not_null<ContentMemento*> memento) const;
|
|
|
|
|
|
|
|
Wrap wrap() const;
|
|
|
|
rpl::producer<Wrap> wrapValue() const;
|
2017-11-03 15:47:08 +00:00
|
|
|
void setSection(not_null<ContentMemento*> memento);
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
Ui::SearchFieldController *searchFieldController() const {
|
|
|
|
return _searchFieldController.get();
|
|
|
|
}
|
2017-12-09 15:13:06 +00:00
|
|
|
void setSearchEnabledByContent(bool enabled) override {
|
2017-11-03 18:26:14 +00:00
|
|
|
_seachEnabledByContent = enabled;
|
|
|
|
}
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<bool> searchEnabledByContent() const;
|
2017-10-31 18:25:22 +00:00
|
|
|
rpl::producer<SparseIdsMergedSlice> mediaSource(
|
|
|
|
SparseIdsMergedSlice::UniversalMsgId aroundId,
|
|
|
|
int limitBefore,
|
2017-12-09 15:13:06 +00:00
|
|
|
int limitAfter) const override;
|
|
|
|
rpl::producer<QString> mediaSourceQueryValue() const override;
|
2017-12-08 08:14:30 +00:00
|
|
|
bool takeSearchStartsFocused() {
|
|
|
|
return base::take(_searchStartsFocused);
|
|
|
|
}
|
2017-10-31 18:25:22 +00:00
|
|
|
|
2018-09-09 17:38:08 +00:00
|
|
|
void setCanSaveChanges(rpl::producer<bool> can);
|
|
|
|
rpl::producer<bool> canSaveChanges() const;
|
2018-09-11 07:46:07 +00:00
|
|
|
bool canSaveChangesNow() const;
|
2018-09-09 17:38:08 +00:00
|
|
|
|
2017-11-03 15:47:08 +00:00
|
|
|
void saveSearchState(not_null<ContentMemento*> memento);
|
|
|
|
|
2017-12-04 07:33:33 +00:00
|
|
|
void showSection(
|
|
|
|
Window::SectionMemento &&memento,
|
|
|
|
const Window::SectionShow ¶ms = Window::SectionShow()) override;
|
|
|
|
void showBackFromStack(
|
|
|
|
const Window::SectionShow ¶ms = Window::SectionShow()) override;
|
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
rpl::lifetime &lifetime() {
|
|
|
|
return _lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Controller();
|
|
|
|
|
|
|
|
private:
|
|
|
|
using SearchQuery = Api::DelayedSearchController::Query;
|
|
|
|
|
2017-11-03 15:47:08 +00:00
|
|
|
void updateSearchControllers(not_null<ContentMemento*> memento);
|
|
|
|
SearchQuery produceSearchQuery(const QString &query) const;
|
2017-11-06 12:14:44 +00:00
|
|
|
void setupMigrationViewer();
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
not_null<WrapWidget*> _widget;
|
2018-01-22 19:51:38 +00:00
|
|
|
Key _key;
|
2017-10-31 18:25:22 +00:00
|
|
|
PeerData *_migrated = nullptr;
|
|
|
|
rpl::variable<Wrap> _wrap;
|
|
|
|
Section _section;
|
|
|
|
|
|
|
|
std::unique_ptr<Ui::SearchFieldController> _searchFieldController;
|
|
|
|
std::unique_ptr<Api::DelayedSearchController> _searchController;
|
2017-11-03 18:26:14 +00:00
|
|
|
rpl::variable<bool> _seachEnabledByContent = false;
|
2018-09-09 17:38:08 +00:00
|
|
|
rpl::variable<bool> _canSaveChanges = false;
|
2017-12-08 08:14:30 +00:00
|
|
|
bool _searchStartsFocused = false;
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Info
|