/* 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 "ui/layers/box_content.h" #include "base/unique_qptr.h" #include "data/data_chat_participant_status.h" namespace Ui { class FlatLabel; class LinkButton; class Checkbox; class Radiobutton; class RadiobuttonGroup; class VerticalLayout; template class SlideWrap; } // namespace Ui class ChannelOwnershipTransfer; class EditTagControl; class EditParticipantBox : public Ui::BoxContent { public: EditParticipantBox( QWidget*, not_null peer, not_null user, bool hasAdminRights); [[nodiscard]] not_null verticalLayout() const; protected: void prepare() override; [[nodiscard]] not_null user() const { return _user; } [[nodiscard]] not_null peer() const { return _peer; } [[nodiscard]] bool amCreator() const; template Widget *addControl(object_ptr widget, QMargins margin = {}); void setCoverMode(bool enabled); bool hasAdminRights() const { return _hasAdminRights; } private: not_null _peer; not_null _user; bool _hasAdminRights = false; class Inner; QPointer _inner; }; struct EditAdminBotFields { QString token; ChatAdminRights existing; }; class EditAdminBox : public EditParticipantBox { public: EditAdminBox( QWidget*, not_null peer, not_null user, ChatAdminRightsInfo rights, const QString &rank, TimeId promotedSince, UserData *by, std::optional addingBot = {}); void setSaveCallback( Fn &rank)> callback) { _saveCallback = std::move(callback); } protected: void prepare() override; private: [[nodiscard]] ChatAdminRightsInfo defaultRights() const; void transferOwnership(); [[nodiscard]] bool canSave() const { return _saveCallback != nullptr; } void finishAddAdmin(); void refreshButtons(); [[nodiscard]] bool canTransferOwnership() const; not_null*> setupTransferButton( not_null container, bool isGroup); const ChatAdminRightsInfo _oldRights; const QString _oldRank; Fn &rank)> _saveCallback; base::weak_qptr _confirmBox; Ui::Checkbox *_addAsAdmin = nullptr; Ui::SlideWrap *_adminControlsWrap = nullptr; EditTagControl *_tagControl = nullptr; Fn _save, _finishSave; TimeId _promotedSince = 0; UserData *_by = nullptr; std::optional _addingBot; std::unique_ptr _ownershipTransfer; }; // Restricted box works with flags in the opposite way. // If some flag is set in the rights then the checkbox is unchecked. class EditRestrictedBox : public EditParticipantBox { public: EditRestrictedBox( QWidget*, not_null peer, not_null user, bool hasAdminRights, ChatRestrictionsInfo rights, const QString &rank, UserData *by, TimeId since); void setSaveCallback( Fn callback) { _saveCallback = std::move(callback); } protected: void prepare() override; private: [[nodiscard]] ChatRestrictionsInfo defaultRights() const; bool canSave() const { return !!_saveCallback; } void showRestrictUntil(); void setRestrictUntil(TimeId until); bool isUntilForever() const; void createUntilGroup(); void createUntilVariants(); TimeId getRealUntilValue() const; const ChatRestrictionsInfo _oldRights; const QString _oldRank; EditTagControl *_tagControl = nullptr; UserData *_by = nullptr; TimeId _since = 0; TimeId _until = 0; Fn _saveCallback; std::shared_ptr _untilGroup; std::vector> _untilVariants; static constexpr auto kUntilOneDay = -1; static constexpr auto kUntilOneWeek = -2; static constexpr auto kUntilCustom = -3; };