2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
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)
|
|
|
|
//
|
|
|
|
#include "td/telegram/DialogParticipant.h"
|
|
|
|
|
2021-01-25 00:07:38 +01:00
|
|
|
#include "td/telegram/ContactsManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/Global.h"
|
2019-11-11 08:02:23 +01:00
|
|
|
#include "td/telegram/misc.h"
|
2021-01-25 00:07:38 +01:00
|
|
|
#include "td/telegram/Td.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2022-04-04 15:19:41 +02:00
|
|
|
AdministratorRights::AdministratorRights(const tl_object_ptr<telegram_api::chatAdminRights> &rights,
|
|
|
|
ChannelType channel_type) {
|
2022-04-04 12:58:14 +02:00
|
|
|
if (rights == nullptr) {
|
|
|
|
flags_ = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rights->other_) {
|
|
|
|
LOG(ERROR) << "Receive wrong other flag in " << to_string(rights);
|
|
|
|
}
|
2022-10-23 12:20:53 +02:00
|
|
|
*this = AdministratorRights(rights->anonymous_, rights->other_, rights->change_info_, rights->post_messages_,
|
|
|
|
rights->edit_messages_, rights->delete_messages_, rights->invite_users_,
|
|
|
|
rights->ban_users_, rights->pin_messages_, rights->manage_topics_, rights->add_admins_,
|
|
|
|
rights->manage_call_, channel_type);
|
2022-04-04 12:58:14 +02:00
|
|
|
}
|
|
|
|
|
2022-04-04 15:19:41 +02:00
|
|
|
AdministratorRights::AdministratorRights(const td_api::object_ptr<td_api::chatAdministratorRights> &rights,
|
|
|
|
ChannelType channel_type) {
|
2022-04-04 12:58:14 +02:00
|
|
|
if (rights == nullptr) {
|
2022-04-02 14:32:04 +02:00
|
|
|
flags_ = 0;
|
|
|
|
return;
|
|
|
|
}
|
2022-04-04 12:58:14 +02:00
|
|
|
*this = AdministratorRights(rights->is_anonymous_, rights->can_manage_chat_, rights->can_change_info_,
|
|
|
|
rights->can_post_messages_, rights->can_edit_messages_, rights->can_delete_messages_,
|
|
|
|
rights->can_invite_users_, rights->can_restrict_members_, rights->can_pin_messages_,
|
2022-10-23 12:20:53 +02:00
|
|
|
rights->can_manage_topics_, rights->can_promote_members_, rights->can_manage_video_chats_,
|
|
|
|
channel_type);
|
2022-04-02 14:32:04 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 10:09:43 +01:00
|
|
|
AdministratorRights::AdministratorRights(bool is_anonymous, 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,
|
2022-10-23 12:20:53 +02:00
|
|
|
bool can_manage_topics, bool can_promote_members, bool can_manage_calls,
|
|
|
|
ChannelType channel_type) {
|
2022-04-04 15:19:41 +02:00
|
|
|
switch (channel_type) {
|
|
|
|
case ChannelType::Broadcast:
|
|
|
|
can_pin_messages = false;
|
2022-10-23 12:20:53 +02:00
|
|
|
can_manage_topics = false;
|
2022-04-04 15:19:41 +02:00
|
|
|
is_anonymous = false;
|
|
|
|
break;
|
|
|
|
case ChannelType::Megagroup:
|
|
|
|
can_post_messages = false;
|
|
|
|
can_edit_messages = false;
|
|
|
|
break;
|
|
|
|
case ChannelType::Unknown:
|
|
|
|
break;
|
|
|
|
}
|
2022-03-18 13:44:41 +01:00
|
|
|
flags_ = (static_cast<uint32>(can_manage_dialog) * CAN_MANAGE_DIALOG) |
|
2022-03-18 14:56:22 +01:00
|
|
|
(static_cast<uint32>(can_change_info) * CAN_CHANGE_INFO_AND_SETTINGS) |
|
2022-03-18 13:44:41 +01:00
|
|
|
(static_cast<uint32>(can_post_messages) * CAN_POST_MESSAGES) |
|
|
|
|
(static_cast<uint32>(can_edit_messages) * CAN_EDIT_MESSAGES) |
|
|
|
|
(static_cast<uint32>(can_delete_messages) * CAN_DELETE_MESSAGES) |
|
2022-03-18 14:56:22 +01:00
|
|
|
(static_cast<uint32>(can_invite_users) * CAN_INVITE_USERS) |
|
2022-03-18 13:44:41 +01:00
|
|
|
(static_cast<uint32>(can_restrict_members) * CAN_RESTRICT_MEMBERS) |
|
2022-03-18 14:56:22 +01:00
|
|
|
(static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES) |
|
2022-10-23 12:20:53 +02:00
|
|
|
(static_cast<uint32>(can_manage_topics) * CAN_MANAGE_TOPICS) |
|
2022-03-18 13:44:41 +01:00
|
|
|
(static_cast<uint32>(can_promote_members) * CAN_PROMOTE_MEMBERS) |
|
2022-03-22 10:09:43 +01:00
|
|
|
(static_cast<uint32>(can_manage_calls) * CAN_MANAGE_CALLS) |
|
|
|
|
(static_cast<uint32>(is_anonymous) * IS_ANONYMOUS);
|
2022-03-18 14:56:22 +01:00
|
|
|
if (flags_ != 0) {
|
|
|
|
flags_ |= CAN_MANAGE_DIALOG;
|
2022-04-04 15:19:41 +02:00
|
|
|
if (channel_type == ChannelType::Broadcast) {
|
|
|
|
flags_ |= CAN_RESTRICT_MEMBERS;
|
|
|
|
}
|
2022-03-18 14:56:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 10:09:43 +01:00
|
|
|
telegram_api::object_ptr<telegram_api::chatAdminRights> AdministratorRights::get_chat_admin_rights() const {
|
2022-03-18 14:56:22 +01:00
|
|
|
int32 flags = 0;
|
2022-10-23 11:15:09 +02:00
|
|
|
if (can_change_info_and_settings()) {
|
2022-03-18 14:56:22 +01:00
|
|
|
flags |= telegram_api::chatAdminRights::CHANGE_INFO_MASK;
|
|
|
|
}
|
|
|
|
if (can_post_messages()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::POST_MESSAGES_MASK;
|
|
|
|
}
|
|
|
|
if (can_edit_messages()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::EDIT_MESSAGES_MASK;
|
|
|
|
}
|
|
|
|
if (can_delete_messages()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::DELETE_MESSAGES_MASK;
|
|
|
|
}
|
2022-10-23 11:15:09 +02:00
|
|
|
if (can_invite_users()) {
|
2022-03-18 14:56:22 +01:00
|
|
|
flags |= telegram_api::chatAdminRights::INVITE_USERS_MASK;
|
|
|
|
}
|
|
|
|
if (can_restrict_members()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::BAN_USERS_MASK;
|
|
|
|
}
|
2022-10-23 11:15:09 +02:00
|
|
|
if (can_pin_messages()) {
|
2022-03-18 14:56:22 +01:00
|
|
|
flags |= telegram_api::chatAdminRights::PIN_MESSAGES_MASK;
|
|
|
|
}
|
2022-10-23 12:20:53 +02:00
|
|
|
if (can_manage_topics()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::MANAGE_TOPICS_MASK;
|
|
|
|
}
|
2022-03-18 14:56:22 +01:00
|
|
|
if (can_promote_members()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::ADD_ADMINS_MASK;
|
|
|
|
}
|
|
|
|
if (can_manage_calls()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::MANAGE_CALL_MASK;
|
|
|
|
}
|
|
|
|
if (can_manage_dialog()) {
|
|
|
|
flags |= telegram_api::chatAdminRights::OTHER_MASK;
|
|
|
|
}
|
2022-03-22 10:09:43 +01:00
|
|
|
if (is_anonymous()) {
|
2022-03-18 14:56:22 +01:00
|
|
|
flags |= telegram_api::chatAdminRights::ANONYMOUS_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return telegram_api::make_object<telegram_api::chatAdminRights>(
|
|
|
|
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
2022-10-07 17:04:00 +02:00
|
|
|
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
|
|
|
false /*ignored*/);
|
2022-03-18 13:44:41 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 11:17:48 +01:00
|
|
|
td_api::object_ptr<td_api::chatAdministratorRights> AdministratorRights::get_chat_administrator_rights_object() const {
|
|
|
|
return td_api::make_object<td_api::chatAdministratorRights>(
|
|
|
|
can_manage_dialog(), can_change_info_and_settings(), can_post_messages(), can_edit_messages(),
|
2022-10-23 12:20:53 +02:00
|
|
|
can_delete_messages(), can_invite_users(), can_restrict_members(), can_pin_messages(), can_manage_topics(),
|
|
|
|
can_promote_members(), can_manage_calls(), is_anonymous());
|
2022-03-22 11:17:48 +01:00
|
|
|
}
|
|
|
|
|
2022-03-18 13:44:41 +01:00
|
|
|
bool operator==(const AdministratorRights &lhs, const AdministratorRights &rhs) {
|
|
|
|
return lhs.flags_ == rhs.flags_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const AdministratorRights &lhs, const AdministratorRights &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const AdministratorRights &status) {
|
|
|
|
string_builder << "Administrator: ";
|
|
|
|
if (status.can_manage_dialog()) {
|
|
|
|
string_builder << "(manage)";
|
|
|
|
}
|
|
|
|
if (status.can_change_info_and_settings()) {
|
|
|
|
string_builder << "(change)";
|
|
|
|
}
|
|
|
|
if (status.can_post_messages()) {
|
|
|
|
string_builder << "(post)";
|
|
|
|
}
|
|
|
|
if (status.can_edit_messages()) {
|
|
|
|
string_builder << "(edit)";
|
|
|
|
}
|
|
|
|
if (status.can_delete_messages()) {
|
|
|
|
string_builder << "(delete)";
|
|
|
|
}
|
|
|
|
if (status.can_invite_users()) {
|
|
|
|
string_builder << "(invite)";
|
|
|
|
}
|
|
|
|
if (status.can_restrict_members()) {
|
|
|
|
string_builder << "(restrict)";
|
|
|
|
}
|
|
|
|
if (status.can_pin_messages()) {
|
|
|
|
string_builder << "(pin)";
|
|
|
|
}
|
2022-10-23 12:20:53 +02:00
|
|
|
if (status.can_manage_topics()) {
|
|
|
|
string_builder << "(manage_topics)";
|
|
|
|
}
|
2022-03-18 13:44:41 +01:00
|
|
|
if (status.can_promote_members()) {
|
|
|
|
string_builder << "(promote)";
|
|
|
|
}
|
|
|
|
if (status.can_manage_calls()) {
|
|
|
|
string_builder << "(voice chat)";
|
|
|
|
}
|
2022-03-22 10:09:43 +01:00
|
|
|
if (status.is_anonymous()) {
|
|
|
|
string_builder << "(anonymous)";
|
|
|
|
}
|
2022-03-18 13:44:41 +01:00
|
|
|
return string_builder;
|
|
|
|
}
|
|
|
|
|
2022-04-04 13:13:51 +02:00
|
|
|
RestrictedRights::RestrictedRights(const tl_object_ptr<telegram_api::chatBannedRights> &rights) {
|
|
|
|
if (rights == nullptr) {
|
|
|
|
flags_ = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (rights->view_messages_) {
|
|
|
|
LOG(ERROR) << "Can't view messages in banned rights " << to_string(rights);
|
|
|
|
}
|
|
|
|
LOG_IF(ERROR, rights->until_date_ != std::numeric_limits<int32>::max())
|
|
|
|
<< "Have until date " << rights->until_date_ << " in restricted rights";
|
|
|
|
|
2022-10-23 12:20:53 +02:00
|
|
|
*this =
|
|
|
|
RestrictedRights(!rights->send_messages_, !rights->send_media_, !rights->send_stickers_, !rights->send_gifs_,
|
|
|
|
!rights->send_games_, !rights->send_inline_, !rights->embed_links_, !rights->send_polls_,
|
|
|
|
!rights->change_info_, !rights->invite_users_, !rights->pin_messages_, !rights->manage_topics_);
|
2022-04-04 13:13:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RestrictedRights::RestrictedRights(const td_api::object_ptr<td_api::chatPermissions> &rights) {
|
|
|
|
if (rights == nullptr) {
|
|
|
|
flags_ = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_send_polls = rights->can_send_polls_;
|
|
|
|
bool can_send_media = rights->can_send_media_messages_;
|
|
|
|
bool can_send_messages = rights->can_send_messages_ || can_send_media || can_send_polls ||
|
|
|
|
rights->can_send_other_messages_ || rights->can_add_web_page_previews_;
|
2022-04-04 14:59:30 +02:00
|
|
|
*this = RestrictedRights(can_send_messages, can_send_media, rights->can_send_other_messages_,
|
|
|
|
rights->can_send_other_messages_, rights->can_send_other_messages_,
|
|
|
|
rights->can_send_other_messages_, rights->can_add_web_page_previews_, can_send_polls,
|
2022-10-23 12:20:53 +02:00
|
|
|
rights->can_change_info_, rights->can_invite_users_, rights->can_pin_messages_,
|
|
|
|
rights->can_manage_topics_);
|
2022-04-04 13:13:51 +02:00
|
|
|
}
|
|
|
|
|
2022-03-18 14:25:07 +01:00
|
|
|
RestrictedRights::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,
|
2022-10-23 12:20:53 +02:00
|
|
|
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages,
|
|
|
|
bool can_manage_topics) {
|
2022-03-18 14:25:07 +01:00
|
|
|
flags_ = (static_cast<uint32>(can_send_messages) * CAN_SEND_MESSAGES) |
|
|
|
|
(static_cast<uint32>(can_send_media) * CAN_SEND_MEDIA) |
|
|
|
|
(static_cast<uint32>(can_send_stickers) * CAN_SEND_STICKERS) |
|
|
|
|
(static_cast<uint32>(can_send_animations) * CAN_SEND_ANIMATIONS) |
|
|
|
|
(static_cast<uint32>(can_send_games) * CAN_SEND_GAMES) |
|
|
|
|
(static_cast<uint32>(can_use_inline_bots) * CAN_USE_INLINE_BOTS) |
|
|
|
|
(static_cast<uint32>(can_add_web_page_previews) * CAN_ADD_WEB_PAGE_PREVIEWS) |
|
|
|
|
(static_cast<uint32>(can_send_polls) * CAN_SEND_POLLS) |
|
|
|
|
(static_cast<uint32>(can_change_info_and_settings) * CAN_CHANGE_INFO_AND_SETTINGS) |
|
|
|
|
(static_cast<uint32>(can_invite_users) * CAN_INVITE_USERS) |
|
2022-10-23 12:20:53 +02:00
|
|
|
(static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES) |
|
|
|
|
(static_cast<uint32>(can_manage_topics) * CAN_MANAGE_TOPICS);
|
2022-03-18 14:25:07 +01:00
|
|
|
}
|
|
|
|
|
2022-03-18 16:27:10 +01:00
|
|
|
td_api::object_ptr<td_api::chatPermissions> RestrictedRights::get_chat_permissions_object() const {
|
2022-03-18 14:25:07 +01:00
|
|
|
return td_api::make_object<td_api::chatPermissions>(
|
|
|
|
can_send_messages(), can_send_media(), can_send_polls(),
|
|
|
|
can_send_stickers() || can_send_animations() || can_send_games() || can_use_inline_bots(),
|
2022-10-23 12:20:53 +02:00
|
|
|
can_add_web_page_previews(), can_change_info_and_settings(), can_invite_users(), can_pin_messages(),
|
|
|
|
can_manage_topics());
|
2022-03-18 14:25:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::chatBannedRights> RestrictedRights::get_chat_banned_rights() const {
|
|
|
|
int32 flags = 0;
|
|
|
|
if (!can_send_messages()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::SEND_MESSAGES_MASK;
|
|
|
|
}
|
|
|
|
if (!can_send_media()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::SEND_MEDIA_MASK;
|
|
|
|
}
|
|
|
|
if (!can_send_stickers()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::SEND_STICKERS_MASK;
|
|
|
|
}
|
|
|
|
if (!can_send_animations()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::SEND_GIFS_MASK;
|
|
|
|
}
|
|
|
|
if (!can_send_games()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::SEND_GAMES_MASK;
|
|
|
|
}
|
|
|
|
if (!can_use_inline_bots()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::SEND_INLINE_MASK;
|
|
|
|
}
|
|
|
|
if (!can_add_web_page_previews()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::EMBED_LINKS_MASK;
|
|
|
|
}
|
|
|
|
if (!can_send_polls()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::SEND_POLLS_MASK;
|
|
|
|
}
|
|
|
|
if (!can_change_info_and_settings()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::CHANGE_INFO_MASK;
|
|
|
|
}
|
|
|
|
if (!can_invite_users()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::INVITE_USERS_MASK;
|
|
|
|
}
|
|
|
|
if (!can_pin_messages()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::PIN_MESSAGES_MASK;
|
|
|
|
}
|
2022-10-23 12:20:53 +02:00
|
|
|
if (!can_manage_topics()) {
|
|
|
|
flags |= telegram_api::chatBannedRights::MANAGE_TOPICS_MASK;
|
|
|
|
}
|
2022-03-18 14:25:07 +01:00
|
|
|
|
|
|
|
LOG(INFO) << "Create chat banned rights " << flags;
|
2022-10-07 17:04:00 +02:00
|
|
|
return make_tl_object<telegram_api::chatBannedRights>(
|
|
|
|
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
|
|
|
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
|
|
|
false /*ignored*/, false /*ignored*/, 0);
|
2022-03-18 14:25:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const RestrictedRights &lhs, const RestrictedRights &rhs) {
|
|
|
|
return lhs.flags_ == rhs.flags_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const RestrictedRights &lhs, const RestrictedRights &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status) {
|
|
|
|
string_builder << "Restricted: ";
|
|
|
|
if (!status.can_send_messages()) {
|
|
|
|
string_builder << "(text)";
|
|
|
|
}
|
|
|
|
if (!status.can_send_media()) {
|
|
|
|
string_builder << "(media)";
|
|
|
|
}
|
|
|
|
if (!status.can_send_stickers()) {
|
|
|
|
string_builder << "(stickers)";
|
|
|
|
}
|
|
|
|
if (!status.can_send_animations()) {
|
|
|
|
string_builder << "(animations)";
|
|
|
|
}
|
|
|
|
if (!status.can_send_games()) {
|
|
|
|
string_builder << "(games)";
|
|
|
|
}
|
|
|
|
if (!status.can_send_polls()) {
|
|
|
|
string_builder << "(polls)";
|
|
|
|
}
|
|
|
|
if (!status.can_use_inline_bots()) {
|
|
|
|
string_builder << "(inline bots)";
|
|
|
|
}
|
|
|
|
if (!status.can_add_web_page_previews()) {
|
|
|
|
string_builder << "(links)";
|
|
|
|
}
|
|
|
|
if (!status.can_change_info_and_settings()) {
|
|
|
|
string_builder << "(change)";
|
|
|
|
}
|
|
|
|
if (!status.can_invite_users()) {
|
|
|
|
string_builder << "(invite)";
|
|
|
|
}
|
|
|
|
if (!status.can_pin_messages()) {
|
|
|
|
string_builder << "(pin)";
|
|
|
|
}
|
2022-10-23 12:20:53 +02:00
|
|
|
if (!status.can_manage_topics()) {
|
|
|
|
string_builder << "(topics)";
|
|
|
|
}
|
2022-03-18 14:25:07 +01:00
|
|
|
return string_builder;
|
|
|
|
}
|
|
|
|
|
2019-11-11 08:02:23 +01:00
|
|
|
DialogParticipantStatus::DialogParticipantStatus(Type type, uint32 flags, int32 until_date, string rank)
|
|
|
|
: type_(type), flags_(flags), until_date_(until_date), rank_(strip_empty_characters(std::move(rank), 16)) {
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
int32 DialogParticipantStatus::fix_until_date(int32 date) {
|
|
|
|
if (date == std::numeric_limits<int32>::max() || date < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
2022-03-22 10:38:44 +01:00
|
|
|
DialogParticipantStatus DialogParticipantStatus::Creator(bool is_member, bool is_anonymous, string &&rank) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return DialogParticipantStatus(Type::Creator,
|
2022-03-18 16:47:34 +01:00
|
|
|
AdministratorRights::ALL_ADMINISTRATOR_RIGHTS |
|
|
|
|
RestrictedRights::ALL_RESTRICTED_RIGHTS | (is_member ? IS_MEMBER : 0) |
|
2022-03-22 10:09:43 +01:00
|
|
|
(is_anonymous ? AdministratorRights::IS_ANONYMOUS : 0),
|
2020-09-11 00:49:15 +02:00
|
|
|
0, std::move(rank));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 10:38:44 +01:00
|
|
|
DialogParticipantStatus DialogParticipantStatus::Administrator(AdministratorRights administrator_rights, string &&rank,
|
|
|
|
bool can_be_edited) {
|
|
|
|
uint32 flags = administrator_rights.flags_;
|
2022-03-18 14:56:22 +01:00
|
|
|
if (flags == 0) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return Member();
|
|
|
|
}
|
2022-03-18 14:56:22 +01:00
|
|
|
flags = flags | (static_cast<uint32>(can_be_edited) * CAN_BE_EDITED);
|
2022-03-18 16:47:34 +01:00
|
|
|
return DialogParticipantStatus(
|
|
|
|
Type::Administrator,
|
|
|
|
IS_MEMBER | (RestrictedRights::ALL_RESTRICTED_RIGHTS & ~RestrictedRights::ALL_ADMIN_PERMISSION_RIGHTS) | flags, 0,
|
|
|
|
std::move(rank));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogParticipantStatus DialogParticipantStatus::Member() {
|
2022-03-18 16:47:34 +01:00
|
|
|
return DialogParticipantStatus(Type::Member, IS_MEMBER | RestrictedRights::ALL_RESTRICTED_RIGHTS, 0, string());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 10:38:44 +01:00
|
|
|
DialogParticipantStatus DialogParticipantStatus::Restricted(RestrictedRights restricted_rights, bool is_member,
|
|
|
|
int32 restricted_until_date) {
|
|
|
|
uint32 flags = restricted_rights.flags_;
|
|
|
|
if (flags == RestrictedRights::ALL_RESTRICTED_RIGHTS) {
|
|
|
|
return is_member ? Member() : Left();
|
|
|
|
}
|
|
|
|
flags |= (static_cast<uint32>(is_member) * IS_MEMBER);
|
|
|
|
return DialogParticipantStatus(Type::Restricted, flags, fix_until_date(restricted_until_date), string());
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
DialogParticipantStatus DialogParticipantStatus::Left() {
|
2022-03-18 16:47:34 +01:00
|
|
|
return DialogParticipantStatus(Type::Left, RestrictedRights::ALL_RESTRICTED_RIGHTS, 0, string());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogParticipantStatus DialogParticipantStatus::Banned(int32 banned_until_date) {
|
2019-11-11 08:02:23 +01:00
|
|
|
return DialogParticipantStatus(Type::Banned, 0, fix_until_date(banned_until_date), string());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogParticipantStatus DialogParticipantStatus::GroupAdministrator(bool is_creator) {
|
2022-10-23 12:20:53 +02:00
|
|
|
return Administrator(AdministratorRights(false, true, true, false, false, true, true, true, true, false, false, true,
|
|
|
|
ChannelType::Unknown),
|
|
|
|
string(), is_creator);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogParticipantStatus DialogParticipantStatus::ChannelAdministrator(bool is_creator, bool is_megagroup) {
|
2022-10-23 12:20:53 +02:00
|
|
|
auto rights = is_megagroup ? AdministratorRights(false, true, true, false, false, true, true, true, true, true, false,
|
2022-04-04 15:19:41 +02:00
|
|
|
false, ChannelType::Megagroup)
|
|
|
|
: AdministratorRights(false, true, false, true, true, true, false, true, false, false,
|
2022-10-23 12:20:53 +02:00
|
|
|
false, false, ChannelType::Broadcast);
|
2022-04-04 14:59:30 +02:00
|
|
|
return Administrator(rights, string(), is_creator);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-03-19 18:34:16 +01:00
|
|
|
DialogParticipantStatus::DialogParticipantStatus(bool can_be_edited,
|
|
|
|
tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights,
|
2022-04-04 15:19:41 +02:00
|
|
|
string rank, ChannelType channel_type) {
|
2022-03-19 18:34:16 +01:00
|
|
|
CHECK(admin_rights != nullptr);
|
2022-04-04 15:19:41 +02:00
|
|
|
uint32 flags = AdministratorRights(admin_rights, channel_type).flags_ | AdministratorRights::CAN_MANAGE_DIALOG;
|
2022-03-19 18:34:16 +01:00
|
|
|
if (can_be_edited) {
|
|
|
|
flags |= CAN_BE_EDITED;
|
|
|
|
}
|
|
|
|
flags |= (RestrictedRights::ALL_RESTRICTED_RIGHTS & ~RestrictedRights::ALL_ADMIN_PERMISSION_RIGHTS) | IS_MEMBER;
|
|
|
|
*this = DialogParticipantStatus(Type::Administrator, flags, 0, std::move(rank));
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogParticipantStatus::DialogParticipantStatus(bool is_member,
|
|
|
|
tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights) {
|
|
|
|
CHECK(banned_rights != nullptr);
|
2022-03-22 11:30:55 +01:00
|
|
|
if (banned_rights->view_messages_) {
|
2022-03-19 18:34:16 +01:00
|
|
|
*this = DialogParticipantStatus::Banned(banned_rights->until_date_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto until_date = fix_until_date(banned_rights->until_date_);
|
|
|
|
banned_rights->until_date_ = std::numeric_limits<int32>::max();
|
2022-04-04 13:13:51 +02:00
|
|
|
uint32 flags = RestrictedRights(banned_rights).flags_ | (static_cast<uint32>(is_member) * IS_MEMBER);
|
2022-03-19 18:34:16 +01:00
|
|
|
*this = DialogParticipantStatus(Type::Restricted, flags, until_date, string());
|
|
|
|
}
|
|
|
|
|
2022-03-18 15:50:55 +01:00
|
|
|
RestrictedRights DialogParticipantStatus::get_effective_restricted_rights() const {
|
2019-03-20 13:28:06 +01:00
|
|
|
return RestrictedRights(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(),
|
2022-10-23 12:20:53 +02:00
|
|
|
can_change_info_and_settings(), can_invite_users(), can_pin_messages(), can_create_topics());
|
2019-03-20 13:28:06 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member_status_object() const {
|
|
|
|
switch (type_) {
|
|
|
|
case Type::Creator:
|
2020-09-28 00:15:56 +02:00
|
|
|
return td_api::make_object<td_api::chatMemberStatusCreator>(rank_, is_anonymous(), is_member());
|
2018-12-31 20:04:05 +01:00
|
|
|
case Type::Administrator:
|
2019-11-11 08:02:23 +01:00
|
|
|
return td_api::make_object<td_api::chatMemberStatusAdministrator>(
|
2022-03-22 11:17:48 +01:00
|
|
|
rank_, can_be_edited(), get_administrator_rights().get_chat_administrator_rights_object());
|
2018-12-31 20:04:05 +01:00
|
|
|
case Type::Member:
|
2019-11-11 08:02:23 +01:00
|
|
|
return td_api::make_object<td_api::chatMemberStatusMember>();
|
2018-12-31 20:04:05 +01:00
|
|
|
case Type::Restricted:
|
2019-11-11 08:02:23 +01:00
|
|
|
return td_api::make_object<td_api::chatMemberStatusRestricted>(
|
|
|
|
is_member(), until_date_, get_restricted_rights().get_chat_permissions_object());
|
2018-12-31 20:04:05 +01:00
|
|
|
case Type::Left:
|
2019-11-11 08:02:23 +01:00
|
|
|
return td_api::make_object<td_api::chatMemberStatusLeft>();
|
2018-12-31 20:04:05 +01:00
|
|
|
case Type::Banned:
|
2019-11-11 08:02:23 +01:00
|
|
|
return td_api::make_object<td_api::chatMemberStatusBanned>(until_date_);
|
2018-12-31 20:04:05 +01:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 14:52:55 +01:00
|
|
|
tl_object_ptr<telegram_api::chatAdminRights> DialogParticipantStatus::get_chat_admin_rights() const {
|
2022-03-22 10:09:43 +01:00
|
|
|
return get_administrator_rights().get_chat_admin_rights();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-03-15 14:52:55 +01:00
|
|
|
tl_object_ptr<telegram_api::chatBannedRights> DialogParticipantStatus::get_chat_banned_rights() const {
|
2022-03-18 16:27:10 +01:00
|
|
|
auto result = get_restricted_rights().get_chat_banned_rights();
|
2018-12-31 20:04:05 +01:00
|
|
|
if (type_ == Type::Banned) {
|
2022-03-18 16:27:10 +01:00
|
|
|
result->flags_ |= telegram_api::chatBannedRights::VIEW_MESSAGES_MASK;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-03-18 16:27:10 +01:00
|
|
|
result->until_date_ = until_date_;
|
|
|
|
return result;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 16:32:06 +01:00
|
|
|
DialogParticipantStatus DialogParticipantStatus::apply_restrictions(RestrictedRights default_restrictions,
|
|
|
|
bool is_bot) const {
|
2019-03-22 15:04:01 +01:00
|
|
|
auto flags = flags_;
|
|
|
|
switch (type_) {
|
|
|
|
case Type::Creator:
|
|
|
|
// creator can do anything and isn't affected by restrictions
|
|
|
|
break;
|
|
|
|
case Type::Administrator:
|
|
|
|
// administrators aren't affected by restrictions, but if everyone can invite users,
|
|
|
|
// pin messages or change info, they also can do that
|
2019-03-22 16:32:06 +01:00
|
|
|
if (!is_bot) {
|
2022-03-18 16:47:34 +01:00
|
|
|
flags |= default_restrictions.flags_ & RestrictedRights::ALL_ADMIN_PERMISSION_RIGHTS;
|
2019-03-22 16:32:06 +01:00
|
|
|
}
|
2019-03-22 15:04:01 +01:00
|
|
|
break;
|
|
|
|
case Type::Member:
|
|
|
|
case Type::Restricted:
|
|
|
|
case Type::Left:
|
|
|
|
// members and restricted are affected by default restrictions
|
2022-03-18 16:47:34 +01:00
|
|
|
flags &= (~RestrictedRights::ALL_RESTRICTED_RIGHTS) | default_restrictions.flags_;
|
2019-03-22 16:32:06 +01:00
|
|
|
if (is_bot) {
|
2022-03-18 16:47:34 +01:00
|
|
|
flags &= ~RestrictedRights::ALL_ADMIN_PERMISSION_RIGHTS;
|
2019-03-22 16:32:06 +01:00
|
|
|
}
|
2019-03-22 15:04:01 +01:00
|
|
|
break;
|
|
|
|
case Type::Banned:
|
2019-11-23 23:37:46 +01:00
|
|
|
// banned can do nothing, even restrictions allows them to do that
|
2019-03-22 15:04:01 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-11 08:02:23 +01:00
|
|
|
return DialogParticipantStatus(type_, flags, 0, string());
|
2019-03-22 15:04:01 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void DialogParticipantStatus::update_restrictions() const {
|
|
|
|
if (until_date_ != 0 && G()->unix_time() > until_date_) {
|
|
|
|
until_date_ = 0;
|
|
|
|
if (type_ == Type::Restricted) {
|
|
|
|
if (is_member()) {
|
|
|
|
type_ = Type::Member;
|
|
|
|
} else {
|
|
|
|
type_ = Type::Left;
|
|
|
|
}
|
2022-03-18 16:47:34 +01:00
|
|
|
flags_ |= RestrictedRights::ALL_RESTRICTED_RIGHTS;
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (type_ == Type::Banned) {
|
|
|
|
type_ = Type::Left;
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const DialogParticipantStatus &lhs, const DialogParticipantStatus &rhs) {
|
2019-11-11 08:02:23 +01:00
|
|
|
return lhs.type_ == rhs.type_ && lhs.flags_ == rhs.flags_ && lhs.until_date_ == rhs.until_date_ &&
|
|
|
|
lhs.rank_ == rhs.rank_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const DialogParticipantStatus &lhs, const DialogParticipantStatus &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantStatus &status) {
|
|
|
|
switch (status.type_) {
|
|
|
|
case DialogParticipantStatus::Type::Creator:
|
|
|
|
string_builder << "Creator";
|
|
|
|
if (!status.is_member()) {
|
|
|
|
string_builder << "-non-member";
|
|
|
|
}
|
2019-11-11 08:02:23 +01:00
|
|
|
if (!status.rank_.empty()) {
|
|
|
|
string_builder << " [" << status.rank_ << "]";
|
|
|
|
}
|
2020-09-11 00:49:15 +02:00
|
|
|
if (status.is_anonymous()) {
|
|
|
|
string_builder << "-anonymous";
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
return string_builder;
|
|
|
|
case DialogParticipantStatus::Type::Administrator:
|
2022-03-18 14:07:14 +01:00
|
|
|
string_builder << status.get_administrator_rights();
|
2022-06-04 12:58:08 +02:00
|
|
|
if (status.can_be_edited()) {
|
|
|
|
string_builder << "(can_be_edited)";
|
|
|
|
}
|
2019-11-11 08:02:23 +01:00
|
|
|
if (!status.rank_.empty()) {
|
|
|
|
string_builder << " [" << status.rank_ << "]";
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
return string_builder;
|
|
|
|
case DialogParticipantStatus::Type::Member:
|
|
|
|
return string_builder << "Member";
|
|
|
|
case DialogParticipantStatus::Type::Restricted:
|
2022-03-18 14:07:14 +01:00
|
|
|
string_builder << status.get_restricted_rights();
|
2018-12-31 20:04:05 +01:00
|
|
|
if (status.until_date_ == 0) {
|
|
|
|
string_builder << "forever ";
|
|
|
|
} else {
|
|
|
|
string_builder << "until " << status.until_date_ << " ";
|
|
|
|
}
|
|
|
|
if (!status.is_member()) {
|
|
|
|
string_builder << "non-";
|
|
|
|
}
|
2022-03-18 14:07:14 +01:00
|
|
|
string_builder << "member";
|
2018-12-31 20:04:05 +01:00
|
|
|
return string_builder;
|
|
|
|
case DialogParticipantStatus::Type::Left:
|
|
|
|
return string_builder << "Left";
|
|
|
|
case DialogParticipantStatus::Type::Banned:
|
|
|
|
string_builder << "Banned ";
|
|
|
|
if (status.until_date_ == 0) {
|
|
|
|
string_builder << "forever";
|
|
|
|
} else {
|
|
|
|
string_builder << "until " << status.until_date_;
|
|
|
|
}
|
|
|
|
return string_builder;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return string_builder << "Impossible";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 15:19:41 +02:00
|
|
|
DialogParticipantStatus get_dialog_participant_status(const td_api::object_ptr<td_api::ChatMemberStatus> &status,
|
|
|
|
ChannelType channel_type) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto constructor_id = status == nullptr ? td_api::chatMemberStatusMember::ID : status->get_id();
|
2022-05-12 13:38:45 +02:00
|
|
|
auto fix_until_date = [](int32 until_date) {
|
|
|
|
if (until_date == 0) {
|
|
|
|
// fast path
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if user is restricted for more than 366 days or less than 30 seconds from the current time,
|
|
|
|
// they are considered to be restricted forever
|
|
|
|
auto unix_time = G()->unix_time();
|
|
|
|
if (until_date < unix_time + 30 || until_date > unix_time + 366 * 86400) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return until_date;
|
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
switch (constructor_id) {
|
|
|
|
case td_api::chatMemberStatusCreator::ID: {
|
|
|
|
auto st = static_cast<const td_api::chatMemberStatusCreator *>(status.get());
|
2021-09-28 16:31:00 +02:00
|
|
|
auto custom_title = st->custom_title_;
|
|
|
|
if (!clean_input_string(custom_title)) {
|
|
|
|
custom_title.clear();
|
|
|
|
}
|
2022-03-22 10:38:44 +01:00
|
|
|
return DialogParticipantStatus::Creator(st->is_member_, st->is_anonymous_, std::move(custom_title));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
case td_api::chatMemberStatusAdministrator::ID: {
|
|
|
|
auto st = static_cast<const td_api::chatMemberStatusAdministrator *>(status.get());
|
2021-09-28 16:31:00 +02:00
|
|
|
auto custom_title = st->custom_title_;
|
|
|
|
if (!clean_input_string(custom_title)) {
|
|
|
|
custom_title.clear();
|
|
|
|
}
|
2022-04-04 15:19:41 +02:00
|
|
|
return DialogParticipantStatus::Administrator(AdministratorRights(st->rights_, channel_type),
|
|
|
|
std::move(custom_title), true /*st->can_be_edited_*/);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
case td_api::chatMemberStatusMember::ID:
|
|
|
|
return DialogParticipantStatus::Member();
|
|
|
|
case td_api::chatMemberStatusRestricted::ID: {
|
|
|
|
auto st = static_cast<const td_api::chatMemberStatusRestricted *>(status.get());
|
2022-04-04 13:13:51 +02:00
|
|
|
return DialogParticipantStatus::Restricted(RestrictedRights(st->permissions_), st->is_member_,
|
2022-05-12 13:38:45 +02:00
|
|
|
fix_until_date(st->restricted_until_date_));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
case td_api::chatMemberStatusLeft::ID:
|
|
|
|
return DialogParticipantStatus::Left();
|
|
|
|
case td_api::chatMemberStatusBanned::ID: {
|
|
|
|
auto st = static_cast<const td_api::chatMemberStatusBanned *>(status.get());
|
2022-05-12 13:38:45 +02:00
|
|
|
return DialogParticipantStatus::Banned(fix_until_date(st->banned_until_date_));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return DialogParticipantStatus::Member();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-22 02:03:24 +01:00
|
|
|
DialogParticipant::DialogParticipant(DialogId dialog_id, UserId inviter_user_id, int32 joined_date,
|
2020-06-30 16:46:36 +02:00
|
|
|
DialogParticipantStatus status)
|
2021-10-29 13:39:07 +02:00
|
|
|
: dialog_id_(dialog_id), inviter_user_id_(inviter_user_id), joined_date_(joined_date), status_(std::move(status)) {
|
|
|
|
if (!inviter_user_id_.is_valid() && inviter_user_id_ != UserId()) {
|
|
|
|
LOG(ERROR) << "Receive inviter " << inviter_user_id_;
|
|
|
|
inviter_user_id_ = UserId();
|
2020-06-30 16:46:36 +02:00
|
|
|
}
|
2021-10-29 13:39:07 +02:00
|
|
|
if (joined_date_ < 0) {
|
|
|
|
LOG(ERROR) << "Receive date " << joined_date_;
|
|
|
|
joined_date_ = 0;
|
2020-06-30 16:46:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 23:38:16 +01:00
|
|
|
DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChatParticipant> &&participant_ptr,
|
|
|
|
int32 chat_creation_date, bool is_creator) {
|
|
|
|
switch (participant_ptr->get_id()) {
|
|
|
|
case telegram_api::chatParticipant::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::chatParticipant>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(UserId(participant->user_id_)), UserId(participant->inviter_id_), participant->date_,
|
2021-02-18 23:38:16 +01:00
|
|
|
DialogParticipantStatus::Member()};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::chatParticipantCreator::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::chatParticipantCreator>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(UserId(participant->user_id_)), UserId(participant->user_id_), chat_creation_date,
|
2021-02-18 23:38:16 +01:00
|
|
|
DialogParticipantStatus::Creator(true, false, string())};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::chatParticipantAdmin::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::chatParticipantAdmin>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(UserId(participant->user_id_)), UserId(participant->inviter_id_), participant->date_,
|
2021-02-18 23:38:16 +01:00
|
|
|
DialogParticipantStatus::GroupAdministrator(is_creator)};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 15:19:41 +02:00
|
|
|
DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr,
|
|
|
|
ChannelType channel_type) {
|
2020-06-30 16:46:36 +02:00
|
|
|
CHECK(participant_ptr != nullptr);
|
2021-03-21 19:55:21 +01:00
|
|
|
|
2020-06-30 15:43:44 +02:00
|
|
|
switch (participant_ptr->get_id()) {
|
|
|
|
case telegram_api::channelParticipant::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::channelParticipant>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(UserId(participant->user_id_)), UserId(), participant->date_,
|
|
|
|
DialogParticipantStatus::Member()};
|
2020-06-30 15:43:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::channelParticipantSelf::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::channelParticipantSelf>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(UserId(participant->user_id_)), UserId(participant->inviter_id_), participant->date_,
|
2021-03-01 00:33:38 +01:00
|
|
|
DialogParticipantStatus::Member()};
|
2020-06-30 15:43:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::channelParticipantCreator::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::channelParticipantCreator>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(UserId(participant->user_id_)), UserId(), 0,
|
2021-11-01 19:53:23 +01:00
|
|
|
DialogParticipantStatus::Creator(true, participant->admin_rights_->anonymous_,
|
|
|
|
std::move(participant->rank_))};
|
2020-06-30 15:43:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::channelParticipantAdmin::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::channelParticipantAdmin>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(UserId(participant->user_id_)), UserId(participant->promoted_by_), participant->date_,
|
2022-03-18 17:13:22 +01:00
|
|
|
DialogParticipantStatus(participant->can_edit_, std::move(participant->admin_rights_),
|
2022-04-04 15:19:41 +02:00
|
|
|
std::move(participant->rank_), channel_type)};
|
2020-06-30 15:43:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-10-14 21:35:30 +02:00
|
|
|
case telegram_api::channelParticipantLeft::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::channelParticipantLeft>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(participant->peer_), UserId(), 0, DialogParticipantStatus::Left()};
|
2020-10-14 21:35:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-06-30 15:43:44 +02:00
|
|
|
case telegram_api::channelParticipantBanned::ID: {
|
|
|
|
auto participant = move_tl_object_as<telegram_api::channelParticipantBanned>(participant_ptr);
|
2021-03-22 02:03:24 +01:00
|
|
|
*this = {DialogId(participant->peer_), UserId(participant->kicked_by_), participant->date_,
|
2022-03-18 17:13:22 +01:00
|
|
|
DialogParticipantStatus(!participant->left_, std::move(participant->banned_rights_))};
|
2020-06-30 15:43:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-30 16:46:36 +02:00
|
|
|
bool DialogParticipant::is_valid() const {
|
2021-10-29 13:39:07 +02:00
|
|
|
if (!dialog_id_.is_valid() || joined_date_ < 0) {
|
2020-06-30 16:46:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-10-29 13:39:07 +02:00
|
|
|
if (status_.is_restricted() || status_.is_banned() || (status_.is_administrator() && !status_.is_creator())) {
|
|
|
|
return inviter_user_id_.is_valid();
|
2020-06-30 16:46:36 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-12 10:38:37 +01:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant &dialog_participant) {
|
2021-10-29 13:39:07 +02:00
|
|
|
return string_builder << '[' << dialog_participant.dialog_id_ << " invited by " << dialog_participant.inviter_user_id_
|
|
|
|
<< " at " << dialog_participant.joined_date_ << " with status " << dialog_participant.status_
|
2019-03-12 10:38:37 +01:00
|
|
|
<< ']';
|
|
|
|
}
|
|
|
|
|
2021-01-25 00:07:38 +01:00
|
|
|
td_api::object_ptr<td_api::chatMembers> DialogParticipants::get_chat_members_object(Td *td) const {
|
|
|
|
vector<tl_object_ptr<td_api::chatMember>> chat_members;
|
|
|
|
chat_members.reserve(participants_.size());
|
|
|
|
for (auto &participant : participants_) {
|
|
|
|
chat_members.push_back(td->contacts_manager_->get_chat_member_object(participant));
|
|
|
|
}
|
|
|
|
|
|
|
|
return td_api::make_object<td_api::chatMembers>(total_count_, std::move(chat_members));
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|