| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- /*
- 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"
- #include "base/flat_set.h"
- #include "base/weak_ptr.h"
- #include "base/timer.h"
- #include "mtproto/sender.h"
- class History;
- namespace style {
- struct PeerListItem;
- } // namespace style
- namespace Api {
- struct MessageMoneyRestriction;
- } // namespace Api
- namespace Data {
- class Thread;
- class Forum;
- class ForumTopic;
- } // namespace Data
- namespace Ui {
- struct OutlineSegment;
- } // namespace Ui
- namespace Window {
- class SessionController;
- } // namespace Window
- [[nodiscard]] object_ptr<Ui::BoxContent> PrepareContactsBox(
- not_null<Window::SessionController*> sessionController);
- [[nodiscard]] QBrush PeerListStoriesGradient(const style::PeerList &st);
- [[nodiscard]] std::vector<Ui::OutlineSegment> PeerListStoriesSegments(
- int count,
- int unread,
- const QBrush &unreadBrush);
- class PeerListRowWithLink : public PeerListRow {
- public:
- using PeerListRow::PeerListRow;
- void setActionLink(const QString &action);
- void lazyInitialize(const style::PeerListItem &st) override;
- protected:
- QSize rightActionSize() const override;
- QMargins rightActionMargins() const override;
- void rightActionPaint(
- Painter &p,
- int x,
- int y,
- int outerWidth,
- bool selected,
- bool actionSelected) override;
- private:
- void refreshActionLink();
- QString _action;
- int _actionWidth = 0;
- };
- class PeerListGlobalSearchController : public PeerListSearchController {
- public:
- explicit PeerListGlobalSearchController(not_null<Main::Session*> session);
- 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);
- const not_null<Main::Session*> _session;
- MTP::Sender _api;
- base::Timer _timer;
- QString _query;
- mtpRequestId _requestId = 0;
- std::map<QString, MTPcontacts_Found> _cache;
- std::map<mtpRequestId, QString> _queries;
- };
- struct RecipientMoneyRestrictionError {
- TextWithEntities text;
- };
- [[nodiscard]] RecipientMoneyRestrictionError WriteMoneyRestrictionError(
- not_null<UserData*> user);
- struct RestrictionBadgeCache {
- int paletteVersion = 0;
- int stars = 0;
- QImage badge;
- };
- void PaintRestrictionBadge(
- Painter &p,
- not_null<const style::PeerListItem*> st,
- int stars,
- RestrictionBadgeCache &cache,
- int x,
- int y,
- int outerWidth,
- int size);
- class RecipientRow : public PeerListRow {
- public:
- explicit RecipientRow(
- not_null<PeerData*> peer,
- const style::PeerListItem *maybeLockedSt = nullptr,
- History *maybeHistory = nullptr);
- bool refreshLock(not_null<const style::PeerListItem*> maybeLockedSt);
- [[nodiscard]] static bool ShowLockedError(
- not_null<PeerListController*> controller,
- not_null<PeerListRow*> row,
- Fn<RecipientMoneyRestrictionError(not_null<UserData*>)> error);
- [[nodiscard]] History *maybeHistory() const {
- return _maybeHistory;
- }
- void paintUserpicOverlay(
- Painter &p,
- const style::PeerListItem &st,
- int x,
- int y,
- int outerWidth) override;
- void preloadUserpic() override;
- [[nodiscard]] Api::MessageMoneyRestriction restriction() const;
- void setRestriction(Api::MessageMoneyRestriction restriction);
- private:
- struct Restriction;
- History *_maybeHistory = nullptr;
- const style::PeerListItem *_maybeLockedSt = nullptr;
- std::shared_ptr<Restriction> _restriction;
- };
- void TrackMessageMoneyRestrictionsChanges(
- not_null<PeerListController*> controller,
- rpl::lifetime &lifetime);
- class ChatsListBoxController : public PeerListController {
- public:
- class Row : public RecipientRow {
- public:
- Row(
- not_null<History*> history,
- const style::PeerListItem *maybeLockedSt = nullptr);
- [[nodiscard]] not_null<History*> history() const {
- return maybeHistory();
- }
- };
- ChatsListBoxController(not_null<Main::Session*> session);
- ChatsListBoxController(
- std::unique_ptr<PeerListSearchController> searchController);
- void prepare() override final;
- std::unique_ptr<PeerListRow> createSearchRow(
- not_null<PeerData*> peer) override final;
- protected:
- virtual std::unique_ptr<Row> createRow(not_null<History*> history) = 0;
- virtual void prepareViewHook() = 0;
- virtual void updateRowHook(not_null<Row*> row) {
- }
- virtual QString emptyBoxText() const;
- private:
- void rebuildRows();
- void checkForEmptyRows();
- bool appendRow(not_null<History*> history);
- };
- 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;
- };
- class ContactsBoxController : public PeerListController {
- public:
- explicit ContactsBoxController(not_null<Main::Session*> session);
- ContactsBoxController(
- not_null<Main::Session*> session,
- std::unique_ptr<PeerListSearchController> searchController);
- [[nodiscard]] Main::Session &session() const override;
- void prepare() override final;
- [[nodiscard]] std::unique_ptr<PeerListRow> createSearchRow(
- not_null<PeerData*> peer) override final;
- void rowClicked(not_null<PeerListRow*> row) override;
- bool trackSelectedList() override {
- return !_stories;
- }
- enum class SortMode {
- Alphabet,
- Online,
- };
- void setSortMode(SortMode mode);
- void setStoriesShown(bool shown);
- protected:
- virtual std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user);
- virtual void prepareViewHook() {
- }
- virtual void updateRowHook(not_null<PeerListRow*> row) {
- }
- private:
- void sort();
- void sortByOnline();
- void rebuildRows();
- void checkForEmptyRows();
- bool appendRow(not_null<UserData*> user);
- const not_null<Main::Session*> _session;
- SortMode _sortMode = SortMode::Alphabet;
- base::Timer _sortByOnlineTimer;
- rpl::lifetime _sortByOnlineLifetime;
- std::unique_ptr<PeerListStories> _stories;
- };
- struct ChooseRecipientArgs {
- not_null<Main::Session*> session;
- FnMut<void(not_null<Data::Thread*>)> callback;
- Fn<bool(not_null<Data::Thread*>)> filter;
- using MoneyRestrictionError = RecipientMoneyRestrictionError;
- Fn<MoneyRestrictionError(not_null<UserData*>)> moneyRestrictionError;
- };
- class ChooseRecipientBoxController
- : public ChatsListBoxController
- , public base::has_weak_ptr {
- public:
- ChooseRecipientBoxController(
- not_null<Main::Session*> session,
- FnMut<void(not_null<Data::Thread*>)> callback,
- Fn<bool(not_null<Data::Thread*>)> filter = nullptr);
- explicit ChooseRecipientBoxController(ChooseRecipientArgs &&args);
- Main::Session &session() const override;
- void rowClicked(not_null<PeerListRow*> row) override;
- QString savedMessagesChatStatus() const override;
- protected:
- void prepareViewHook() override;
- std::unique_ptr<Row> createRow(not_null<History*> history) override;
- bool showLockedError(not_null<PeerListRow*> row);
- private:
- const not_null<Main::Session*> _session;
- FnMut<void(not_null<Data::Thread*>)> _callback;
- Fn<bool(not_null<Data::Thread*>)> _filter;
- Fn<RecipientMoneyRestrictionError(
- not_null<UserData*>)> _moneyRestrictionError;
- };
- 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;
- [[nodiscard]] static std::unique_ptr<PeerListRow> MakeRow(
- not_null<Data::ForumTopic*> topic);
- 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;
- PaintRoundImageCallback generatePaintUserpicCallback(
- bool forceRound) override;
- 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;
- };
|