2017-08-14 12:53:49 +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-08-14 12:53:49 +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-08-14 12:53:49 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-08-14 12:48:11 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
|
|
|
#include "base/flat_set.h"
|
2017-11-30 17:33:27 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2017-08-15 09:41:53 +00:00
|
|
|
// Not used for now.
|
|
|
|
//
|
|
|
|
//class MembersAddButton : public Ui::RippleButton {
|
|
|
|
//public:
|
|
|
|
// MembersAddButton(QWidget *parent, const style::TwoIconButton &st);
|
|
|
|
//
|
|
|
|
//protected:
|
|
|
|
// void paintEvent(QPaintEvent *e) override;
|
|
|
|
//
|
|
|
|
// QImage prepareRippleMask() const override;
|
|
|
|
// QPoint prepareRippleStartPosition() const override;
|
|
|
|
//
|
|
|
|
//private:
|
|
|
|
// const style::TwoIconButton &_st;
|
|
|
|
//
|
|
|
|
//};
|
|
|
|
|
2017-08-14 12:53:49 +00:00
|
|
|
class PeerListRowWithLink : public PeerListRow {
|
|
|
|
public:
|
|
|
|
using PeerListRow::PeerListRow;
|
|
|
|
|
|
|
|
void setActionLink(const QString &action);
|
|
|
|
|
2017-10-10 20:39:44 +00:00
|
|
|
void lazyInitialize(const style::PeerListItem &st) override;
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void refreshActionLink();
|
|
|
|
QSize actionSize() const override;
|
|
|
|
QMargins actionMargins() const override;
|
2017-11-07 17:53:00 +00:00
|
|
|
void paintAction(
|
|
|
|
Painter &p,
|
|
|
|
TimeMs ms,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
bool selected,
|
|
|
|
bool actionSelected) override;
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
QString _action;
|
|
|
|
int _actionWidth = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PeerListGlobalSearchController : public PeerListSearchController, private MTP::Sender {
|
|
|
|
public:
|
|
|
|
PeerListGlobalSearchController();
|
|
|
|
|
|
|
|
void searchQuery(const QString &query) override;
|
|
|
|
bool isLoading() override;
|
|
|
|
bool loadMoreRows() override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool searchInCache();
|
|
|
|
void searchOnServer();
|
|
|
|
void searchDone(const MTPcontacts_Found &result, mtpRequestId requestId);
|
|
|
|
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
std::map<QString, MTPcontacts_Found> _cache;
|
|
|
|
std::map<mtpRequestId, QString> _queries;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
class ChatsListBoxController
|
|
|
|
: public PeerListController
|
|
|
|
, protected base::Subscriber {
|
2017-08-14 12:53:49 +00:00
|
|
|
public:
|
2017-12-05 14:07:01 +00:00
|
|
|
ChatsListBoxController(
|
|
|
|
std::unique_ptr<PeerListSearchController> searchController
|
|
|
|
= std::make_unique<PeerListGlobalSearchController>());
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
void prepare() override final;
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final;
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
class Row : public PeerListRow {
|
|
|
|
public:
|
2018-01-13 12:45:11 +00:00
|
|
|
Row(not_null<History*> history);
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<History*> history() const {
|
2017-08-14 12:53:49 +00:00
|
|
|
return _history;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<History*> _history;
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
};
|
2017-08-17 08:31:24 +00:00
|
|
|
virtual std::unique_ptr<Row> createRow(not_null<History*> history) = 0;
|
2017-08-14 12:53:49 +00:00
|
|
|
virtual void prepareViewHook() = 0;
|
2017-08-17 08:31:24 +00:00
|
|
|
virtual void updateRowHook(not_null<Row*> row) {
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
2017-08-15 09:35:19 +00:00
|
|
|
virtual QString emptyBoxText() const;
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void rebuildRows();
|
|
|
|
void checkForEmptyRows();
|
2017-08-17 08:31:24 +00:00
|
|
|
bool appendRow(not_null<History*> history);
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
class ContactsBoxController
|
|
|
|
: public PeerListController
|
|
|
|
, protected base::Subscriber {
|
2017-08-14 12:53:49 +00:00
|
|
|
public:
|
2019-01-13 13:28:05 +00:00
|
|
|
ContactsBoxController(
|
|
|
|
std::unique_ptr<PeerListSearchController> searchController
|
|
|
|
= std::make_unique<PeerListGlobalSearchController>());
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
void prepare() override final;
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final;
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
protected:
|
2017-08-17 08:31:24 +00:00
|
|
|
virtual std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user);
|
2017-08-14 12:53:49 +00:00
|
|
|
virtual void prepareViewHook() {
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
virtual void updateRowHook(not_null<PeerListRow*> row) {
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void rebuildRows();
|
|
|
|
void checkForEmptyRows();
|
2017-08-17 08:31:24 +00:00
|
|
|
bool appendRow(not_null<UserData*> user);
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
};
|
2017-08-14 12:48:11 +00:00
|
|
|
|
2018-11-30 05:45:22 +00:00
|
|
|
class AddBotToGroupBoxController
|
|
|
|
: public ChatsListBoxController
|
|
|
|
, public base::has_weak_ptr {
|
2017-08-15 09:35:19 +00:00
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
static void Start(not_null<UserData*> bot);
|
2017-08-15 09:35:19 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
AddBotToGroupBoxController(not_null<UserData*> bot);
|
2017-08-15 09:35:19 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
2017-08-15 09:35:19 +00:00
|
|
|
|
|
|
|
protected:
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<Row> createRow(not_null<History*> history) override;
|
2017-08-15 09:35:19 +00:00
|
|
|
void prepareViewHook() override;
|
|
|
|
QString emptyBoxText() const override;
|
|
|
|
|
|
|
|
private:
|
2017-08-17 08:31:24 +00:00
|
|
|
static bool SharingBotGame(not_null<UserData*> bot);
|
2017-08-15 09:35:19 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
bool needToCreateRow(not_null<PeerData*> peer) const;
|
2017-08-15 09:35:19 +00:00
|
|
|
bool sharingBotGame() const;
|
|
|
|
QString noResultsText() const;
|
|
|
|
QString descriptionText() const;
|
|
|
|
void updateLabels();
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void shareBotGame(not_null<PeerData*> chat);
|
|
|
|
void addBotToGroup(not_null<PeerData*> chat);
|
2017-08-15 09:35:19 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<UserData*> _bot;
|
2017-08-15 09:35:19 +00:00
|
|
|
|
|
|
|
};
|
2017-11-07 13:13:41 +00:00
|
|
|
|
2018-11-30 05:45:22 +00:00
|
|
|
class ChooseRecipientBoxController
|
|
|
|
: public ChatsListBoxController
|
|
|
|
, public base::has_weak_ptr {
|
2017-11-07 13:13:41 +00:00
|
|
|
public:
|
|
|
|
ChooseRecipientBoxController(
|
2018-06-04 15:35:11 +00:00
|
|
|
FnMut<void(not_null<PeerData*>)> callback);
|
2017-11-07 13:13:41 +00:00
|
|
|
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
bool respectSavedMessagesChat() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-07 13:13:41 +00:00
|
|
|
protected:
|
|
|
|
void prepareViewHook() override;
|
|
|
|
std::unique_ptr<Row> createRow(
|
|
|
|
not_null<History*> history) override;
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
private:
|
2018-06-04 15:35:11 +00:00
|
|
|
FnMut<void(not_null<PeerData*>)> _callback;
|
2017-11-07 13:13:41 +00:00
|
|
|
|
|
|
|
};
|