2021-10-13 11:48:45 +00:00
|
|
|
/*
|
|
|
|
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 "boxes/peer_list_box.h"
|
2021-10-13 20:08:13 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2021-10-13 11:48:45 +00:00
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
class SessionNavigation;
|
|
|
|
} // namespace Window
|
|
|
|
|
2021-10-13 14:29:10 +00:00
|
|
|
namespace Ui {
|
|
|
|
class RippleAnimation;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2021-10-13 20:08:13 +00:00
|
|
|
class RequestsBoxController final
|
|
|
|
: public PeerListController
|
|
|
|
, public base::has_weak_ptr {
|
2021-10-13 11:48:45 +00:00
|
|
|
public:
|
|
|
|
RequestsBoxController(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<PeerData*> peer);
|
2021-10-13 14:29:10 +00:00
|
|
|
~RequestsBoxController();
|
2021-10-13 11:48:45 +00:00
|
|
|
|
2021-10-14 10:17:03 +00:00
|
|
|
static void Start(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<PeerData*> peer);
|
|
|
|
|
2021-10-13 11:48:45 +00:00
|
|
|
Main::Session &session() const override;
|
|
|
|
void prepare() override;
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
2021-10-13 14:29:10 +00:00
|
|
|
void rowElementClicked(not_null<PeerListRow*> row, int element) override;
|
2021-10-13 11:48:45 +00:00
|
|
|
void loadMoreRows() override;
|
|
|
|
|
|
|
|
std::unique_ptr<PeerListRow> createSearchRow(
|
|
|
|
not_null<PeerData*> peer) override;
|
|
|
|
|
|
|
|
private:
|
2021-10-13 14:29:10 +00:00
|
|
|
class RowHelper;
|
|
|
|
|
2021-10-13 11:48:45 +00:00
|
|
|
static std::unique_ptr<PeerListSearchController> CreateSearchController(
|
|
|
|
not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
[[nodiscard]] std::unique_ptr<PeerListRow> createRow(
|
|
|
|
not_null<UserData*> user,
|
|
|
|
TimeId date = 0);
|
|
|
|
|
|
|
|
void appendRow(not_null<UserData*> user, TimeId date);
|
|
|
|
void refreshDescription();
|
|
|
|
void processRequest(not_null<UserData*> user, bool approved);
|
2021-10-14 10:47:23 +00:00
|
|
|
void pushRecentRequests();
|
2021-10-13 11:48:45 +00:00
|
|
|
|
|
|
|
void subscribeToMigration();
|
|
|
|
void migrate(not_null<ChatData*> chat, not_null<ChannelData*> channel);
|
|
|
|
|
|
|
|
const not_null<Window::SessionNavigation*> _navigation;
|
2021-10-13 14:29:10 +00:00
|
|
|
const std::unique_ptr<RowHelper> _helper;
|
2021-10-13 11:48:45 +00:00
|
|
|
not_null<PeerData*> _peer;
|
|
|
|
MTP::Sender _api;
|
|
|
|
|
|
|
|
TimeId _offsetDate = 0;
|
|
|
|
UserData *_offsetUser = nullptr;
|
|
|
|
mtpRequestId _loadRequestId = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Members, banned and restricted users server side search.
|
|
|
|
class RequestsBoxSearchController final : public PeerListSearchController {
|
|
|
|
public:
|
|
|
|
RequestsBoxSearchController(not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
void searchQuery(const QString &query) override;
|
|
|
|
bool isLoading() override;
|
|
|
|
bool loadMoreRows() override;
|
|
|
|
|
|
|
|
void removeFromCache(not_null<UserData*> user);
|
|
|
|
[[nodiscard]] TimeId dateForUser(not_null<UserData*> user);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Item {
|
|
|
|
not_null<UserData*> user;
|
|
|
|
TimeId date = 0;
|
|
|
|
};
|
|
|
|
struct CacheEntry {
|
|
|
|
std::vector<Item> items;
|
|
|
|
int requestedCount = 0;
|
|
|
|
};
|
|
|
|
struct Query {
|
|
|
|
QString text;
|
|
|
|
TimeId offsetDate = 0;
|
|
|
|
UserData *offsetUser = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void searchOnServer();
|
|
|
|
bool searchInCache();
|
|
|
|
void searchDone(
|
|
|
|
mtpRequestId requestId,
|
|
|
|
const std::vector<Item> &items,
|
|
|
|
int requestedCount);
|
|
|
|
|
|
|
|
not_null<PeerData*> _peer;
|
|
|
|
MTP::Sender _api;
|
|
|
|
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
TimeId _offsetDate = 0;
|
|
|
|
UserData *_offsetUser = nullptr;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
base::flat_map<QString, CacheEntry> _cache;
|
|
|
|
base::flat_map<mtpRequestId, Query> _queries;
|
|
|
|
base::flat_map<not_null<UserData*>, TimeId> _dates;
|
|
|
|
|
|
|
|
};
|