2020-12-08 15:29:25 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2020-12-08 15:29:25 +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/GroupCallParticipant.h"
|
|
|
|
|
|
|
|
#include "td/telegram/ContactsManager.h"
|
|
|
|
|
2020-12-22 13:51:57 +01:00
|
|
|
#include "td/utils/logging.h"
|
|
|
|
|
2020-12-08 15:29:25 +01:00
|
|
|
namespace td {
|
|
|
|
|
2020-12-11 15:43:23 +01:00
|
|
|
GroupCallParticipant::GroupCallParticipant(const tl_object_ptr<telegram_api::groupCallParticipant> &participant) {
|
2020-12-08 15:29:25 +01:00
|
|
|
CHECK(participant != nullptr);
|
|
|
|
user_id = UserId(participant->user_id_);
|
2021-01-11 13:02:02 +01:00
|
|
|
audio_source = participant->source_;
|
2020-12-08 15:29:25 +01:00
|
|
|
is_muted = participant->muted_;
|
|
|
|
can_self_unmute = participant->can_self_unmute_;
|
2020-12-31 00:48:45 +01:00
|
|
|
is_muted_only_for_self = participant->muted_by_you_;
|
2020-12-31 01:10:41 +01:00
|
|
|
if ((participant->flags_ & telegram_api::groupCallParticipant::VOLUME_MASK) != 0) {
|
|
|
|
volume_level = participant->volume_;
|
2021-01-02 20:59:48 +01:00
|
|
|
if (volume_level < MIN_VOLUME_LEVEL || volume_level > MAX_VOLUME_LEVEL) {
|
2020-12-31 01:10:41 +01:00
|
|
|
LOG(ERROR) << "Receive " << to_string(participant);
|
|
|
|
volume_level = 10000;
|
|
|
|
}
|
2021-02-01 20:29:45 +01:00
|
|
|
is_volume_level_local = (participant->flags_ & telegram_api::groupCallParticipant::VOLUME_BY_ADMIN_MASK) == 0;
|
2020-12-31 01:10:41 +01:00
|
|
|
}
|
2020-12-08 15:29:25 +01:00
|
|
|
if (!participant->left_) {
|
|
|
|
joined_date = participant->date_;
|
|
|
|
if ((participant->flags_ & telegram_api::groupCallParticipant::ACTIVE_DATE_MASK) != 0) {
|
|
|
|
active_date = participant->active_date_;
|
|
|
|
}
|
2020-12-11 15:43:23 +01:00
|
|
|
if (joined_date < 0 || active_date < 0) {
|
|
|
|
LOG(ERROR) << "Receive invalid " << to_string(participant);
|
|
|
|
joined_date = 0;
|
|
|
|
active_date = 0;
|
|
|
|
}
|
2020-12-08 15:29:25 +01:00
|
|
|
}
|
2020-12-11 15:43:23 +01:00
|
|
|
is_just_joined = participant->just_joined_;
|
2021-02-01 20:29:45 +01:00
|
|
|
is_min = (participant->flags_ & telegram_api::groupCallParticipant::MIN_MASK) != 0;
|
2020-12-08 15:29:25 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 13:20:05 +01:00
|
|
|
bool GroupCallParticipant::is_versioned_update(const tl_object_ptr<telegram_api::groupCallParticipant> &participant) {
|
|
|
|
return participant->just_joined_ || participant->left_ || participant->versioned_;
|
|
|
|
}
|
|
|
|
|
2020-12-17 00:07:05 +01:00
|
|
|
bool GroupCallParticipant::update_can_be_muted(bool can_manage, bool is_self, bool is_admin) {
|
2020-12-31 00:48:45 +01:00
|
|
|
bool new_can_be_muted_for_all_users = false;
|
|
|
|
bool new_can_be_unmuted_for_all_users = false;
|
|
|
|
bool new_can_be_muted_only_for_self = !can_manage && !is_muted_only_for_self;
|
|
|
|
bool new_can_be_unmuted_only_for_self = !can_manage && is_muted_only_for_self;
|
2020-12-17 00:07:05 +01:00
|
|
|
if (is_self) {
|
|
|
|
// current user can be muted if !is_muted; after that is_muted && can_self_unmute
|
|
|
|
// current user can be unmuted if is_muted && can_self_unmute; after that !is_muted
|
2020-12-31 00:48:45 +01:00
|
|
|
new_can_be_muted_for_all_users = !is_muted;
|
|
|
|
new_can_be_unmuted_for_all_users = is_muted && can_self_unmute;
|
|
|
|
new_can_be_muted_only_for_self = false;
|
|
|
|
new_can_be_unmuted_only_for_self = false;
|
2020-12-17 00:07:05 +01:00
|
|
|
} else if (is_admin) {
|
|
|
|
// admin user can be muted if can_manage && !is_muted; after that is_muted && can_self_unmute
|
|
|
|
// admin user can't be unmuted
|
2020-12-31 00:48:45 +01:00
|
|
|
new_can_be_muted_for_all_users = can_manage && !is_muted;
|
2020-12-17 00:07:05 +01:00
|
|
|
} else {
|
2020-12-31 00:48:45 +01:00
|
|
|
// other users can be muted if can_manage; after that is_muted && !can_self_unmute
|
|
|
|
// other users can be unmuted if can_manage && is_muted && !can_self_unmute; after that is_muted && can_self_unmute
|
|
|
|
new_can_be_muted_for_all_users = can_manage && (!is_muted || can_self_unmute);
|
|
|
|
new_can_be_unmuted_for_all_users = can_manage && is_muted && !can_self_unmute;
|
2020-12-17 00:07:05 +01:00
|
|
|
}
|
2020-12-31 00:48:45 +01:00
|
|
|
if (new_can_be_muted_for_all_users != can_be_muted_for_all_users ||
|
|
|
|
new_can_be_unmuted_for_all_users != can_be_unmuted_for_all_users ||
|
|
|
|
new_can_be_muted_only_for_self != can_be_muted_only_for_self ||
|
|
|
|
new_can_be_unmuted_only_for_self != can_be_unmuted_only_for_self) {
|
|
|
|
can_be_muted_for_all_users = new_can_be_muted_for_all_users;
|
|
|
|
can_be_unmuted_for_all_users = new_can_be_unmuted_for_all_users;
|
|
|
|
can_be_muted_only_for_self = new_can_be_muted_only_for_self;
|
|
|
|
can_be_unmuted_only_for_self = new_can_be_unmuted_only_for_self;
|
2020-12-17 00:07:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-11 15:43:23 +01:00
|
|
|
td_api::object_ptr<td_api::groupCallParticipant> GroupCallParticipant::get_group_call_participant_object(
|
|
|
|
ContactsManager *contacts_manager) const {
|
2020-12-08 15:29:25 +01:00
|
|
|
if (!is_valid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return td_api::make_object<td_api::groupCallParticipant>(
|
2021-01-11 13:02:02 +01:00
|
|
|
contacts_manager->get_user_id_object(user_id, "get_group_call_participant_object"), audio_source, is_speaking,
|
2020-12-31 00:48:45 +01:00
|
|
|
can_be_muted_for_all_users, can_be_unmuted_for_all_users, can_be_muted_only_for_self,
|
2021-01-26 00:00:12 +01:00
|
|
|
can_be_unmuted_only_for_self, is_muted, can_self_unmute, volume_level, order);
|
2020-12-11 15:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const GroupCallParticipant &lhs, const GroupCallParticipant &rhs) {
|
2021-01-26 00:00:12 +01:00
|
|
|
return lhs.user_id == rhs.user_id && lhs.audio_source == rhs.audio_source &&
|
2020-12-31 00:48:45 +01:00
|
|
|
lhs.can_be_muted_for_all_users == rhs.can_be_muted_for_all_users &&
|
|
|
|
lhs.can_be_unmuted_for_all_users == rhs.can_be_unmuted_for_all_users &&
|
|
|
|
lhs.can_be_muted_only_for_self == rhs.can_be_muted_only_for_self &&
|
|
|
|
lhs.can_be_unmuted_only_for_self == rhs.can_be_unmuted_only_for_self && lhs.is_muted == rhs.is_muted &&
|
2020-12-31 01:10:41 +01:00
|
|
|
lhs.can_self_unmute == rhs.can_self_unmute && lhs.is_speaking == rhs.is_speaking &&
|
|
|
|
lhs.volume_level == rhs.volume_level && lhs.order == rhs.order;
|
2020-12-11 15:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const GroupCallParticipant &lhs, const GroupCallParticipant &rhs) {
|
|
|
|
return !(lhs == rhs);
|
2020-12-08 15:29:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const GroupCallParticipant &group_call_participant) {
|
2021-01-11 13:02:02 +01:00
|
|
|
return string_builder << '[' << group_call_participant.user_id << " with source "
|
|
|
|
<< group_call_participant.audio_source << " and order " << group_call_participant.order << ']';
|
2020-12-08 15:29:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|