2018-12-31 20:04:05 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2021-03-22 02:03:24 +01:00
|
|
|
#include "td/telegram/DialogId.h"
|
2020-10-19 00:33:31 +02:00
|
|
|
#include "td/telegram/MessageId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
#include "td/telegram/UserId.h"
|
2021-04-09 01:35:50 +02:00
|
|
|
#include "td/telegram/Version.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2021-01-25 00:07:38 +01:00
|
|
|
class Td;
|
|
|
|
|
2019-03-20 13:28:06 +01:00
|
|
|
class RestrictedRights {
|
|
|
|
static constexpr uint32 CAN_SEND_MESSAGES = 1 << 16;
|
|
|
|
static constexpr uint32 CAN_SEND_MEDIA = 1 << 17;
|
|
|
|
static constexpr uint32 CAN_SEND_STICKERS = 1 << 18;
|
|
|
|
static constexpr uint32 CAN_SEND_ANIMATIONS = 1 << 19;
|
|
|
|
static constexpr uint32 CAN_SEND_GAMES = 1 << 20;
|
|
|
|
static constexpr uint32 CAN_USE_INLINE_BOTS = 1 << 21;
|
|
|
|
static constexpr uint32 CAN_ADD_WEB_PAGE_PREVIEWS = 1 << 22;
|
|
|
|
static constexpr uint32 CAN_SEND_POLLS = 1 << 23;
|
|
|
|
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS = 1 << 24;
|
|
|
|
static constexpr uint32 CAN_INVITE_USERS = 1 << 25;
|
|
|
|
static constexpr uint32 CAN_PIN_MESSAGES = 1 << 26;
|
|
|
|
|
|
|
|
uint32 flags_;
|
|
|
|
|
2019-03-22 13:23:44 +01:00
|
|
|
friend class DialogParticipantStatus;
|
|
|
|
|
2019-03-20 13:28:06 +01:00
|
|
|
public:
|
|
|
|
RestrictedRights(bool can_send_messages, bool can_send_media, bool can_send_stickers, bool can_send_animations,
|
|
|
|
bool can_send_games, bool can_use_inline_bots, bool can_add_web_page_previews, bool can_send_polls,
|
|
|
|
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages);
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::chatPermissions> get_chat_permissions_object() const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::chatBannedRights> get_chat_banned_rights() const;
|
|
|
|
|
|
|
|
bool can_change_info_and_settings() const {
|
|
|
|
return (flags_ & CAN_CHANGE_INFO_AND_SETTINGS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_invite_users() const {
|
2019-09-08 22:40:30 +02:00
|
|
|
return (flags_ & CAN_INVITE_USERS) != 0;
|
2019-03-20 13:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool can_pin_messages() const {
|
|
|
|
return (flags_ & CAN_PIN_MESSAGES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_messages() const {
|
|
|
|
return (flags_ & CAN_SEND_MESSAGES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_media() const {
|
|
|
|
return (flags_ & CAN_SEND_MEDIA) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_stickers() const {
|
|
|
|
return (flags_ & CAN_SEND_STICKERS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_animations() const {
|
|
|
|
return (flags_ & CAN_SEND_ANIMATIONS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_games() const {
|
|
|
|
return (flags_ & CAN_SEND_GAMES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_use_inline_bots() const {
|
|
|
|
return (flags_ & CAN_USE_INLINE_BOTS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_add_web_page_previews() const {
|
|
|
|
return (flags_ & CAN_ADD_WEB_PAGE_PREVIEWS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_polls() const {
|
|
|
|
return (flags_ & CAN_SEND_POLLS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
td::store(flags_, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
|
|
|
td::parse(flags_, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const RestrictedRights &lhs, const RestrictedRights &rhs);
|
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const RestrictedRights &lhs, const RestrictedRights &rhs);
|
|
|
|
|
|
|
|
bool operator!=(const RestrictedRights &lhs, const RestrictedRights &rhs);
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class DialogParticipantStatus {
|
2019-03-15 14:52:55 +01:00
|
|
|
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS_ADMIN = 1 << 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
static constexpr uint32 CAN_POST_MESSAGES = 1 << 1;
|
|
|
|
static constexpr uint32 CAN_EDIT_MESSAGES = 1 << 2;
|
|
|
|
static constexpr uint32 CAN_DELETE_MESSAGES = 1 << 3;
|
2019-03-15 14:52:55 +01:00
|
|
|
static constexpr uint32 CAN_INVITE_USERS_ADMIN = 1 << 4;
|
2019-03-08 02:04:30 +01:00
|
|
|
// static constexpr uint32 CAN_EXPORT_DIALOG_INVITE_LINK = 1 << 5;
|
2018-12-31 20:04:05 +01:00
|
|
|
static constexpr uint32 CAN_RESTRICT_MEMBERS = 1 << 6;
|
2019-03-15 14:52:55 +01:00
|
|
|
static constexpr uint32 CAN_PIN_MESSAGES_ADMIN = 1 << 7;
|
2018-12-31 20:04:05 +01:00
|
|
|
static constexpr uint32 CAN_PROMOTE_MEMBERS = 1 << 8;
|
2020-11-24 00:43:14 +01:00
|
|
|
static constexpr uint32 CAN_MANAGE_CALLS = 1 << 9;
|
2021-02-19 13:58:14 +01:00
|
|
|
static constexpr uint32 CAN_MANAGE_DIALOG = 1 << 10;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static constexpr uint32 CAN_BE_EDITED = 1 << 15;
|
|
|
|
|
|
|
|
static constexpr uint32 CAN_SEND_MESSAGES = 1 << 16;
|
|
|
|
static constexpr uint32 CAN_SEND_MEDIA = 1 << 17;
|
|
|
|
static constexpr uint32 CAN_SEND_STICKERS = 1 << 18;
|
|
|
|
static constexpr uint32 CAN_SEND_ANIMATIONS = 1 << 19;
|
|
|
|
static constexpr uint32 CAN_SEND_GAMES = 1 << 20;
|
|
|
|
static constexpr uint32 CAN_USE_INLINE_BOTS = 1 << 21;
|
|
|
|
static constexpr uint32 CAN_ADD_WEB_PAGE_PREVIEWS = 1 << 22;
|
2019-03-15 14:52:55 +01:00
|
|
|
static constexpr uint32 CAN_SEND_POLLS = 1 << 23;
|
|
|
|
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS_BANNED = 1 << 24;
|
|
|
|
static constexpr uint32 CAN_INVITE_USERS_BANNED = 1 << 25;
|
|
|
|
static constexpr uint32 CAN_PIN_MESSAGES_BANNED = 1 << 26;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static constexpr uint32 IS_MEMBER = 1 << 27;
|
|
|
|
|
2020-09-11 00:49:15 +02:00
|
|
|
static constexpr uint32 IS_ANONYMOUS = 1 << 13;
|
2021-03-22 02:03:24 +01:00
|
|
|
static constexpr uint32 HAS_RANK = 1 << 14;
|
2019-11-11 08:02:23 +01:00
|
|
|
// bits 28-30 reserved for Type
|
2018-12-31 20:04:05 +01:00
|
|
|
static constexpr int TYPE_SHIFT = 28;
|
|
|
|
static constexpr uint32 HAS_UNTIL_DATE = 1u << 31;
|
|
|
|
|
2021-02-19 13:58:14 +01:00
|
|
|
static constexpr uint32 ALL_ADMINISTRATOR_RIGHTS = CAN_CHANGE_INFO_AND_SETTINGS_ADMIN | CAN_POST_MESSAGES |
|
|
|
|
CAN_EDIT_MESSAGES | CAN_DELETE_MESSAGES | CAN_INVITE_USERS_ADMIN |
|
|
|
|
CAN_RESTRICT_MEMBERS | CAN_PIN_MESSAGES_ADMIN |
|
|
|
|
CAN_PROMOTE_MEMBERS | CAN_MANAGE_CALLS | CAN_MANAGE_DIALOG;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-03-22 16:18:46 +01:00
|
|
|
static constexpr uint32 ALL_ADMIN_PERMISSION_RIGHTS =
|
2019-03-22 15:04:01 +01:00
|
|
|
CAN_CHANGE_INFO_AND_SETTINGS_BANNED | CAN_INVITE_USERS_BANNED | CAN_PIN_MESSAGES_BANNED;
|
|
|
|
|
2019-03-22 16:18:46 +01:00
|
|
|
static constexpr uint32 ALL_RESTRICTED_RIGHTS = CAN_SEND_MESSAGES | CAN_SEND_MEDIA | CAN_SEND_STICKERS |
|
|
|
|
CAN_SEND_ANIMATIONS | CAN_SEND_GAMES | CAN_USE_INLINE_BOTS |
|
|
|
|
CAN_ADD_WEB_PAGE_PREVIEWS | CAN_SEND_POLLS;
|
|
|
|
|
|
|
|
static constexpr uint32 ALL_PERMISSION_RIGHTS = ALL_RESTRICTED_RIGHTS | ALL_ADMIN_PERMISSION_RIGHTS;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-04-19 15:08:30 +02:00
|
|
|
enum class Type : int32 { Creator, Administrator, Member, Restricted, Left, Banned };
|
2018-12-31 20:04:05 +01:00
|
|
|
// all fields are logically const, but should be updated in update_restrictions()
|
|
|
|
mutable Type type_;
|
|
|
|
mutable uint32 flags_;
|
|
|
|
mutable int32 until_date_; // restricted and banned only
|
2019-11-11 08:02:23 +01:00
|
|
|
string rank_; // creator and administrator only
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static int32 fix_until_date(int32 date);
|
|
|
|
|
2019-11-11 08:02:23 +01:00
|
|
|
DialogParticipantStatus(Type type, uint32 flags, int32 until_date, string rank);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
public:
|
2020-09-11 00:49:15 +02:00
|
|
|
static DialogParticipantStatus Creator(bool is_member, bool is_anonymous, string rank);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-02-19 13:58:14 +01:00
|
|
|
static DialogParticipantStatus Administrator(bool is_anonymous, string rank, bool can_be_edited,
|
|
|
|
bool can_manage_dialog, bool can_change_info, bool can_post_messages,
|
|
|
|
bool can_edit_messages, bool can_delete_messages, bool can_invite_users,
|
|
|
|
bool can_restrict_members, bool can_pin_messages,
|
2020-11-24 00:43:14 +01:00
|
|
|
bool can_promote_members, bool can_manage_calls);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static DialogParticipantStatus Member();
|
|
|
|
|
|
|
|
static DialogParticipantStatus Restricted(bool is_member, int32 restricted_until_date, bool can_send_messages,
|
|
|
|
bool can_send_media, bool can_send_stickers, bool can_send_animations,
|
|
|
|
bool can_send_games, bool can_use_inline_bots,
|
2019-03-15 14:52:55 +01:00
|
|
|
bool can_add_web_page_previews, bool can_send_polls,
|
|
|
|
bool can_change_info_and_settings, bool can_invite_users,
|
|
|
|
bool can_pin_messages);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static DialogParticipantStatus Left();
|
|
|
|
|
|
|
|
static DialogParticipantStatus Banned(int32 banned_until_date);
|
|
|
|
|
|
|
|
// legacy rights
|
|
|
|
static DialogParticipantStatus GroupAdministrator(bool is_creator);
|
|
|
|
|
|
|
|
// legacy rights
|
|
|
|
static DialogParticipantStatus ChannelAdministrator(bool is_creator, bool is_megagroup);
|
|
|
|
|
2019-03-20 13:28:06 +01:00
|
|
|
RestrictedRights get_restricted_rights() const;
|
|
|
|
|
2019-03-22 16:32:06 +01:00
|
|
|
DialogParticipantStatus apply_restrictions(RestrictedRights default_restrictions, bool is_bot) const;
|
2019-03-22 13:23:44 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
tl_object_ptr<td_api::ChatMemberStatus> get_chat_member_status_object() const;
|
|
|
|
|
2019-03-15 14:52:55 +01:00
|
|
|
tl_object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-03-15 14:52:55 +01:00
|
|
|
tl_object_ptr<telegram_api::chatBannedRights> get_chat_banned_rights() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
// unrestricts user if restriction time expired. Should be called before all privileges checks
|
|
|
|
void update_restrictions() const;
|
|
|
|
|
2021-02-19 13:58:14 +01:00
|
|
|
bool can_manage_dialog() const {
|
|
|
|
return (flags_ & CAN_MANAGE_DIALOG) != 0;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool can_change_info_and_settings() const {
|
2019-03-15 14:52:55 +01:00
|
|
|
return (flags_ & CAN_CHANGE_INFO_AND_SETTINGS_ADMIN) != 0 || (flags_ & CAN_CHANGE_INFO_AND_SETTINGS_BANNED) != 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool can_post_messages() const {
|
|
|
|
return (flags_ & CAN_POST_MESSAGES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_edit_messages() const {
|
|
|
|
return (flags_ & CAN_EDIT_MESSAGES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_delete_messages() const {
|
|
|
|
return (flags_ & CAN_DELETE_MESSAGES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_invite_users() const {
|
2019-03-15 14:52:55 +01:00
|
|
|
return (flags_ & CAN_INVITE_USERS_ADMIN) != 0 || (flags_ & CAN_INVITE_USERS_BANNED) != 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-03-28 00:35:11 +01:00
|
|
|
bool can_manage_invite_links() const {
|
|
|
|
// invite links can be managed, only if administrator was explicitly granted the right
|
|
|
|
return (flags_ & CAN_INVITE_USERS_ADMIN) != 0;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool can_restrict_members() const {
|
|
|
|
return (flags_ & CAN_RESTRICT_MEMBERS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_pin_messages() const {
|
2019-03-15 14:52:55 +01:00
|
|
|
return (flags_ & CAN_PIN_MESSAGES_ADMIN) != 0 || (flags_ & CAN_PIN_MESSAGES_BANNED) != 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool can_promote_members() const {
|
|
|
|
return (flags_ & CAN_PROMOTE_MEMBERS) != 0;
|
|
|
|
}
|
|
|
|
|
2020-11-24 00:43:14 +01:00
|
|
|
bool can_manage_calls() const {
|
|
|
|
return (flags_ & CAN_MANAGE_CALLS) != 0;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool can_be_edited() const {
|
|
|
|
return (flags_ & CAN_BE_EDITED) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_messages() const {
|
|
|
|
return (flags_ & CAN_SEND_MESSAGES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_media() const {
|
|
|
|
return (flags_ & CAN_SEND_MEDIA) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_stickers() const {
|
|
|
|
return (flags_ & CAN_SEND_STICKERS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_animations() const {
|
|
|
|
return (flags_ & CAN_SEND_ANIMATIONS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_games() const {
|
|
|
|
return (flags_ & CAN_SEND_GAMES) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_use_inline_bots() const {
|
|
|
|
return (flags_ & CAN_USE_INLINE_BOTS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_add_web_page_previews() const {
|
|
|
|
return (flags_ & CAN_ADD_WEB_PAGE_PREVIEWS) != 0;
|
|
|
|
}
|
|
|
|
|
2019-03-15 14:52:55 +01:00
|
|
|
bool can_send_polls() const {
|
|
|
|
return (flags_ & CAN_SEND_POLLS) != 0;
|
|
|
|
}
|
|
|
|
|
2019-01-01 22:14:03 +01:00
|
|
|
void set_is_member(bool is_member) {
|
|
|
|
if (is_member) {
|
|
|
|
flags_ |= IS_MEMBER;
|
|
|
|
} else {
|
|
|
|
flags_ &= ~IS_MEMBER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_member() const {
|
|
|
|
return (flags_ & IS_MEMBER) != 0;
|
|
|
|
}
|
|
|
|
|
2019-03-19 16:13:16 +01:00
|
|
|
bool is_left() const {
|
|
|
|
return (flags_ & IS_MEMBER) == 0;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_creator() const {
|
|
|
|
return type_ == Type::Creator;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_administrator() const {
|
|
|
|
return type_ == Type::Administrator || type_ == Type::Creator;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_restricted() const {
|
|
|
|
return type_ == Type::Restricted;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_banned() const {
|
|
|
|
return type_ == Type::Banned;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 get_until_date() const {
|
|
|
|
return until_date_;
|
|
|
|
}
|
|
|
|
|
2020-09-11 00:49:15 +02:00
|
|
|
bool is_anonymous() const {
|
|
|
|
return (flags_ & IS_ANONYMOUS) != 0;
|
|
|
|
}
|
|
|
|
|
2019-11-11 08:02:23 +01:00
|
|
|
const string &get_rank() const {
|
|
|
|
return rank_;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
uint32 stored_flags = flags_ | (static_cast<uint32>(type_) << TYPE_SHIFT);
|
|
|
|
if (until_date_ > 0) {
|
|
|
|
stored_flags |= HAS_UNTIL_DATE;
|
|
|
|
}
|
2019-11-11 08:02:23 +01:00
|
|
|
if (!rank_.empty()) {
|
|
|
|
stored_flags |= HAS_RANK;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
td::store(stored_flags, storer);
|
|
|
|
if (until_date_ > 0) {
|
|
|
|
td::store(until_date_, storer);
|
|
|
|
}
|
2019-11-11 08:02:23 +01:00
|
|
|
if (!rank_.empty()) {
|
|
|
|
td::store(rank_, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
|
|
|
uint32 stored_flags;
|
|
|
|
td::parse(stored_flags, parser);
|
|
|
|
if ((stored_flags & HAS_UNTIL_DATE) != 0) {
|
|
|
|
td::parse(until_date_, parser);
|
|
|
|
stored_flags &= ~HAS_UNTIL_DATE;
|
|
|
|
}
|
2019-11-11 08:02:23 +01:00
|
|
|
if ((stored_flags & HAS_RANK) != 0) {
|
|
|
|
td::parse(rank_, parser);
|
|
|
|
stored_flags &= ~HAS_RANK;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
type_ = static_cast<Type>(stored_flags >> TYPE_SHIFT);
|
|
|
|
flags_ = stored_flags & ((1 << TYPE_SHIFT) - 1);
|
2020-12-06 22:47:48 +01:00
|
|
|
|
|
|
|
if (is_creator()) {
|
|
|
|
flags_ |= ALL_ADMINISTRATOR_RIGHTS | ALL_PERMISSION_RIGHTS;
|
2021-02-19 13:58:14 +01:00
|
|
|
} else if (is_administrator()) {
|
|
|
|
flags_ |= CAN_MANAGE_DIALOG;
|
2020-12-06 22:47:48 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const DialogParticipantStatus &lhs, const DialogParticipantStatus &rhs);
|
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantStatus &status);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const DialogParticipantStatus &lhs, const DialogParticipantStatus &rhs);
|
|
|
|
|
|
|
|
bool operator!=(const DialogParticipantStatus &lhs, const DialogParticipantStatus &rhs);
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantStatus &status);
|
|
|
|
|
|
|
|
struct DialogParticipant {
|
2021-03-22 02:03:24 +01:00
|
|
|
DialogId dialog_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
UserId inviter_user_id;
|
|
|
|
int32 joined_date = 0;
|
|
|
|
DialogParticipantStatus status = DialogParticipantStatus::Left();
|
|
|
|
|
|
|
|
DialogParticipant() = default;
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
DialogParticipant(DialogId dialog_id, UserId inviter_user_id, int32 joined_date, DialogParticipantStatus status);
|
2019-09-18 01:14:24 +02:00
|
|
|
|
2021-02-18 23:38:16 +01:00
|
|
|
DialogParticipant(tl_object_ptr<telegram_api::ChatParticipant> &&participant_ptr, int32 chat_creation_date,
|
|
|
|
bool is_creator);
|
|
|
|
|
2021-03-01 00:33:38 +01:00
|
|
|
explicit DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr);
|
2020-06-30 15:43:44 +02:00
|
|
|
|
2021-03-22 02:03:24 +01:00
|
|
|
static DialogParticipant left(DialogId dialog_id) {
|
|
|
|
return {dialog_id, UserId(), 0, DialogParticipantStatus::Left()};
|
2020-08-03 20:16:08 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 16:46:36 +02:00
|
|
|
bool is_valid() const;
|
|
|
|
|
2019-09-18 01:14:24 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
2021-03-22 02:03:24 +01:00
|
|
|
td::store(dialog_id, storer);
|
2019-09-18 01:14:24 +02:00
|
|
|
td::store(inviter_user_id, storer);
|
|
|
|
td::store(joined_date, storer);
|
|
|
|
td::store(status, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
2021-03-22 02:03:24 +01:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::SupportBannedChannels)) {
|
|
|
|
td::parse(dialog_id, parser);
|
|
|
|
} else {
|
|
|
|
UserId user_id;
|
|
|
|
td::parse(user_id, parser);
|
|
|
|
dialog_id = DialogId(user_id);
|
|
|
|
}
|
2019-09-18 01:14:24 +02:00
|
|
|
td::parse(inviter_user_id, parser);
|
|
|
|
td::parse(joined_date, parser);
|
|
|
|
td::parse(status, parser);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2019-03-12 10:38:37 +01:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant &dialog_participant);
|
|
|
|
|
2021-01-25 00:00:57 +01:00
|
|
|
struct DialogParticipants {
|
|
|
|
int32 total_count_ = 0;
|
|
|
|
vector<DialogParticipant> participants_;
|
|
|
|
|
|
|
|
DialogParticipants() = default;
|
|
|
|
DialogParticipants(int32 total_count, vector<DialogParticipant> &&participants)
|
|
|
|
: total_count_(total_count), participants_(std::move(participants)) {
|
|
|
|
}
|
2021-01-25 00:07:38 +01:00
|
|
|
|
|
|
|
td_api::object_ptr<td_api::chatMembers> get_chat_members_object(Td *td) const;
|
2021-01-25 00:00:57 +01:00
|
|
|
};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class ChannelParticipantsFilter {
|
2021-10-23 20:56:37 +02:00
|
|
|
enum class Type : int32 { Recent, Contacts, Administrators, Search, Mention, Restricted, Banned, Bots };
|
|
|
|
Type type_;
|
|
|
|
string query_;
|
|
|
|
MessageId top_thread_message_id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-03-12 10:38:37 +01:00
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipantsFilter &filter);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit ChannelParticipantsFilter(const tl_object_ptr<td_api::SupergroupMembersFilter> &filter);
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::ChannelParticipantsFilter> get_input_channel_participants_filter() const;
|
|
|
|
|
|
|
|
bool is_administrators() const {
|
2021-10-23 20:56:37 +02:00
|
|
|
return type_ == Type::Administrators;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-01-07 17:30:09 +01:00
|
|
|
|
|
|
|
bool is_bots() const {
|
2021-10-23 20:56:37 +02:00
|
|
|
return type_ == Type::Bots;
|
2019-01-07 17:30:09 +01:00
|
|
|
}
|
2019-03-12 09:58:37 +01:00
|
|
|
|
|
|
|
bool is_recent() const {
|
2021-10-23 20:56:37 +02:00
|
|
|
return type_ == Type::Recent;
|
2019-03-12 09:58:37 +01:00
|
|
|
}
|
2019-03-12 10:38:37 +01:00
|
|
|
|
2019-03-18 03:36:47 +01:00
|
|
|
bool is_contacts() const {
|
2021-10-23 20:56:37 +02:00
|
|
|
return type_ == Type::Contacts;
|
2019-03-18 03:36:47 +01:00
|
|
|
}
|
|
|
|
|
2019-03-12 10:38:37 +01:00
|
|
|
bool is_search() const {
|
2021-10-23 20:56:37 +02:00
|
|
|
return type_ == Type::Search;
|
2019-03-12 10:38:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_restricted() const {
|
2021-10-23 20:56:37 +02:00
|
|
|
return type_ == Type::Restricted;
|
2019-03-12 10:38:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_banned() const {
|
2021-10-23 20:56:37 +02:00
|
|
|
return type_ == Type::Banned;
|
2019-03-12 10:38:37 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2019-03-12 10:38:37 +01:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipantsFilter &filter);
|
|
|
|
|
2020-10-19 00:48:31 +02:00
|
|
|
class DialogParticipantsFilter {
|
|
|
|
public:
|
2020-10-19 13:06:35 +02:00
|
|
|
enum class Type : int32 { Contacts, Administrators, Members, Restricted, Banned, Mention, Bots };
|
2021-10-23 20:56:37 +02:00
|
|
|
Type type_;
|
|
|
|
MessageId top_thread_message_id_;
|
2020-10-19 00:48:31 +02:00
|
|
|
|
2020-10-19 13:06:35 +02:00
|
|
|
explicit DialogParticipantsFilter(Type type, MessageId top_thread_message_id = MessageId())
|
2021-10-23 20:56:37 +02:00
|
|
|
: type_(type), top_thread_message_id_(top_thread_message_id) {
|
2020-10-19 00:48:31 +02:00
|
|
|
}
|
|
|
|
};
|
2018-07-20 02:00:17 +02:00
|
|
|
|
2021-01-16 09:56:02 +01:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantsFilter &filter);
|
|
|
|
|
2018-07-20 02:00:17 +02:00
|
|
|
DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr<td_api::ChatMembersFilter> &filter);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api::ChatMemberStatus> &status);
|
|
|
|
|
2019-03-15 14:52:55 +01:00
|
|
|
DialogParticipantStatus get_dialog_participant_status(bool can_be_edited,
|
2021-10-19 17:11:16 +02:00
|
|
|
tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights,
|
2019-11-11 08:02:23 +01:00
|
|
|
string rank);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
DialogParticipantStatus get_dialog_participant_status(bool is_member,
|
|
|
|
tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
RestrictedRights get_restricted_rights(tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights);
|
2019-03-19 16:13:16 +01:00
|
|
|
|
2019-03-20 18:58:13 +01:00
|
|
|
RestrictedRights get_restricted_rights(const td_api::object_ptr<td_api::chatPermissions> &permissions);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|