// // This file is part of Kepka, // an unofficial desktop version of Telegram messaging app, // see https://github.com/procxx/kepka // // Kepka is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // It is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // In addition, as a special exception, the copyright holders give permission // to link the code of portions of this program with the OpenSSL library. // // Full license: https://github.com/procxx/kepka/blob/master/LICENSE // Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org // Copyright (c) 2017- Kepka Contributors, https://github.com/procxx // #pragma once #include "base/flat_set.h" #include "base/weak_unique_ptr.h" #include "boxes/peer_list_box.h" #include "history/history.h" // 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; // //}; class PeerListRowWithLink : public PeerListRow { public: using PeerListRow::PeerListRow; void setActionLink(const QString &action); void lazyInitialize() override; private: void refreshActionLink(); QSize actionSize() const override; QMargins actionMargins() const override; void paintAction(Painter &p, TimeMs ms, int x, int y, int outerWidth, bool actionSelected) override; 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 _cache; std::map _queries; }; class ChatsListBoxController : public PeerListController, protected base::Subscriber { public: ChatsListBoxController(std::unique_ptr searchController = std::make_unique()); void prepare() override final; std::unique_ptr createSearchRow(not_null peer) override final; protected: class Row : public PeerListRow { public: Row(not_null history) : PeerListRow(history->peer) , _history(history) {} not_null history() const { return _history; } private: not_null _history; }; virtual std::unique_ptr createRow(not_null history) = 0; virtual void prepareViewHook() = 0; virtual void updateRowHook(not_null row) {} virtual QString emptyBoxText() const; private: void rebuildRows(); void checkForEmptyRows(); bool appendRow(not_null history); }; class ContactsBoxController : public PeerListController, protected base::Subscriber { public: ContactsBoxController(std::unique_ptr searchController = std::make_unique()); void prepare() override final; std::unique_ptr createSearchRow(not_null peer) override final; void rowClicked(not_null row) override; protected: virtual std::unique_ptr createRow(not_null user); virtual void prepareViewHook() {} virtual void updateRowHook(not_null row) {} private: void rebuildRows(); void checkForEmptyRows(); bool appendRow(not_null user); }; class EditChatAdminsBoxController : public PeerListController, private base::Subscriber { public: static void Start(not_null chat); EditChatAdminsBoxController(not_null chat); bool allAreAdmins() const; void prepare() override; void rowClicked(not_null row) override; private: void createAllAdminsCheckbox(); void rebuildRows(); std::unique_ptr createRow(not_null user); not_null _chat; int _adminsUpdatedSubscription = 0; class LabeledCheckbox; QPointer _allAdmins; }; class AddParticipantsBoxController : public ContactsBoxController { public: static void Start(not_null chat); static void Start(not_null channel); static void Start(not_null channel, base::flat_set> &&alreadyIn); AddParticipantsBoxController(PeerData *peer); AddParticipantsBoxController(not_null channel, base::flat_set> &&alreadyIn); using ContactsBoxController::ContactsBoxController; void rowClicked(not_null row) override; void itemDeselectedHook(not_null peer) override; protected: void prepareViewHook() override; std::unique_ptr createRow(not_null user) override; private: static void Start(not_null channel, base::flat_set> &&alreadyIn, bool justCreated); int alreadyInCount() const; bool isAlreadyIn(not_null user) const; int fullCount() const; void updateTitle(); PeerData *_peer = nullptr; base::flat_set> _alreadyIn; }; class AddBotToGroupBoxController : public ChatsListBoxController, public base::enable_weak_from_this { public: static void Start(not_null bot); AddBotToGroupBoxController(not_null bot); void rowClicked(not_null row) override; protected: std::unique_ptr createRow(not_null history) override; void prepareViewHook() override; QString emptyBoxText() const override; private: static bool SharingBotGame(not_null bot); bool needToCreateRow(not_null peer) const; bool sharingBotGame() const; QString noResultsText() const; QString descriptionText() const; void updateLabels(); void shareBotGame(not_null chat); void addBotToGroup(not_null chat); not_null _bot; };