2017-06-07 12:59:45 +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-06-07 12:59:45 +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-06-07 12:59:45 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-11-15 00:52:41 +00:00
|
|
|
#include "ui/layers/box_content.h"
|
2019-01-08 10:54:18 +00:00
|
|
|
#include "base/unique_qptr.h"
|
2021-11-21 19:48:08 +00:00
|
|
|
#include "data/data_chat_participant_status.h"
|
2017-06-07 12:59:45 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class FlatLabel;
|
|
|
|
class LinkButton;
|
|
|
|
class Checkbox;
|
2017-07-10 10:43:25 +00:00
|
|
|
class Radiobutton;
|
|
|
|
class RadiobuttonGroup;
|
2022-03-23 14:22:09 +00:00
|
|
|
class VerticalLayout;
|
2019-06-14 12:01:35 +00:00
|
|
|
template <typename Widget>
|
|
|
|
class SlideWrap;
|
2017-06-07 12:59:45 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2019-06-14 14:04:30 +00:00
|
|
|
namespace Core {
|
|
|
|
struct CloudPasswordResult;
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
class PasscodeBox;
|
2017-06-09 16:12:02 +00:00
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
class EditParticipantBox : public Ui::BoxContent {
|
2017-06-07 12:59:45 +00:00
|
|
|
public:
|
2019-01-07 12:55:49 +00:00
|
|
|
EditParticipantBox(
|
|
|
|
QWidget*,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> peer,
|
2019-01-07 12:55:49 +00:00
|
|
|
not_null<UserData*> user,
|
|
|
|
bool hasAdminRights);
|
2017-06-07 12:59:45 +00:00
|
|
|
|
|
|
|
protected:
|
2017-06-09 16:12:02 +00:00
|
|
|
void prepare() override;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2019-07-19 14:11:28 +00:00
|
|
|
[[nodiscard]] not_null<UserData*> user() const {
|
2017-06-07 12:59:45 +00:00
|
|
|
return _user;
|
|
|
|
}
|
2019-07-19 14:11:28 +00:00
|
|
|
[[nodiscard]] not_null<PeerData*> peer() const {
|
2019-01-10 06:26:08 +00:00
|
|
|
return _peer;
|
2017-06-07 12:59:45 +00:00
|
|
|
}
|
2019-07-19 14:11:28 +00:00
|
|
|
[[nodiscard]] bool amCreator() const;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
|
|
|
template <typename Widget>
|
2019-01-08 10:54:18 +00:00
|
|
|
Widget *addControl(object_ptr<Widget> widget, QMargins margin = {});
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2017-06-17 19:51:23 +00:00
|
|
|
bool hasAdminRights() const {
|
|
|
|
return _hasAdminRights;
|
|
|
|
}
|
|
|
|
|
2017-06-07 12:59:45 +00:00
|
|
|
private:
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> _peer;
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<UserData*> _user;
|
2017-06-17 19:51:23 +00:00
|
|
|
bool _hasAdminRights = false;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2017-06-09 16:12:02 +00:00
|
|
|
class Inner;
|
|
|
|
QPointer<Inner> _inner;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-03-24 09:46:44 +00:00
|
|
|
struct EditAdminBotFields {
|
|
|
|
QString token;
|
|
|
|
ChatAdminRights existing;
|
|
|
|
};
|
|
|
|
|
2017-06-07 12:59:45 +00:00
|
|
|
class EditAdminBox : public EditParticipantBox {
|
|
|
|
public:
|
2019-01-07 12:55:49 +00:00
|
|
|
EditAdminBox(
|
|
|
|
QWidget*,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> peer,
|
2019-01-07 12:55:49 +00:00
|
|
|
not_null<UserData*> user,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatAdminRightsInfo rights,
|
2022-03-23 14:22:09 +00:00
|
|
|
const QString &rank,
|
2022-03-24 09:46:44 +00:00
|
|
|
std::optional<EditAdminBotFields> addingBot = {});
|
2019-01-07 12:55:49 +00:00
|
|
|
|
|
|
|
void setSaveCallback(
|
2019-07-19 13:34:09 +00:00
|
|
|
Fn<void(
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatAdminRightsInfo,
|
|
|
|
ChatAdminRightsInfo,
|
2019-07-19 13:34:09 +00:00
|
|
|
const QString &rank)> callback) {
|
2017-07-10 12:29:55 +00:00
|
|
|
_saveCallback = std::move(callback);
|
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
|
2017-06-07 12:59:45 +00:00
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
2021-07-08 10:34:06 +00:00
|
|
|
[[nodiscard]] ChatAdminRightsInfo defaultRights() const;
|
2017-07-05 21:11:49 +00:00
|
|
|
|
2022-03-23 14:22:09 +00:00
|
|
|
not_null<Ui::InputField*> addRankInput(
|
|
|
|
not_null<Ui::VerticalLayout*> container);
|
2019-06-14 12:01:35 +00:00
|
|
|
void transferOwnership();
|
2019-06-14 14:04:30 +00:00
|
|
|
void transferOwnershipChecked();
|
2021-11-26 04:38:00 +00:00
|
|
|
bool handleTransferPasswordError(const QString &error);
|
2019-06-14 14:04:30 +00:00
|
|
|
void requestTransferPassword(not_null<ChannelData*> channel);
|
|
|
|
void sendTransferRequestFrom(
|
|
|
|
QPointer<PasscodeBox> box,
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
const Core::CloudPasswordResult &result);
|
2017-07-10 12:29:55 +00:00
|
|
|
bool canSave() const {
|
2019-07-19 13:34:09 +00:00
|
|
|
return _saveCallback != nullptr;
|
2017-07-10 12:29:55 +00:00
|
|
|
}
|
2022-03-23 14:22:09 +00:00
|
|
|
void finishAddAdmin();
|
|
|
|
void refreshButtons();
|
2019-01-07 12:55:49 +00:00
|
|
|
void refreshAboutAddAdminsText(bool canAddAdmins);
|
2019-06-14 12:01:35 +00:00
|
|
|
bool canTransferOwnership() const;
|
2022-03-23 14:22:09 +00:00
|
|
|
not_null<Ui::SlideWrap<Ui::RpWidget>*> setupTransferButton(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
bool isGroup);
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
const ChatAdminRightsInfo _oldRights;
|
2019-07-19 13:34:09 +00:00
|
|
|
const QString _oldRank;
|
|
|
|
Fn<void(
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatAdminRightsInfo,
|
|
|
|
ChatAdminRightsInfo,
|
2019-07-19 13:34:09 +00:00
|
|
|
const QString &rank)> _saveCallback;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2022-03-23 14:22:09 +00:00
|
|
|
QPointer<Ui::BoxContent> _confirmBox;
|
|
|
|
Ui::Checkbox *_addAsAdmin = nullptr;
|
|
|
|
Ui::SlideWrap<Ui::VerticalLayout> *_adminControlsWrap = nullptr;
|
|
|
|
Ui::InputField *_rank = nullptr;
|
2017-06-07 12:59:45 +00:00
|
|
|
QPointer<Ui::FlatLabel> _aboutAddAdmins;
|
2019-06-14 12:01:35 +00:00
|
|
|
mtpRequestId _checkTransferRequestId = 0;
|
2019-06-15 15:17:22 +00:00
|
|
|
mtpRequestId _transferRequestId = 0;
|
2022-03-23 14:22:09 +00:00
|
|
|
Fn<void()> _save, _finishSave;
|
|
|
|
|
2022-03-24 09:46:44 +00:00
|
|
|
std::optional<EditAdminBotFields> _addingBot;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-09 16:12:02 +00:00
|
|
|
// Restricted box works with flags in the opposite way.
|
|
|
|
// If some flag is set in the rights then the checkbox is unchecked.
|
|
|
|
|
2017-06-07 12:59:45 +00:00
|
|
|
class EditRestrictedBox : public EditParticipantBox {
|
|
|
|
public:
|
2019-01-07 12:55:49 +00:00
|
|
|
EditRestrictedBox(
|
|
|
|
QWidget*,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> peer,
|
2019-01-07 12:55:49 +00:00
|
|
|
not_null<UserData*> user,
|
|
|
|
bool hasAdminRights,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestrictionsInfo rights);
|
2019-01-07 12:55:49 +00:00
|
|
|
|
|
|
|
void setSaveCallback(
|
2021-07-08 10:34:06 +00:00
|
|
|
Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> callback) {
|
2017-07-10 12:29:55 +00:00
|
|
|
_saveCallback = std::move(callback);
|
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
|
2017-06-07 12:59:45 +00:00
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
2021-07-08 10:34:06 +00:00
|
|
|
[[nodiscard]] ChatRestrictionsInfo defaultRights() const;
|
2017-07-05 21:11:49 +00:00
|
|
|
|
2017-07-10 12:29:55 +00:00
|
|
|
bool canSave() const {
|
|
|
|
return !!_saveCallback;
|
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
void showRestrictUntil();
|
2017-07-10 10:43:25 +00:00
|
|
|
void setRestrictUntil(TimeId until);
|
2019-01-04 11:09:48 +00:00
|
|
|
bool isUntilForever() const;
|
2017-07-10 10:43:25 +00:00
|
|
|
void createUntilGroup();
|
|
|
|
void createUntilVariants();
|
|
|
|
TimeId getRealUntilValue() const;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
const ChatRestrictionsInfo _oldRights;
|
2017-07-10 10:43:25 +00:00
|
|
|
TimeId _until = 0;
|
2021-07-08 10:34:06 +00:00
|
|
|
Fn<void(ChatRestrictionsInfo, ChatRestrictionsInfo)> _saveCallback;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2017-07-10 10:43:25 +00:00
|
|
|
std::shared_ptr<Ui::RadiobuttonGroup> _untilGroup;
|
2019-01-08 10:54:18 +00:00
|
|
|
std::vector<base::unique_qptr<Ui::Radiobutton>> _untilVariants;
|
2017-06-07 12:59:45 +00:00
|
|
|
|
2017-07-10 10:43:25 +00:00
|
|
|
static constexpr auto kUntilOneDay = -1;
|
|
|
|
static constexpr auto kUntilOneWeek = -2;
|
|
|
|
static constexpr auto kUntilCustom = -3;
|
|
|
|
|
2017-06-07 12:59:45 +00:00
|
|
|
};
|