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"
|
2021-12-22 15:14:16 +00:00
|
|
|
#include "base/timer.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2019-09-13 06:06:02 +00:00
|
|
|
class History;
|
|
|
|
|
2022-11-01 04:46:31 +00:00
|
|
|
namespace Data {
|
|
|
|
class Thread;
|
|
|
|
class Forum;
|
|
|
|
class ForumTopic;
|
|
|
|
} // namespace Data
|
|
|
|
|
2023-07-18 16:10:15 +00:00
|
|
|
namespace Ui {
|
|
|
|
struct OutlineSegment;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
namespace Window {
|
2020-10-07 17:08:50 +00:00
|
|
|
class SessionController;
|
2019-07-25 18:55:11 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2020-10-07 17:08:50 +00:00
|
|
|
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareContactsBox(
|
|
|
|
not_null<Window::SessionController*> sessionController);
|
2023-07-18 16:10:15 +00:00
|
|
|
[[nodiscard]] QBrush PeerListStoriesGradient(const style::PeerList &st);
|
|
|
|
[[nodiscard]] std::vector<Ui::OutlineSegment> PeerListStoriesSegments(
|
|
|
|
int count,
|
|
|
|
int unread,
|
|
|
|
const QBrush &unreadBrush);
|
2020-10-07 17:08:50 +00:00
|
|
|
|
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
|
|
|
|
2022-03-29 16:43:33 +00:00
|
|
|
protected:
|
2021-10-13 12:37:38 +00:00
|
|
|
QSize rightActionSize() const override;
|
|
|
|
QMargins rightActionMargins() const override;
|
|
|
|
void rightActionPaint(
|
2017-11-07 17:53:00 +00:00
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
bool selected,
|
|
|
|
bool actionSelected) override;
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2022-03-29 16:43:33 +00:00
|
|
|
private:
|
|
|
|
void refreshActionLink();
|
|
|
|
|
2017-08-14 12:53:49 +00:00
|
|
|
QString _action;
|
|
|
|
int _actionWidth = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
class PeerListGlobalSearchController : public PeerListSearchController {
|
2017-08-14 12:53:49 +00:00
|
|
|
public:
|
2020-12-21 19:43:23 +00:00
|
|
|
explicit PeerListGlobalSearchController(not_null<Main::Session*> session);
|
2017-08-14 12:53:49 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-12-21 19:43:23 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
2017-08-14 12:53:49 +00:00
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
std::map<QString, MTPcontacts_Found> _cache;
|
|
|
|
std::map<mtpRequestId, QString> _queries;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
class ChatsListBoxController : public PeerListController {
|
2017-08-14 12:53:49 +00:00
|
|
|
public:
|
|
|
|
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
|
|
|
|
|
|
|
};
|
2020-03-20 14:56:18 +00:00
|
|
|
|
2020-12-21 19:43:23 +00:00
|
|
|
ChatsListBoxController(not_null<Main::Session*> session);
|
2020-03-20 14:56:18 +00:00
|
|
|
ChatsListBoxController(
|
|
|
|
std::unique_ptr<PeerListSearchController> searchController);
|
|
|
|
|
|
|
|
void prepare() override final;
|
2022-11-01 04:46:31 +00:00
|
|
|
std::unique_ptr<PeerListRow> createSearchRow(
|
|
|
|
not_null<PeerData*> peer) override final;
|
2020-03-20 14:56:18 +00:00
|
|
|
|
|
|
|
protected:
|
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
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-07-18 16:10:15 +00:00
|
|
|
class PeerListStories final {
|
|
|
|
public:
|
|
|
|
PeerListStories(
|
|
|
|
not_null<PeerListController*> controller,
|
|
|
|
not_null<Main::Session*> session);
|
|
|
|
|
|
|
|
void prepare(not_null<PeerListDelegate*> delegate);
|
|
|
|
|
|
|
|
void process(not_null<PeerListRow*> row);
|
|
|
|
bool handleClick(not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Counts {
|
|
|
|
int count = 0;
|
|
|
|
int unread = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void updateColors();
|
|
|
|
void updateFor(uint64 id, int count, int unread);
|
|
|
|
void applyForRow(
|
|
|
|
not_null<PeerListRow*> row,
|
|
|
|
int count,
|
|
|
|
int unread,
|
|
|
|
bool force = false);
|
|
|
|
|
|
|
|
const not_null<PeerListController*> _controller;
|
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
PeerListDelegate *_delegate = nullptr;
|
|
|
|
|
|
|
|
QBrush _unreadBrush;
|
|
|
|
base::flat_map<uint64, Counts> _counts;
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
class ContactsBoxController : public PeerListController {
|
2017-08-14 12:53:49 +00:00
|
|
|
public:
|
2020-12-21 19:43:23 +00:00
|
|
|
explicit ContactsBoxController(not_null<Main::Session*> session);
|
2019-01-13 13:28:05 +00:00
|
|
|
ContactsBoxController(
|
2020-12-21 19:43:23 +00:00
|
|
|
not_null<Main::Session*> session,
|
2019-07-25 18:55:11 +00:00
|
|
|
std::unique_ptr<PeerListSearchController> searchController);
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2020-12-21 19:43:23 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const override;
|
2017-08-14 12:53:49 +00:00
|
|
|
void prepare() override final;
|
2020-12-21 19:43:23 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<PeerListRow> createSearchRow(
|
|
|
|
not_null<PeerData*> peer) override final;
|
2017-08-17 08:31:24 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
2023-07-04 08:29:40 +00:00
|
|
|
bool trackSelectedList() override {
|
2023-07-18 16:10:15 +00:00
|
|
|
return !_stories;
|
2023-07-04 08:29:40 +00:00
|
|
|
}
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2021-12-22 15:14:16 +00:00
|
|
|
enum class SortMode {
|
|
|
|
Alphabet,
|
|
|
|
Online,
|
|
|
|
};
|
|
|
|
void setSortMode(SortMode mode);
|
2023-07-04 08:29:40 +00:00
|
|
|
void setStoriesShown(bool shown);
|
2021-12-22 15:14:16 +00:00
|
|
|
|
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:
|
2021-12-22 15:14:16 +00:00
|
|
|
void sort();
|
|
|
|
void sortByOnline();
|
2017-08-14 12:53:49 +00:00
|
|
|
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
|
|
|
|
2020-12-21 19:43:23 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2021-12-22 15:14:16 +00:00
|
|
|
SortMode _sortMode = SortMode::Alphabet;
|
|
|
|
base::Timer _sortByOnlineTimer;
|
|
|
|
rpl::lifetime _sortByOnlineLifetime;
|
2019-07-25 18:55:11 +00:00
|
|
|
|
2023-07-18 16:10:15 +00:00
|
|
|
std::unique_ptr<PeerListStories> _stories;
|
2023-07-04 08:29:40 +00:00
|
|
|
|
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 ChooseRecipientBoxController
|
|
|
|
: public ChatsListBoxController
|
|
|
|
, public base::has_weak_ptr {
|
2017-11-07 13:13:41 +00:00
|
|
|
public:
|
|
|
|
ChooseRecipientBoxController(
|
2020-12-21 19:43:23 +00:00
|
|
|
not_null<Main::Session*> session,
|
2022-11-01 04:46:31 +00:00
|
|
|
FnMut<void(not_null<Data::Thread*>)> callback,
|
|
|
|
Fn<bool(not_null<Data::Thread*>)> filter = nullptr);
|
2017-11-07 13:13:41 +00:00
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
Main::Session &session() const override;
|
2017-11-07 13:13:41 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
|
2023-10-29 05:52:42 +00:00
|
|
|
QString savedMessagesChatStatus() const override;
|
2017-12-05 14:07:01 +00:00
|
|
|
|
2017-11-07 13:13:41 +00:00
|
|
|
protected:
|
|
|
|
void prepareViewHook() override;
|
2020-09-11 15:33:26 +00:00
|
|
|
std::unique_ptr<Row> createRow(not_null<History*> history) override;
|
2017-11-07 13:13:41 +00:00
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
private:
|
2020-12-21 19:43:23 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2022-11-01 04:46:31 +00:00
|
|
|
FnMut<void(not_null<Data::Thread*>)> _callback;
|
|
|
|
Fn<bool(not_null<Data::Thread*>)> _filter;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class ChooseTopicSearchController : public PeerListSearchController {
|
|
|
|
public:
|
|
|
|
explicit ChooseTopicSearchController(not_null<Data::Forum*> forum);
|
|
|
|
|
|
|
|
void searchQuery(const QString &query) override;
|
|
|
|
bool isLoading() override;
|
|
|
|
bool loadMoreRows() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void searchOnServer();
|
|
|
|
void searchDone(const MTPcontacts_Found &result, mtpRequestId requestId);
|
|
|
|
|
|
|
|
const not_null<Data::Forum*> _forum;
|
|
|
|
MTP::Sender _api;
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
TimeId _offsetDate = 0;
|
|
|
|
MsgId _offsetId = 0;
|
|
|
|
MsgId _offsetTopicId = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class ChooseTopicBoxController final
|
|
|
|
: public PeerListController
|
|
|
|
, public base::has_weak_ptr {
|
|
|
|
public:
|
|
|
|
ChooseTopicBoxController(
|
|
|
|
not_null<Data::Forum*> forum,
|
|
|
|
FnMut<void(not_null<Data::ForumTopic*>)> callback,
|
|
|
|
Fn<bool(not_null<Data::ForumTopic*>)> filter = nullptr);
|
|
|
|
|
|
|
|
Main::Session &session() const override;
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
|
|
|
|
void prepare() override;
|
|
|
|
void loadMoreRows() override;
|
|
|
|
std::unique_ptr<PeerListRow> createSearchRow(PeerListRowId id) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Row final : public PeerListRow {
|
|
|
|
public:
|
|
|
|
explicit Row(not_null<Data::ForumTopic*> topic);
|
|
|
|
|
|
|
|
[[nodiscard]] not_null<Data::ForumTopic*> topic() const {
|
|
|
|
return _topic;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString generateName() override;
|
|
|
|
QString generateShortName() override;
|
2022-12-06 08:12:07 +00:00
|
|
|
PaintRoundImageCallback generatePaintUserpicCallback(
|
|
|
|
bool forceRound) override;
|
2022-11-01 04:46:31 +00:00
|
|
|
|
|
|
|
auto generateNameFirstLetters() const
|
|
|
|
-> const base::flat_set<QChar> & override;
|
|
|
|
auto generateNameWords() const
|
|
|
|
-> const base::flat_set<QString> & override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const not_null<Data::ForumTopic*> _topic;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void refreshRows(bool initial = false);
|
|
|
|
[[nodiscard]] std::unique_ptr<Row> createRow(
|
|
|
|
not_null<Data::ForumTopic*> topic);
|
|
|
|
|
|
|
|
const not_null<Data::Forum*> _forum;
|
|
|
|
FnMut<void(not_null<Data::ForumTopic*>)> _callback;
|
|
|
|
Fn<bool(not_null<Data::ForumTopic*>)> _filter;
|
2017-11-07 13:13:41 +00:00
|
|
|
|
|
|
|
};
|