mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Move channel requests to a layer.
This commit is contained in:
parent
3f3143514e
commit
df45edd816
8 changed files with 498 additions and 23 deletions
|
@ -986,6 +986,8 @@ PRIVATE
|
||||||
info/profile/info_profile_values.h
|
info/profile/info_profile_values.h
|
||||||
info/profile/info_profile_widget.cpp
|
info/profile/info_profile_widget.cpp
|
||||||
info/profile/info_profile_widget.h
|
info/profile/info_profile_widget.h
|
||||||
|
info/requests_list/info_requests_list_widget.cpp
|
||||||
|
info/requests_list/info_requests_list_widget.h
|
||||||
info/saved/info_saved_sublists_widget.cpp
|
info/saved/info_saved_sublists_widget.cpp
|
||||||
info/saved/info_saved_sublists_widget.h
|
info/saved/info_saved_sublists_widget.h
|
||||||
info/settings/info_settings_widget.cpp
|
info/settings/info_settings_widget.cpp
|
||||||
|
|
|
@ -7,27 +7,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "boxes/peers/edit_peer_requests_box.h"
|
#include "boxes/peers/edit_peer_requests_box.h"
|
||||||
|
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "api/api_invite_links.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "base/unixtime.h"
|
||||||
#include "boxes/peer_list_controllers.h"
|
#include "boxes/peer_list_controllers.h"
|
||||||
#include "boxes/peers/edit_participants_box.h" // SubscribeToMigration
|
#include "boxes/peers/edit_participants_box.h" // SubscribeToMigration
|
||||||
#include "boxes/peers/edit_peer_invite_link.h" // PrepareRequestedRowStatus
|
#include "boxes/peers/edit_peer_invite_link.h" // PrepareRequestedRowStatus
|
||||||
#include "boxes/peers/prepare_short_info_box.h" // PrepareShortInfoBox
|
#include "boxes/peers/edit_peer_requests_box.h"
|
||||||
#include "history/view/history_view_requests_bar.h" // kRecentRequestsLimit
|
|
||||||
#include "data/data_peer.h"
|
|
||||||
#include "data/data_user.h"
|
|
||||||
#include "data/data_chat.h"
|
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
|
#include "data/data_chat.h"
|
||||||
|
#include "data/data_peer.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "base/unixtime.h"
|
#include "data/data_user.h"
|
||||||
|
#include "history/view/history_view_requests_bar.h" // kRecentRequestsLimit
|
||||||
|
#include "info/info_controller.h"
|
||||||
|
#include "info/info_memento.h"
|
||||||
|
#include "info/requests_list/info_requests_list_widget.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
#include "ui/painter.h"
|
||||||
#include "ui/round_rect.h"
|
#include "ui/round_rect.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/painter.h"
|
|
||||||
#include "lang/lang_keys.h"
|
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "apiwrap.h"
|
|
||||||
#include "api/api_invite_links.h"
|
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -262,14 +265,10 @@ RequestsBoxController::~RequestsBoxController() = default;
|
||||||
void RequestsBoxController::Start(
|
void RequestsBoxController::Start(
|
||||||
not_null<Window::SessionNavigation*> navigation,
|
not_null<Window::SessionNavigation*> navigation,
|
||||||
not_null<PeerData*> peer) {
|
not_null<PeerData*> peer) {
|
||||||
auto controller = std::make_unique<RequestsBoxController>(
|
navigation->showSection(
|
||||||
navigation,
|
std::make_shared<Info::Memento>(
|
||||||
peer->migrateToOrMe());
|
peer->migrateToOrMe(),
|
||||||
const auto initBox = [=](not_null<PeerListBox*> box) {
|
Info::Section::Type::RequestsList));
|
||||||
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
|
|
||||||
};
|
|
||||||
navigation->parentController()->show(
|
|
||||||
Box<PeerListBox>(std::move(controller), initBox));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Main::Session &RequestsBoxController::session() const {
|
Main::Session &RequestsBoxController::session() const {
|
||||||
|
@ -289,6 +288,58 @@ std::unique_ptr<PeerListRow> RequestsBoxController::createSearchRow(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<PeerListRow> RequestsBoxController::createRestoredRow(
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
if (const auto user = peer->asUser()) {
|
||||||
|
return createRow(user, _dates[user]);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto RequestsBoxController::saveState() const
|
||||||
|
-> std::unique_ptr<PeerListState> {
|
||||||
|
auto result = PeerListController::saveState();
|
||||||
|
|
||||||
|
auto my = std::make_unique<SavedState>();
|
||||||
|
my->dates = _dates;
|
||||||
|
my->offsetDate = _offsetDate;
|
||||||
|
my->offsetUser = _offsetUser;
|
||||||
|
my->allLoaded = _allLoaded;
|
||||||
|
my->wasLoading = (_loadRequestId != 0);
|
||||||
|
if (const auto search = searchController()) {
|
||||||
|
my->searchState = search->saveState();
|
||||||
|
}
|
||||||
|
result->controllerState = std::move(my);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RequestsBoxController::restoreState(
|
||||||
|
std::unique_ptr<PeerListState> state) {
|
||||||
|
auto typeErasedState = state
|
||||||
|
? state->controllerState.get()
|
||||||
|
: nullptr;
|
||||||
|
if (const auto my = dynamic_cast<SavedState*>(typeErasedState)) {
|
||||||
|
if (const auto requestId = base::take(_loadRequestId)) {
|
||||||
|
_api.request(requestId).cancel();
|
||||||
|
}
|
||||||
|
_dates = std::move(my->dates);
|
||||||
|
_offsetDate = my->offsetDate;
|
||||||
|
_offsetUser = my->offsetUser;
|
||||||
|
_allLoaded = my->allLoaded;
|
||||||
|
if (const auto search = searchController()) {
|
||||||
|
search->restoreState(std::move(my->searchState));
|
||||||
|
}
|
||||||
|
if (my->wasLoading) {
|
||||||
|
loadMoreRows();
|
||||||
|
}
|
||||||
|
PeerListController::restoreState(std::move(state));
|
||||||
|
if (delegate()->peerListFullRowsCount() || _allLoaded) {
|
||||||
|
refreshDescription();
|
||||||
|
delegate()->peerListRefreshRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RequestsBoxController::prepare() {
|
void RequestsBoxController::prepare() {
|
||||||
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
||||||
delegate()->peerListSetTitle(_peer->isBroadcast()
|
delegate()->peerListSetTitle(_peer->isBroadcast()
|
||||||
|
@ -356,9 +407,7 @@ void RequestsBoxController::refreshDescription() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestsBoxController::rowClicked(not_null<PeerListRow*> row) {
|
void RequestsBoxController::rowClicked(not_null<PeerListRow*> row) {
|
||||||
_navigation->parentController()->show(PrepareShortInfoBox(
|
_navigation->showPeerInfo(row->peer());
|
||||||
row->peer(),
|
|
||||||
_navigation));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestsBoxController::rowElementClicked(
|
void RequestsBoxController::rowElementClicked(
|
||||||
|
@ -405,6 +454,7 @@ void RequestsBoxController::appendRow(
|
||||||
not_null<UserData*> user,
|
not_null<UserData*> user,
|
||||||
TimeId date) {
|
TimeId date) {
|
||||||
if (!delegate()->peerListFindRow(user->id.value)) {
|
if (!delegate()->peerListFindRow(user->id.value)) {
|
||||||
|
_dates.emplace(user, date);
|
||||||
if (auto row = createRow(user, date)) {
|
if (auto row = createRow(user, date)) {
|
||||||
delegate()->peerListAppendRow(std::move(row));
|
delegate()->peerListAppendRow(std::move(row));
|
||||||
setDescriptionText(QString());
|
setDescriptionText(QString());
|
||||||
|
@ -503,6 +553,7 @@ std::unique_ptr<PeerListRow> RequestsBoxController::createRow(
|
||||||
const auto search = static_cast<RequestsBoxSearchController*>(
|
const auto search = static_cast<RequestsBoxSearchController*>(
|
||||||
searchController());
|
searchController());
|
||||||
date = search->dateForUser(user);
|
date = search->dateForUser(user);
|
||||||
|
_dates.emplace(user, date);
|
||||||
}
|
}
|
||||||
return std::make_unique<Row>(_helper.get(), user, date);
|
return std::make_unique<Row>(_helper.get(), user, date);
|
||||||
}
|
}
|
||||||
|
@ -574,6 +625,36 @@ TimeId RequestsBoxSearchController::dateForUser(not_null<UserData*> user) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto RequestsBoxSearchController::saveState() const
|
||||||
|
-> std::unique_ptr<SavedStateBase> {
|
||||||
|
auto result = std::make_unique<SavedState>();
|
||||||
|
result->query = _query;
|
||||||
|
result->offsetDate = _offsetDate;
|
||||||
|
result->offsetUser = _offsetUser;
|
||||||
|
result->allLoaded = _allLoaded;
|
||||||
|
result->wasLoading = (_requestId != 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RequestsBoxSearchController::restoreState(
|
||||||
|
std::unique_ptr<SavedStateBase> state) {
|
||||||
|
if (auto my = dynamic_cast<SavedState*>(state.get())) {
|
||||||
|
if (auto requestId = base::take(_requestId)) {
|
||||||
|
_api.request(requestId).cancel();
|
||||||
|
}
|
||||||
|
_cache.clear();
|
||||||
|
_queries.clear();
|
||||||
|
|
||||||
|
_allLoaded = my->allLoaded;
|
||||||
|
_offsetDate = my->offsetDate;
|
||||||
|
_offsetUser = my->offsetUser;
|
||||||
|
_query = my->query;
|
||||||
|
if (my->wasLoading) {
|
||||||
|
searchOnServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool RequestsBoxSearchController::searchInCache() {
|
bool RequestsBoxSearchController::searchInCache() {
|
||||||
const auto i = _cache.find(_query);
|
const auto i = _cache.find(_query);
|
||||||
if (i != _cache.cend()) {
|
if (i != _cache.cend()) {
|
||||||
|
|
|
@ -35,15 +35,34 @@ public:
|
||||||
Main::Session &session() const override;
|
Main::Session &session() const override;
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
void rowClicked(not_null<PeerListRow*> row) override;
|
void rowClicked(not_null<PeerListRow*> row) override;
|
||||||
void rowElementClicked(not_null<PeerListRow*> row, int element) override;
|
void rowElementClicked(
|
||||||
|
not_null<PeerListRow*> row,
|
||||||
|
int element) override;
|
||||||
void loadMoreRows() override;
|
void loadMoreRows() override;
|
||||||
|
|
||||||
std::unique_ptr<PeerListRow> createSearchRow(
|
std::unique_ptr<PeerListRow> createSearchRow(
|
||||||
not_null<PeerData*> peer) override;
|
not_null<PeerData*> peer) override;
|
||||||
|
std::unique_ptr<PeerListRow> createRestoredRow(
|
||||||
|
not_null<PeerData*> peer) override;
|
||||||
|
|
||||||
|
std::unique_ptr<PeerListState> saveState() const override;
|
||||||
|
void restoreState(std::unique_ptr<PeerListState> state) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class RowHelper;
|
class RowHelper;
|
||||||
|
|
||||||
|
struct SavedState : SavedStateBase {
|
||||||
|
using SearchStateBase = PeerListSearchController::SavedStateBase;
|
||||||
|
std::unique_ptr<SearchStateBase> searchState;
|
||||||
|
base::flat_map<not_null<UserData*>, TimeId> dates;
|
||||||
|
TimeId offsetDate = 0;
|
||||||
|
UserData *offsetUser = nullptr;
|
||||||
|
bool allLoaded = false;
|
||||||
|
bool wasLoading = false;
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
static std::unique_ptr<PeerListSearchController> CreateSearchController(
|
static std::unique_ptr<PeerListSearchController> CreateSearchController(
|
||||||
not_null<PeerData*> peer);
|
not_null<PeerData*> peer);
|
||||||
|
|
||||||
|
@ -63,6 +82,8 @@ private:
|
||||||
not_null<PeerData*> _peer;
|
not_null<PeerData*> _peer;
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
|
|
||||||
|
base::flat_map<not_null<UserData*>, TimeId> _dates;
|
||||||
|
|
||||||
TimeId _offsetDate = 0;
|
TimeId _offsetDate = 0;
|
||||||
UserData *_offsetUser = nullptr;
|
UserData *_offsetUser = nullptr;
|
||||||
mtpRequestId _loadRequestId = 0;
|
mtpRequestId _loadRequestId = 0;
|
||||||
|
@ -82,7 +103,17 @@ public:
|
||||||
void removeFromCache(not_null<UserData*> user);
|
void removeFromCache(not_null<UserData*> user);
|
||||||
[[nodiscard]] TimeId dateForUser(not_null<UserData*> user);
|
[[nodiscard]] TimeId dateForUser(not_null<UserData*> user);
|
||||||
|
|
||||||
|
std::unique_ptr<SavedStateBase> saveState() const override;
|
||||||
|
void restoreState(std::unique_ptr<SavedStateBase> state) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct SavedState : SavedStateBase {
|
||||||
|
QString query;
|
||||||
|
TimeId offsetDate = 0;
|
||||||
|
UserData *offsetUser = nullptr;
|
||||||
|
bool allLoaded = false;
|
||||||
|
bool wasLoading = false;
|
||||||
|
};
|
||||||
struct Item {
|
struct Item {
|
||||||
not_null<UserData*> user;
|
not_null<UserData*> user;
|
||||||
TimeId date = 0;
|
TimeId date = 0;
|
||||||
|
|
|
@ -296,6 +296,7 @@ void Controller::updateSearchControllers(
|
||||||
: Section::MediaType::kCount;
|
: Section::MediaType::kCount;
|
||||||
const auto hasMediaSearch = isMedia
|
const auto hasMediaSearch = isMedia
|
||||||
&& SharedMediaAllowSearch(mediaType);
|
&& SharedMediaAllowSearch(mediaType);
|
||||||
|
const auto hasRequestsListSearch = (type == Type::RequestsList);
|
||||||
const auto hasCommonGroupsSearch = (type == Type::CommonGroups);
|
const auto hasCommonGroupsSearch = (type == Type::CommonGroups);
|
||||||
const auto hasDownloadsSearch = (type == Type::Downloads);
|
const auto hasDownloadsSearch = (type == Type::Downloads);
|
||||||
const auto hasMembersSearch = (type == Type::Members)
|
const auto hasMembersSearch = (type == Type::Members)
|
||||||
|
@ -312,6 +313,7 @@ void Controller::updateSearchControllers(
|
||||||
_searchController = nullptr;
|
_searchController = nullptr;
|
||||||
}
|
}
|
||||||
if (hasMediaSearch
|
if (hasMediaSearch
|
||||||
|
|| hasRequestsListSearch
|
||||||
|| hasCommonGroupsSearch
|
|| hasCommonGroupsSearch
|
||||||
|| hasDownloadsSearch
|
|| hasDownloadsSearch
|
||||||
|| hasMembersSearch) {
|
|| hasMembersSearch) {
|
||||||
|
|
|
@ -106,6 +106,7 @@ public:
|
||||||
Media,
|
Media,
|
||||||
CommonGroups,
|
CommonGroups,
|
||||||
SimilarChannels,
|
SimilarChannels,
|
||||||
|
RequestsList,
|
||||||
SavedSublists,
|
SavedSublists,
|
||||||
PeerGifts,
|
PeerGifts,
|
||||||
Members,
|
Members,
|
||||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/saved/info_saved_sublists_widget.h"
|
#include "info/saved/info_saved_sublists_widget.h"
|
||||||
#include "info/settings/info_settings_widget.h"
|
#include "info/settings/info_settings_widget.h"
|
||||||
#include "info/similar_channels/info_similar_channels_widget.h"
|
#include "info/similar_channels/info_similar_channels_widget.h"
|
||||||
|
#include "info/requests_list/info_requests_list_widget.h"
|
||||||
#include "info/peer_gifts/info_peer_gifts_widget.h"
|
#include "info/peer_gifts/info_peer_gifts_widget.h"
|
||||||
#include "info/polls/info_polls_results_widget.h"
|
#include "info/polls/info_polls_results_widget.h"
|
||||||
#include "info/info_section_widget.h"
|
#include "info/info_section_widget.h"
|
||||||
|
@ -149,6 +150,8 @@ std::shared_ptr<ContentMemento> Memento::DefaultContent(
|
||||||
case Section::Type::SimilarChannels:
|
case Section::Type::SimilarChannels:
|
||||||
return std::make_shared<SimilarChannels::Memento>(
|
return std::make_shared<SimilarChannels::Memento>(
|
||||||
peer->asChannel());
|
peer->asChannel());
|
||||||
|
case Section::Type::RequestsList:
|
||||||
|
return std::make_shared<RequestsList::Memento>(peer->asChannel());
|
||||||
case Section::Type::PeerGifts:
|
case Section::Type::PeerGifts:
|
||||||
return std::make_shared<PeerGifts::Memento>(peer->asUser());
|
return std::make_shared<PeerGifts::Memento>(peer->asUser());
|
||||||
case Section::Type::SavedSublists:
|
case Section::Type::SavedSublists:
|
||||||
|
|
|
@ -0,0 +1,287 @@
|
||||||
|
/*
|
||||||
|
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/requests_list/info_requests_list_widget.h"
|
||||||
|
|
||||||
|
#include "api/api_chat_participants.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "boxes/peers/edit_peer_requests_box.h"
|
||||||
|
#include "boxes/peer_list_box.h"
|
||||||
|
#include "data/data_channel.h"
|
||||||
|
#include "data/data_peer_values.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
|
#include "info/info_controller.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "ui/widgets/scroll_area.h"
|
||||||
|
#include "ui/search_field_controller.h"
|
||||||
|
#include "ui/ui_utility.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
|
#include "styles/style_info.h"
|
||||||
|
#include "styles/style_widgets.h"
|
||||||
|
#include "boxes/peers/edit_peer_requests_box.h"
|
||||||
|
|
||||||
|
namespace Info::RequestsList {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
class InnerWidget final
|
||||||
|
: public Ui::RpWidget
|
||||||
|
, private PeerListContentDelegate {
|
||||||
|
public:
|
||||||
|
InnerWidget(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Controller*> controller,
|
||||||
|
not_null<ChannelData*> channel);
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<ChannelData*> channel() const {
|
||||||
|
return _channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
|
||||||
|
|
||||||
|
int desiredHeight() const;
|
||||||
|
|
||||||
|
void saveState(not_null<Memento*> memento);
|
||||||
|
void restoreState(not_null<Memento*> memento);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void visibleTopBottomUpdated(
|
||||||
|
int visibleTop,
|
||||||
|
int visibleBottom) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
using ListWidget = PeerListContent;
|
||||||
|
|
||||||
|
// PeerListContentDelegate interface
|
||||||
|
void peerListSetTitle(rpl::producer<QString> title) override;
|
||||||
|
void peerListSetAdditionalTitle(rpl::producer<QString> title) override;
|
||||||
|
bool peerListIsRowChecked(not_null<PeerListRow*> row) override;
|
||||||
|
int peerListSelectedRowsCount() override;
|
||||||
|
void peerListScrollToTop() override;
|
||||||
|
void peerListAddSelectedPeerInBunch(not_null<PeerData*> peer) override;
|
||||||
|
void peerListAddSelectedRowInBunch(not_null<PeerListRow*> row) override;
|
||||||
|
void peerListFinishSelectedRowsBunch() override;
|
||||||
|
void peerListSetDescription(object_ptr<Ui::FlatLabel> description) override;
|
||||||
|
std::shared_ptr<Main::SessionShow> peerListUiShow() override;
|
||||||
|
|
||||||
|
object_ptr<ListWidget> setupList(
|
||||||
|
RpWidget *parent,
|
||||||
|
not_null<RequestsBoxController*> controller);
|
||||||
|
|
||||||
|
const std::shared_ptr<Main::SessionShow> _show;
|
||||||
|
not_null<Controller*> _controller;
|
||||||
|
const not_null<ChannelData*> _channel;
|
||||||
|
std::unique_ptr<RequestsBoxController> _listController;
|
||||||
|
object_ptr<ListWidget> _list;
|
||||||
|
|
||||||
|
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
||||||
|
};
|
||||||
|
|
||||||
|
InnerWidget::InnerWidget(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Controller*> controller,
|
||||||
|
not_null<ChannelData*> channel)
|
||||||
|
: RpWidget(parent)
|
||||||
|
, _show(controller->uiShow())
|
||||||
|
, _controller(controller)
|
||||||
|
, _channel(channel)
|
||||||
|
, _listController(std::make_unique<RequestsBoxController>(
|
||||||
|
controller,
|
||||||
|
_channel))
|
||||||
|
, _list(setupList(this, _listController.get())) {
|
||||||
|
setContent(_list.data());
|
||||||
|
_listController->setDelegate(static_cast<PeerListDelegate*>(this));
|
||||||
|
|
||||||
|
controller->searchFieldController()->queryValue(
|
||||||
|
) | rpl::start_with_next([this](QString &&query) {
|
||||||
|
peerListScrollToTop();
|
||||||
|
content()->searchQueryChanged(std::move(query));
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::visibleTopBottomUpdated(
|
||||||
|
int visibleTop,
|
||||||
|
int visibleBottom) {
|
||||||
|
setChildVisibleTopBottom(_list, visibleTop, visibleBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::saveState(not_null<Memento*> memento) {
|
||||||
|
memento->setListState(_listController->saveState());
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
||||||
|
_listController->restoreState(memento->listState());
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
||||||
|
return _scrollToRequests.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
int InnerWidget::desiredHeight() const {
|
||||||
|
auto desired = 0;
|
||||||
|
desired += _list->fullRowsCount() * st::infoMembersList.item.height;
|
||||||
|
return qMax(height(), desired);
|
||||||
|
}
|
||||||
|
|
||||||
|
object_ptr<InnerWidget::ListWidget> InnerWidget::setupList(
|
||||||
|
RpWidget *parent,
|
||||||
|
not_null<RequestsBoxController*> controller) {
|
||||||
|
auto result = object_ptr<ListWidget>(parent, controller);
|
||||||
|
result->scrollToRequests(
|
||||||
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
||||||
|
auto addmin = (request.ymin < 0) ? 0 : st::infoCommonGroupsMargin.top();
|
||||||
|
auto addmax = (request.ymax < 0) ? 0 : st::infoCommonGroupsMargin.top();
|
||||||
|
_scrollToRequests.fire({
|
||||||
|
request.ymin + addmin,
|
||||||
|
request.ymax + addmax });
|
||||||
|
}, result->lifetime());
|
||||||
|
result->moveToLeft(0, st::infoCommonGroupsMargin.top());
|
||||||
|
|
||||||
|
parent->widthValue(
|
||||||
|
) | rpl::start_with_next([list = result.data()](int newWidth) {
|
||||||
|
list->resizeToWidth(newWidth);
|
||||||
|
}, result->lifetime());
|
||||||
|
|
||||||
|
result->heightValue(
|
||||||
|
) | rpl::start_with_next([parent](int listHeight) {
|
||||||
|
auto newHeight = st::infoCommonGroupsMargin.top()
|
||||||
|
+ listHeight
|
||||||
|
+ st::infoCommonGroupsMargin.bottom();
|
||||||
|
parent->resize(parent->width(), newHeight);
|
||||||
|
}, result->lifetime());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::peerListSetTitle(rpl::producer<QString> title) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::peerListSetAdditionalTitle(rpl::producer<QString> title) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InnerWidget::peerListIsRowChecked(not_null<PeerListRow*> row) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int InnerWidget::peerListSelectedRowsCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::peerListScrollToTop() {
|
||||||
|
_scrollToRequests.fire({ -1, -1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::peerListAddSelectedPeerInBunch(not_null<PeerData*> peer) {
|
||||||
|
Unexpected("Item selection in Info::Profile::Members.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::peerListAddSelectedRowInBunch(not_null<PeerListRow*> row) {
|
||||||
|
Unexpected("Item selection in Info::Profile::Members.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::peerListFinishSelectedRowsBunch() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void InnerWidget::peerListSetDescription(
|
||||||
|
object_ptr<Ui::FlatLabel> description) {
|
||||||
|
description.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Main::SessionShow> InnerWidget::peerListUiShow() {
|
||||||
|
return _show;
|
||||||
|
}
|
||||||
|
|
||||||
|
Memento::Memento(not_null<ChannelData*> channel)
|
||||||
|
: ContentMemento(channel, nullptr, PeerId()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Section Memento::section() const {
|
||||||
|
return Section(Section::Type::RequestsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
not_null<ChannelData*> Memento::channel() const {
|
||||||
|
return peer()->asChannel();
|
||||||
|
}
|
||||||
|
|
||||||
|
object_ptr<ContentWidget> Memento::createWidget(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Controller*> controller,
|
||||||
|
const QRect &geometry) {
|
||||||
|
auto result = object_ptr<Widget>(parent, controller, channel());
|
||||||
|
result->setInternalState(geometry, this);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Memento::setListState(std::unique_ptr<PeerListState> state) {
|
||||||
|
_listState = std::move(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<PeerListState> Memento::listState() {
|
||||||
|
return std::move(_listState);
|
||||||
|
}
|
||||||
|
|
||||||
|
Memento::~Memento() = default;
|
||||||
|
|
||||||
|
Widget::Widget(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Controller*> controller,
|
||||||
|
not_null<ChannelData*> channel)
|
||||||
|
: ContentWidget(parent, controller) {
|
||||||
|
controller->setSearchEnabledByContent(true);
|
||||||
|
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
||||||
|
this,
|
||||||
|
controller,
|
||||||
|
channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<QString> Widget::title() {
|
||||||
|
return tr::lng_manage_peer_requests();
|
||||||
|
}
|
||||||
|
|
||||||
|
not_null<ChannelData*> Widget::channel() const {
|
||||||
|
return _inner->channel();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
||||||
|
if (!controller()->validateMementoPeer(memento)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (auto requestsMemento = dynamic_cast<Memento*>(memento.get())) {
|
||||||
|
if (requestsMemento->channel() == channel()) {
|
||||||
|
restoreState(requestsMemento);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::setInternalState(
|
||||||
|
const QRect &geometry,
|
||||||
|
not_null<Memento*> memento) {
|
||||||
|
setGeometry(geometry);
|
||||||
|
Ui::SendPendingMoveResizeEvents(this);
|
||||||
|
restoreState(memento);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
||||||
|
auto result = std::make_shared<Memento>(channel());
|
||||||
|
saveState(result.get());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::saveState(not_null<Memento*> memento) {
|
||||||
|
memento->setScrollTop(scrollTopSave());
|
||||||
|
_inner->saveState(memento);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::restoreState(not_null<Memento*> memento) {
|
||||||
|
_inner->restoreState(memento);
|
||||||
|
scrollTopRestore(memento->scrollTop());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Info::RequestsList
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "info/info_content_widget.h"
|
||||||
|
|
||||||
|
class ChannelData;
|
||||||
|
struct PeerListState;
|
||||||
|
|
||||||
|
namespace Info::RequestsList {
|
||||||
|
|
||||||
|
class InnerWidget;
|
||||||
|
|
||||||
|
class Memento final : public ContentMemento {
|
||||||
|
public:
|
||||||
|
explicit Memento(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
|
object_ptr<ContentWidget> createWidget(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Controller*> controller,
|
||||||
|
const QRect &geometry) override;
|
||||||
|
|
||||||
|
Section section() const override;
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<ChannelData*> channel() const;
|
||||||
|
|
||||||
|
void setListState(std::unique_ptr<PeerListState> state);
|
||||||
|
std::unique_ptr<PeerListState> listState();
|
||||||
|
|
||||||
|
~Memento();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<PeerListState> _listState;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Widget final : public ContentWidget {
|
||||||
|
public:
|
||||||
|
Widget(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Controller*> controller,
|
||||||
|
not_null<ChannelData*> channel);
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<ChannelData*> channel() const;
|
||||||
|
|
||||||
|
bool showInternal(
|
||||||
|
not_null<ContentMemento*> memento) override;
|
||||||
|
|
||||||
|
void setInternalState(
|
||||||
|
const QRect &geometry,
|
||||||
|
not_null<Memento*> memento);
|
||||||
|
|
||||||
|
rpl::producer<QString> title() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void saveState(not_null<Memento*> memento);
|
||||||
|
void restoreState(not_null<Memento*> memento);
|
||||||
|
|
||||||
|
std::shared_ptr<ContentMemento> doCreateMemento() override;
|
||||||
|
|
||||||
|
InnerWidget *_inner = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Info::RequestsList
|
Loading…
Add table
Reference in a new issue