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"
|
2017-12-04 07:33:33 +00:00
|
|
|
#include "window/window_controller.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class SearchFieldController;
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
class Key {
|
|
|
|
public:
|
|
|
|
Key(not_null<PeerData*> peer);
|
|
|
|
Key(not_null<Data::Feed*> feed);
|
|
|
|
|
|
|
|
PeerData *peer() const;
|
|
|
|
Data::Feed *feed() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
base::variant<not_null<PeerData*>, not_null<Data::Feed*>> _value;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
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,
|
2017-10-31 18:25:22 +00:00
|
|
|
};
|
|
|
|
using MediaType = Storage::SharedMediaType;
|
|
|
|
|
|
|
|
Section(Type type) : _type(type) {
|
|
|
|
Expects(type != Type::Media);
|
|
|
|
}
|
|
|
|
Section(MediaType mediaType)
|
|
|
|
: _type(Type::Media)
|
|
|
|
, _mediaType(mediaType) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Type type() const {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
MediaType mediaType() const {
|
|
|
|
Expects(_type == Type::Media);
|
|
|
|
return _mediaType;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type _type;
|
|
|
|
Storage::SharedMediaType _mediaType;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-12-09 15:13:06 +00:00
|
|
|
class AbstractController : public Window::Navigation {
|
|
|
|
public:
|
|
|
|
AbstractController(not_null<Window::Controller*> parent)
|
|
|
|
: _parent(parent) {
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
PeerId peerId() const {
|
2018-01-22 19:51:38 +00:00
|
|
|
if (const auto peer = key().peer()) {
|
|
|
|
return peer->id;
|
|
|
|
}
|
|
|
|
return PeerId(0);
|
2017-12-09 15:13:06 +00:00
|
|
|
}
|
|
|
|
PeerId migratedPeerId() const {
|
|
|
|
if (auto peer = migrated()) {
|
|
|
|
return peer->id;
|
|
|
|
}
|
|
|
|
return PeerId(0);
|
|
|
|
}
|
2018-01-22 19:51:38 +00:00
|
|
|
Data::Feed *feed() const {
|
|
|
|
return key().feed();
|
|
|
|
}
|
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;
|
|
|
|
not_null<Window::Controller*> parentController() override {
|
|
|
|
return _parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
not_null<Window::Controller*> _parent;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Controller : public AbstractController {
|
2017-10-31 18:25:22 +00:00
|
|
|
public:
|
|
|
|
Controller(
|
|
|
|
not_null<WrapWidget*> widget,
|
|
|
|
not_null<Window::Controller*> window,
|
|
|
|
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
|
|
|
|
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;
|
2017-12-08 08:14:30 +00:00
|
|
|
bool _searchStartsFocused = false;
|
2017-10-31 18:25:22 +00:00
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Info
|