Add GroupCallId class.

This commit is contained in:
levlam 2020-12-03 19:52:50 +03:00
parent 2da4316a06
commit 34e05375c1
13 changed files with 315 additions and 230 deletions

View File

@ -601,7 +601,7 @@ supergroup id:int32 username:string date:int32 status:ChatMemberStatus member_co
//@invite_link Invite link for this chat
//@upgraded_from_basic_group_id Identifier of the basic group from which supergroup was upgraded; 0 if none
//@upgraded_from_max_message_id Identifier of the last message in the basic group from which supergroup was upgraded; 0 if none
supergroupFullInfo photo:chatPhoto description:string member_count:int32 administrator_count:int32 restricted_count:int32 banned_count:int32 linked_chat_id:int53 group_call_id:string slow_mode_delay:int32 slow_mode_delay_expires_in:double can_get_members:Bool can_set_username:Bool can_set_sticker_set:Bool can_set_location:Bool can_get_statistics:Bool is_all_history_available:Bool sticker_set_id:int64 location:chatLocation invite_link:string upgraded_from_basic_group_id:int32 upgraded_from_max_message_id:int53 = SupergroupFullInfo;
supergroupFullInfo photo:chatPhoto description:string member_count:int32 administrator_count:int32 restricted_count:int32 banned_count:int32 linked_chat_id:int53 group_call_id:int32 slow_mode_delay:int32 slow_mode_delay_expires_in:double can_get_members:Bool can_set_username:Bool can_set_sticker_set:Bool can_set_location:Bool can_get_statistics:Bool is_all_history_available:Bool sticker_set_id:int64 location:chatLocation invite_link:string upgraded_from_basic_group_id:int32 upgraded_from_max_message_id:int53 = SupergroupFullInfo;
//@class SecretChatState @description Describes the current secret chat state
@ -1634,10 +1634,10 @@ messageInvoice title:string description:string photo:photo currency:string total
messageCall is_video:Bool discard_reason:CallDiscardReason duration:int32 = MessageContent;
//@description A message with information about a group call @group_call_id Group call identifier @duration Call duration; for finished calls only
messageGroupCall group_call_id:string duration:int32 = MessageContent;
messageGroupCall group_call_id:int32 duration:int32 = MessageContent;
//@description A message with information about an invite to a group call @group_call_id Group call identifier @user_ids Invited user identifiers
messageInviteGroupCallMembers group_call_id:string user_ids:vector<int32> = MessageContent;
messageInviteGroupCallMembers group_call_id:int32 user_ids:vector<int32> = MessageContent;
//@description A newly created basic group @title Title of the basic group @member_user_ids User identifiers of members in the basic group
messageBasicGroupChatCreate title:string member_user_ids:vector<int32> = MessageContent;
@ -2039,7 +2039,7 @@ callServer id:int64 ip_address:string ipv6_address:string port:int32 type:CallSe
callId id:int32 = CallId;
//@description Contains the group call identifier @id Group call identifier
groupCallId id:string = GroupCallId;
groupCallId id:int32 = GroupCallId;
//@class CallState @description Describes the current call state
@ -2070,7 +2070,7 @@ callStateError error:error = CallState;
//@mute_new_members True, if only group call administrators can unmute new members
//@allowed_change_mute_new_members True, if group call administrators can enable or disable mute_new_members setting
//@duration Call duration; for ended calls only
groupCall id:string is_active:Bool member_count:int32 mute_new_members:Bool allowed_change_mute_new_members:Bool duration:int32 = GroupCall;
groupCall id:int32 is_active:Bool member_count:int32 mute_new_members:Bool allowed_change_mute_new_members:Bool duration:int32 = GroupCall;
//@description Describes a payload fingerprint for interaction with tgcalls @hash Value of the field hash @setup Value of the field setup @fingerprint Value of the field fingerprint
groupCallPayloadFingerprint hash:string setup:string fingerprint:string = GroupCallPayloadFingerprint;
@ -4331,31 +4331,31 @@ sendCallDebugInformation call_id:int32 debug_information:string = Ok;
createVoiceChat chat_id:int53 = GroupCallId;
//@description Returns information about a group call @group_call_id Group call identifier
getGroupCall group_call_id:string = GroupCall;
getGroupCall group_call_id:int32 = GroupCall;
//@description Joins a group call @group_call_id Group call identifier @payload Group join payload, received from tgcalls @source Caller synchronization source identifier; received from tgcalls @is_muted True, if the user's microphone is muted
joinGroupCall group_call_id:string payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse;
joinGroupCall group_call_id:int32 payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse;
//@description Toggles whether new members of a group call can be unmuted only by administrators of the group call. Requires can_manage_calls rights in the corresponding chat and allowed_change_mute_mew_members group call flag
//@group_call_id Group call identifier @mute_new_members New value of the mute_new_members setting
toggleGroupCallMuteNewMembers group_call_id:string mute_new_members:Bool = Ok;
toggleGroupCallMuteNewMembers group_call_id:int32 mute_new_members:Bool = Ok;
//@description Invites users to a group call. Sends a service message of type messageInviteToGroupCall for voice chats
//@group_call_id Group call identifier @user_ids User identifiers
inviteGroupCallMembers group_call_id:string user_ids:vector<int32> = Ok;
inviteGroupCallMembers group_call_id:int32 user_ids:vector<int32> = Ok;
//@description Toggles whether a group call member is muted. Requires can_manage_calls rights to mute other group call members
//@group_call_id Group call identifier @user_id User identifier @is_muted Pass true if the user must be muted and false otherwise
toggleGroupCallMemberIsMuted group_call_id:string user_id:int32 is_muted:Bool = Ok;
toggleGroupCallMemberIsMuted group_call_id:int32 user_id:int32 is_muted:Bool = Ok;
//@description Checks group call source for validness. If the method returns an error with a message "GROUP_CALL_JOIN_MISSING", the call needs to be rejoined @group_call_id Group call identifier @source Caller synchronization source identifier
checkGroupCallSource group_call_id:string source:int32 = Ok;
checkGroupCallSource group_call_id:int32 source:int32 = Ok;
//@description Leaves a group call @group_call_id Group call identifier @source Caller synchronization source identifier
leaveGroupCall group_call_id:string source:int32 = Ok;
leaveGroupCall group_call_id:int32 source:int32 = Ok;
//@description Discards a group call. Requires can_manage_calls rights in the corresponding chat @group_call_id Group call identifier
discardGroupCall group_call_id:string = Ok;
discardGroupCall group_call_id:int32 = Ok;
//@description Changes the block state of a message sender. Currently, only users and supergroup chats can be blocked @sender Message Sender @is_blocked New value of is_blocked

Binary file not shown.

View File

@ -5914,7 +5914,7 @@ void ContactsManager::set_channel_slow_mode_delay(DialogId dialog_id, int32 slow
td_->create_handler<ToggleSlowModeQuery>(std::move(promise))->send(channel_id, slow_mode_delay);
}
void ContactsManager::create_channel_voice_chat(DialogId dialog_id, Promise<InputGroupCallId> &&promise) {
void ContactsManager::create_channel_voice_chat(DialogId dialog_id, Promise<GroupCallId> &&promise) {
if (!dialog_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid chat identifier specified"));
}
@ -5950,12 +5950,12 @@ void ContactsManager::create_channel_voice_chat(DialogId dialog_id, Promise<Inpu
send_closure(G()->group_call_manager(), &GroupCallManager::create_voice_chat, channel_id, std::move(new_promise));
}
void ContactsManager::on_create_channel_group_call(ChannelId channel_id, InputGroupCallId group_call_id,
Promise<InputGroupCallId> &&promise) {
void ContactsManager::on_create_channel_group_call(ChannelId channel_id, InputGroupCallId input_group_call_id,
Promise<GroupCallId> &&promise) {
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
}
if (!group_call_id.is_valid()) {
if (!input_group_call_id.is_valid()) {
return promise.set_error(Status::Error(500, "Receive invalid group call identifier"));
}
@ -5968,12 +5968,12 @@ void ContactsManager::on_create_channel_group_call(ChannelId channel_id, InputGr
}
auto channel_full = get_channel_full_force(channel_id, "on_create_channel_group_call");
if (channel_full != nullptr && channel_full->active_group_call_id != group_call_id) {
channel_full->active_group_call_id = group_call_id;
if (channel_full != nullptr && channel_full->active_group_call_id != input_group_call_id) {
channel_full->active_group_call_id = input_group_call_id;
channel_full->is_changed = true;
update_channel_full(channel_full, channel_id);
}
promise.set_value(std::move(group_call_id));
promise.set_value(td_->group_call_manager_->get_group_call_id(input_group_call_id));
}
void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics,
@ -9613,12 +9613,12 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
LOG(ERROR) << "Receive can_view_statistics == true, but invalid statistics DC ID in " << channel_id;
can_view_statistics = false;
}
InputGroupCallId group_call_id;
InputGroupCallId input_group_call_id;
if (channel_full->call_ != nullptr) {
group_call_id = InputGroupCallId(channel_full->call_);
if (group_call_id.is_valid() && !c->is_megagroup) {
LOG(ERROR) << "Receive " << group_call_id << " in " << channel_id;
group_call_id = InputGroupCallId();
input_group_call_id = InputGroupCallId(channel_full->call_);
if (input_group_call_id.is_valid() && !c->is_megagroup) {
LOG(ERROR) << "Receive " << input_group_call_id << " in " << channel_id;
input_group_call_id = InputGroupCallId();
}
}
@ -9657,12 +9657,12 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
channel->need_save_to_database = true;
}
if (channel->active_group_call_id != group_call_id) {
channel->active_group_call_id = group_call_id;
bool has_active_group_call = group_call_id.is_valid();
if (channel->active_group_call_id != input_group_call_id) {
channel->active_group_call_id = input_group_call_id;
bool has_active_group_call = input_group_call_id.is_valid();
if (c->has_active_group_call != has_active_group_call) {
LOG(ERROR) << "Receive invalid has_active_group_call flag " << c->has_active_group_call << ", but have "
<< group_call_id << " in " << channel_id;
<< input_group_call_id << " in " << channel_id;
c->has_active_group_call = has_active_group_call;
c->is_changed = true;
update_channel(c, channel_id);
@ -14398,10 +14398,11 @@ tl_object_ptr<td_api::supergroupFullInfo> ContactsManager::get_supergroup_full_i
get_chat_photo_object(td_->file_manager_.get(), channel_full->photo), channel_full->description,
channel_full->participant_count, channel_full->administrator_count, channel_full->restricted_count,
channel_full->banned_count, DialogId(channel_full->linked_channel_id).get(),
channel_full->active_group_call_id.get_group_call_id(), channel_full->slow_mode_delay, slow_mode_delay_expires_in,
channel_full->can_get_participants, channel_full->can_set_username, channel_full->can_set_sticker_set,
channel_full->can_set_location, channel_full->can_view_statistics, channel_full->is_all_history_available,
channel_full->sticker_set_id.get(), channel_full->location.get_chat_location_object(), channel_full->invite_link,
td_->group_call_manager_->get_group_call_id(channel_full->active_group_call_id).get(),
channel_full->slow_mode_delay, slow_mode_delay_expires_in, channel_full->can_get_participants,
channel_full->can_set_username, channel_full->can_set_sticker_set, channel_full->can_set_location,
channel_full->can_view_statistics, channel_full->is_all_history_available, channel_full->sticker_set_id.get(),
channel_full->location.get_chat_location_object(), channel_full->invite_link,
get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"),
channel_full->migrated_from_max_message_id.get());
}

View File

@ -21,6 +21,7 @@
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/FolderId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/GroupCallId.h"
#include "td/telegram/InputGroupCallId.h"
#include "td/telegram/Location.h"
#include "td/telegram/MessageId.h"
@ -365,7 +366,7 @@ class ContactsManager : public Actor {
void set_channel_slow_mode_delay(DialogId dialog_id, int32 slow_mode_delay, Promise<Unit> &&promise);
void create_channel_voice_chat(DialogId dialog_id, Promise<InputGroupCallId> &&promise);
void create_channel_voice_chat(DialogId dialog_id, Promise<GroupCallId> &&promise);
void report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
Promise<Unit> &&promise);
@ -1317,8 +1318,8 @@ class ContactsManager : public Actor {
void update_bot_info(BotInfo *bot_info, UserId user_id, bool send_update, bool from_database);
void on_create_channel_group_call(ChannelId channel_id, InputGroupCallId group_call_id,
Promise<InputGroupCallId> &&promise);
void on_create_channel_group_call(ChannelId channel_id, InputGroupCallId input_group_call_id,
Promise<GroupCallId> &&promise);
bool is_chat_full_outdated(const ChatFull *chat_full, const Chat *c, ChatId chat_id);

59
td/telegram/GroupCallId.h Normal file
View File

@ -0,0 +1,59 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
//
// 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
#include "td/telegram/td_api.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
#include <functional>
#include <type_traits>
namespace td {
class GroupCallId {
public:
GroupCallId() = default;
explicit GroupCallId(int32 group_call_id) : id(group_call_id) {
}
template <class T, typename = std::enable_if_t<std::is_convertible<T, int32>::value>>
GroupCallId(T group_call_id) = delete;
bool is_valid() const {
return id > 0;
}
int32 get() const {
return id;
}
auto get_group_call_id_object() const {
return td_api::make_object<td_api::groupCallId>(id);
}
bool operator==(const GroupCallId &other) const {
return id == other.id;
}
private:
int32 id{0};
};
struct GroupCallIdHash {
std::size_t operator()(GroupCallId group_call_id) const {
return std::hash<int32>()(group_call_id.get());
}
};
inline StringBuilder &operator<<(StringBuilder &sb, const GroupCallId group_call_id) {
return sb << "group call " << group_call_id.get();
}
} // namespace td

View File

@ -65,17 +65,15 @@ class CreateGroupCallQuery : public Td::ResultHandler {
class GetGroupCallQuery : public Td::ResultHandler {
Promise<tl_object_ptr<telegram_api::phone_groupCall>> promise_;
InputGroupCallId group_call_id_;
public:
explicit GetGroupCallQuery(Promise<tl_object_ptr<telegram_api::phone_groupCall>> &&promise)
: promise_(std::move(promise)) {
}
void send(InputGroupCallId group_call_id) {
group_call_id_ = group_call_id;
send_query(G()->net_query_creator().create(telegram_api::phone_getGroupCall(group_call_id.get_input_group_call())));
void send(InputGroupCallId input_group_call_id) {
send_query(
G()->net_query_creator().create(telegram_api::phone_getGroupCall(input_group_call_id.get_input_group_call())));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -97,15 +95,15 @@ class GetGroupCallQuery : public Td::ResultHandler {
class JoinGroupCallQuery : public Td::ResultHandler {
Promise<Unit> promise_;
InputGroupCallId group_call_id_;
InputGroupCallId input_group_call_id_;
uint64 generation_ = 0;
public:
explicit JoinGroupCallQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
NetQueryRef send(InputGroupCallId group_call_id, const string &payload, bool is_muted, uint64 generation) {
group_call_id_ = group_call_id;
NetQueryRef send(InputGroupCallId input_group_call_id, const string &payload, bool is_muted, uint64 generation) {
input_group_call_id_ = input_group_call_id;
generation_ = generation;
int32 flags = 0;
@ -113,7 +111,7 @@ class JoinGroupCallQuery : public Td::ResultHandler {
flags |= telegram_api::phone_joinGroupCall::MUTED_MASK;
}
auto query = G()->net_query_creator().create(
telegram_api::phone_joinGroupCall(flags, false /*ignored*/, group_call_id.get_input_group_call(),
telegram_api::phone_joinGroupCall(flags, false /*ignored*/, input_group_call_id.get_input_group_call(),
make_tl_object<telegram_api::dataJSON>(payload)));
auto join_query_ref = query.get_weak();
send_query(std::move(query));
@ -126,8 +124,8 @@ class JoinGroupCallQuery : public Td::ResultHandler {
return on_error(id, result_ptr.move_as_error());
}
td->group_call_manager_->process_join_group_call_response(group_call_id_, generation_, result_ptr.move_as_ok(),
std::move(promise_));
td->group_call_manager_->process_join_group_call_response(input_group_call_id_, generation_,
result_ptr.move_as_ok(), std::move(promise_));
}
void on_error(uint64 id, Status status) override {
@ -142,9 +140,9 @@ class ToggleGroupCallSettingsQuery : public Td::ResultHandler {
explicit ToggleGroupCallSettingsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(int32 flags, InputGroupCallId group_call_id, bool join_muted) {
void send(int32 flags, InputGroupCallId input_group_call_id, bool join_muted) {
send_query(G()->net_query_creator().create(
telegram_api::phone_toggleGroupCallSettings(flags, group_call_id.get_input_group_call(), join_muted)));
telegram_api::phone_toggleGroupCallSettings(flags, input_group_call_id.get_input_group_call(), join_muted)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -173,9 +171,9 @@ class InviteToGroupCallQuery : public Td::ResultHandler {
explicit InviteToGroupCallQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId group_call_id, vector<tl_object_ptr<telegram_api::InputUser>> input_users) {
void send(InputGroupCallId input_group_call_id, vector<tl_object_ptr<telegram_api::InputUser>> input_users) {
send_query(G()->net_query_creator().create(
telegram_api::phone_inviteToGroupCall(group_call_id.get_input_group_call(), std::move(input_users))));
telegram_api::phone_inviteToGroupCall(input_group_call_id.get_input_group_call(), std::move(input_users))));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -204,7 +202,7 @@ class EditGroupCallMemberQuery : public Td::ResultHandler {
explicit EditGroupCallMemberQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId group_call_id, UserId user_id, bool is_muted) {
void send(InputGroupCallId input_group_call_id, UserId user_id, bool is_muted) {
auto input_user = td->contacts_manager_->get_input_user(user_id);
CHECK(input_user != nullptr);
@ -214,7 +212,7 @@ class EditGroupCallMemberQuery : public Td::ResultHandler {
}
send_query(G()->net_query_creator().create(telegram_api::phone_editGroupCallMember(
flags, false /*ignored*/, group_call_id.get_input_group_call(), std::move(input_user))));
flags, false /*ignored*/, input_group_call_id.get_input_group_call(), std::move(input_user))));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -243,9 +241,9 @@ class CheckGroupCallQuery : public Td::ResultHandler {
explicit CheckGroupCallQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId group_call_id, int32 source) {
void send(InputGroupCallId input_group_call_id, int32 source) {
send_query(G()->net_query_creator().create(
telegram_api::phone_checkGroupCall(group_call_id.get_input_group_call(), source)));
telegram_api::phone_checkGroupCall(input_group_call_id.get_input_group_call(), source)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -276,9 +274,9 @@ class LeaveGroupCallQuery : public Td::ResultHandler {
explicit LeaveGroupCallQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId group_call_id, int32 source) {
void send(InputGroupCallId input_group_call_id, int32 source) {
send_query(G()->net_query_creator().create(
telegram_api::phone_leaveGroupCall(group_call_id.get_input_group_call(), source)));
telegram_api::phone_leaveGroupCall(input_group_call_id.get_input_group_call(), source)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -307,9 +305,9 @@ class DiscardGroupCallQuery : public Td::ResultHandler {
explicit DiscardGroupCallQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId group_call_id) {
send_query(
G()->net_query_creator().create(telegram_api::phone_discardGroupCall(group_call_id.get_input_group_call())));
void send(InputGroupCallId input_group_call_id) {
send_query(G()->net_query_creator().create(
telegram_api::phone_discardGroupCall(input_group_call_id.get_input_group_call())));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -332,6 +330,8 @@ class DiscardGroupCallQuery : public Td::ResultHandler {
};
struct GroupCallManager::GroupCall {
GroupCallId group_call_id;
bool is_inited = false;
bool is_active = false;
bool mute_new_members = false;
bool allowed_change_mute_new_members = false;
@ -355,54 +355,86 @@ void GroupCallManager::tear_down() {
parent_.reset();
}
GroupCallId GroupCallManager::get_group_call_id(InputGroupCallId input_group_call_id) {
return add_group_call(input_group_call_id)->group_call_id;
}
Result<InputGroupCallId> GroupCallManager::get_input_group_call_id(GroupCallId group_call_id) {
if (!group_call_id.is_valid()) {
return Status::Error(400, "Invalid group call identifier specified");
}
if (group_call_id.get() <= 0 || group_call_id.get() > max_group_call_id_.get()) {
return Status::Error(400, "Wrong group call identifier specified");
}
CHECK(static_cast<size_t>(group_call_id.get()) <= input_group_call_ids_.size());
return input_group_call_ids_[group_call_id.get() - 1];
}
GroupCallId GroupCallManager::get_next_group_call_id(InputGroupCallId input_group_call_id) {
max_group_call_id_ = GroupCallId(max_group_call_id_.get() + 1);
input_group_call_ids_.push_back(input_group_call_id);
return max_group_call_id_;
}
GroupCallManager::GroupCall *GroupCallManager::add_group_call(InputGroupCallId input_group_call_id) {
auto &group_call = group_calls_[input_group_call_id];
if (group_call == nullptr) {
group_call = make_unique<GroupCall>();
group_call->group_call_id = get_next_group_call_id(input_group_call_id);
}
return group_call.get();
}
const GroupCallManager::GroupCall *GroupCallManager::get_group_call(InputGroupCallId input_group_call_id) const {
auto it = group_calls_.find(input_group_call_id);
if (it == group_calls_.end()) {
return nullptr;
} else {
return it->second.get();
}
}
GroupCallManager::GroupCall *GroupCallManager::get_group_call(InputGroupCallId input_group_call_id) {
auto it = group_calls_.find(input_group_call_id);
if (it == group_calls_.end()) {
return nullptr;
} else {
return it->second.get();
}
}
void GroupCallManager::create_voice_chat(ChannelId channel_id, Promise<InputGroupCallId> &&promise) {
td_->create_handler<CreateGroupCallQuery>(std::move(promise))->send(channel_id);
}
const GroupCallManager::GroupCall *GroupCallManager::get_group_call(InputGroupCallId group_call_id) const {
auto it = group_calls_.find(group_call_id);
if (it == group_calls_.end()) {
return nullptr;
} else {
return it->second.get();
}
}
GroupCallManager::GroupCall *GroupCallManager::get_group_call(InputGroupCallId group_call_id) {
auto it = group_calls_.find(group_call_id);
if (it == group_calls_.end()) {
return nullptr;
} else {
return it->second.get();
}
}
void GroupCallManager::get_group_call(InputGroupCallId group_call_id,
void GroupCallManager::get_group_call(GroupCallId group_call_id,
Promise<td_api::object_ptr<td_api::groupCall>> &&promise) {
auto group_call = get_group_call(group_call_id);
if (group_call != nullptr) {
return promise.set_value(get_group_call_object(group_call_id, group_call));
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
auto group_call = get_group_call(input_group_call_id);
if (group_call != nullptr && group_call->is_inited) {
return promise.set_value(get_group_call_object(group_call));
}
reload_group_call(group_call_id, std::move(promise));
reload_group_call(input_group_call_id, std::move(promise));
}
void GroupCallManager::reload_group_call(InputGroupCallId group_call_id,
void GroupCallManager::reload_group_call(InputGroupCallId input_group_call_id,
Promise<td_api::object_ptr<td_api::groupCall>> &&promise) {
auto &queries = load_group_call_queries_[group_call_id];
auto &queries = load_group_call_queries_[input_group_call_id];
queries.push_back(std::move(promise));
if (queries.size() == 1) {
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), group_call_id](Result<tl_object_ptr<telegram_api::phone_groupCall>> &&result) {
send_closure(actor_id, &GroupCallManager::finish_get_group_call, group_call_id, std::move(result));
});
td_->create_handler<GetGroupCallQuery>(std::move(query_promise))->send(group_call_id);
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), input_group_call_id](
Result<tl_object_ptr<telegram_api::phone_groupCall>> &&result) {
send_closure(actor_id, &GroupCallManager::finish_get_group_call, input_group_call_id, std::move(result));
});
td_->create_handler<GetGroupCallQuery>(std::move(query_promise))->send(input_group_call_id);
}
}
void GroupCallManager::finish_get_group_call(InputGroupCallId group_call_id,
void GroupCallManager::finish_get_group_call(InputGroupCallId input_group_call_id,
Result<tl_object_ptr<telegram_api::phone_groupCall>> &&result) {
auto it = load_group_call_queries_.find(group_call_id);
auto it = load_group_call_queries_.find(input_group_call_id);
CHECK(it != load_group_call_queries_.end());
CHECK(!it->second.empty());
auto promises = std::move(it->second);
@ -412,8 +444,8 @@ void GroupCallManager::finish_get_group_call(InputGroupCallId group_call_id,
td_->contacts_manager_->on_get_users(std::move(result.ok_ref()->users_), "finish_get_group_call");
auto call_id = update_group_call(result.ok()->call_);
if (call_id != group_call_id) {
LOG(ERROR) << "Expected " << group_call_id << ", but received " << to_string(result.ok());
if (call_id != input_group_call_id) {
LOG(ERROR) << "Expected " << input_group_call_id << ", but received " << to_string(result.ok());
result = Status::Error(500, "Receive another group call");
}
}
@ -425,19 +457,20 @@ void GroupCallManager::finish_get_group_call(InputGroupCallId group_call_id,
return;
}
auto group_call = get_group_call(group_call_id);
CHECK(group_call != nullptr);
auto group_call = get_group_call(input_group_call_id);
for (auto &promise : promises) {
promise.set_value(get_group_call_object(group_call_id, group_call));
promise.set_value(get_group_call_object(group_call));
}
}
void GroupCallManager::join_group_call(InputGroupCallId group_call_id,
void GroupCallManager::join_group_call(GroupCallId group_call_id,
td_api::object_ptr<td_api::groupCallPayload> &&payload, int32 source,
bool is_muted,
Promise<td_api::object_ptr<td_api::groupCallJoinResponse>> &&promise) {
if (pending_join_requests_.count(group_call_id)) {
auto it = pending_join_requests_.find(group_call_id);
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
if (pending_join_requests_.count(input_group_call_id)) {
auto it = pending_join_requests_.find(input_group_call_id);
CHECK(it != pending_join_requests_.end());
CHECK(it->second != nullptr);
if (!it->second->query_ref.empty()) {
@ -486,27 +519,27 @@ void GroupCallManager::join_group_call(InputGroupCallId group_call_id,
}));
auto generation = ++join_group_request_generation_;
auto &request = pending_join_requests_[group_call_id];
auto &request = pending_join_requests_[input_group_call_id];
request = make_unique<PendingJoinRequest>();
request->generation = generation;
request->promise = std::move(promise);
auto query_promise =
PromiseCreator::lambda([actor_id = actor_id(this), generation, group_call_id](Result<Unit> &&result) {
PromiseCreator::lambda([actor_id = actor_id(this), generation, input_group_call_id](Result<Unit> &&result) {
CHECK(result.is_error());
send_closure(actor_id, &GroupCallManager::finish_join_group_call, group_call_id, generation,
send_closure(actor_id, &GroupCallManager::finish_join_group_call, input_group_call_id, generation,
result.move_as_error());
});
request->query_ref = td_->create_handler<JoinGroupCallQuery>(std::move(query_promise))
->send(group_call_id, json_payload, is_muted, generation);
->send(input_group_call_id, json_payload, is_muted, generation);
}
void GroupCallManager::process_join_group_call_response(InputGroupCallId group_call_id, uint64 generation,
void GroupCallManager::process_join_group_call_response(InputGroupCallId input_group_call_id, uint64 generation,
tl_object_ptr<telegram_api::Updates> &&updates,
Promise<Unit> &&promise) {
auto it = pending_join_requests_.find(group_call_id);
auto it = pending_join_requests_.find(input_group_call_id);
if (it == pending_join_requests_.end() || it->second->generation != generation) {
LOG(INFO) << "Ignore JoinGroupCallQuery response with " << group_call_id << " and generation " << generation;
LOG(INFO) << "Ignore JoinGroupCallQuery response with " << input_group_call_id << " and generation " << generation;
return;
}
@ -580,8 +613,8 @@ Result<td_api::object_ptr<td_api::groupCallJoinResponse>> GroupCallManager::get_
return td_api::make_object<td_api::groupCallJoinResponse>(std::move(payload), std::move(candidates_object));
}
void GroupCallManager::on_join_group_call_response(InputGroupCallId group_call_id, string json_response) {
auto it = pending_join_requests_.find(group_call_id);
void GroupCallManager::on_join_group_call_response(InputGroupCallId input_group_call_id, string json_response) {
auto it = pending_join_requests_.find(input_group_call_id);
if (it == pending_join_requests_.end()) {
return;
}
@ -597,9 +630,9 @@ void GroupCallManager::on_join_group_call_response(InputGroupCallId group_call_i
pending_join_requests_.erase(it);
}
void GroupCallManager::finish_join_group_call(InputGroupCallId group_call_id, uint64 generation, Status error) {
void GroupCallManager::finish_join_group_call(InputGroupCallId input_group_call_id, uint64 generation, Status error) {
CHECK(error.is_error());
auto it = pending_join_requests_.find(group_call_id);
auto it = pending_join_requests_.find(input_group_call_id);
if (it == pending_join_requests_.end() || (generation != 0 && it->second->generation != generation)) {
return;
}
@ -607,14 +640,19 @@ void GroupCallManager::finish_join_group_call(InputGroupCallId group_call_id, ui
pending_join_requests_.erase(it);
}
void GroupCallManager::toggle_group_call_mute_new_members(InputGroupCallId group_call_id, bool mute_new_members,
void GroupCallManager::toggle_group_call_mute_new_members(GroupCallId group_call_id, bool mute_new_members,
Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
int32 flags = telegram_api::phone_toggleGroupCallSettings::JOIN_MUTED_MASK;
td_->create_handler<ToggleGroupCallSettingsQuery>(std::move(promise))->send(flags, group_call_id, mute_new_members);
td_->create_handler<ToggleGroupCallSettingsQuery>(std::move(promise))
->send(flags, input_group_call_id, mute_new_members);
}
void GroupCallManager::invite_group_call_members(InputGroupCallId group_call_id, vector<UserId> &&user_ids,
void GroupCallManager::invite_group_call_members(GroupCallId group_call_id, vector<UserId> &&user_ids,
Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
auto my_user_id = td_->contacts_manager_->get_my_id();
for (auto user_id : user_ids) {
@ -634,27 +672,32 @@ void GroupCallManager::invite_group_call_members(InputGroupCallId group_call_id,
return promise.set_value(Unit());
}
td_->create_handler<InviteToGroupCallQuery>(std::move(promise))->send(group_call_id, std::move(input_users));
td_->create_handler<InviteToGroupCallQuery>(std::move(promise))->send(input_group_call_id, std::move(input_users));
}
void GroupCallManager::toggle_group_call_member_is_muted(InputGroupCallId group_call_id, UserId user_id, bool is_muted,
void GroupCallManager::toggle_group_call_member_is_muted(GroupCallId group_call_id, UserId user_id, bool is_muted,
Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
if (!td_->contacts_manager_->have_input_user(user_id)) {
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
td_->create_handler<EditGroupCallMemberQuery>(std::move(promise))->send(group_call_id, user_id, is_muted);
td_->create_handler<EditGroupCallMemberQuery>(std::move(promise))->send(input_group_call_id, user_id, is_muted);
}
void GroupCallManager::check_group_call_source(InputGroupCallId group_call_id, int32 source, Promise<Unit> &&promise) {
td_->create_handler<CheckGroupCallQuery>(std::move(promise))->send(group_call_id, source);
void GroupCallManager::check_group_call_source(GroupCallId group_call_id, int32 source, Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
td_->create_handler<CheckGroupCallQuery>(std::move(promise))->send(input_group_call_id, source);
}
void GroupCallManager::leave_group_call(InputGroupCallId group_call_id, int32 source, Promise<Unit> &&promise) {
td_->create_handler<LeaveGroupCallQuery>(std::move(promise))->send(group_call_id, source);
void GroupCallManager::leave_group_call(GroupCallId group_call_id, int32 source, Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
td_->create_handler<LeaveGroupCallQuery>(std::move(promise))->send(input_group_call_id, source);
}
void GroupCallManager::discard_group_call(InputGroupCallId group_call_id, Promise<Unit> &&promise) {
td_->create_handler<DiscardGroupCallQuery>(std::move(promise))->send(group_call_id);
void GroupCallManager::discard_group_call(GroupCallId group_call_id, Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id));
td_->create_handler<DiscardGroupCallQuery>(std::move(promise))->send(input_group_call_id);
}
void GroupCallManager::on_update_group_call(tl_object_ptr<telegram_api::GroupCall> group_call_ptr) {
@ -671,6 +714,7 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptr<telegra
InputGroupCallId call_id;
GroupCall call;
call.is_inited = true;
switch (group_call_ptr->get_id()) {
case telegram_api::groupCall::ID: {
auto group_call = static_cast<const telegram_api::groupCall *>(group_call_ptr.get());
@ -699,10 +743,10 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptr<telegra
return {};
}
auto &group_call = group_calls_[call_id];
bool need_update = false;
if (group_call == nullptr) {
group_call = make_unique<GroupCall>();
auto *group_call = add_group_call(call_id);
if (!group_call->is_inited) {
call.group_call_id = group_call->group_call_id;
*group_call = std::move(call);
need_update = true;
} else {
@ -729,23 +773,22 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptr<telegra
}
if (need_update) {
send_closure(G()->td(), &Td::send_update, get_update_group_call_object(call_id, group_call.get()));
send_closure(G()->td(), &Td::send_update, get_update_group_call_object(group_call));
}
return call_id;
}
tl_object_ptr<td_api::groupCall> GroupCallManager::get_group_call_object(InputGroupCallId group_call_id,
const GroupCall *group_call) {
tl_object_ptr<td_api::groupCall> GroupCallManager::get_group_call_object(const GroupCall *group_call) {
CHECK(group_call != nullptr);
return td_api::make_object<td_api::groupCall>(group_call_id.get_group_call_id(), group_call->is_active,
CHECK(group_call->is_inited);
return td_api::make_object<td_api::groupCall>(group_call->group_call_id.get(), group_call->is_active,
group_call->member_count, group_call->mute_new_members,
group_call->allowed_change_mute_new_members, group_call->duration);
}
tl_object_ptr<td_api::updateGroupCall> GroupCallManager::get_update_group_call_object(InputGroupCallId group_call_id,
const GroupCall *group_call) {
return td_api::make_object<td_api::updateGroupCall>(get_group_call_object(group_call_id, group_call));
tl_object_ptr<td_api::updateGroupCall> GroupCallManager::get_update_group_call_object(const GroupCall *group_call) {
return td_api::make_object<td_api::updateGroupCall>(get_group_call_object(group_call));
}
} // namespace td

View File

@ -7,6 +7,7 @@
#pragma once
#include "td/telegram/ChannelId.h"
#include "td/telegram/GroupCallId.h"
#include "td/telegram/InputGroupCallId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
@ -15,6 +16,8 @@
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/Status.h"
#include <unordered_map>
namespace td {
@ -30,31 +33,31 @@ class GroupCallManager : public Actor {
GroupCallManager &operator=(GroupCallManager &&) = delete;
~GroupCallManager() override;
GroupCallId get_group_call_id(InputGroupCallId input_group_call_id);
void create_voice_chat(ChannelId channel_id, Promise<InputGroupCallId> &&promise);
void get_group_call(InputGroupCallId group_call_id, Promise<td_api::object_ptr<td_api::groupCall>> &&promise);
void get_group_call(GroupCallId group_call_id, Promise<td_api::object_ptr<td_api::groupCall>> &&promise);
void join_group_call(InputGroupCallId group_call_id, td_api::object_ptr<td_api::groupCallPayload> &&payload,
int32 source, bool is_muted,
Promise<td_api::object_ptr<td_api::groupCallJoinResponse>> &&promise);
void join_group_call(GroupCallId group_call_id, td_api::object_ptr<td_api::groupCallPayload> &&payload, int32 source,
bool is_muted, Promise<td_api::object_ptr<td_api::groupCallJoinResponse>> &&promise);
void toggle_group_call_mute_new_members(InputGroupCallId group_call_id, bool mute_new_members,
Promise<Unit> &&promise);
void toggle_group_call_mute_new_members(GroupCallId group_call_id, bool mute_new_members, Promise<Unit> &&promise);
void invite_group_call_members(InputGroupCallId group_call_id, vector<UserId> &&user_ids, Promise<Unit> &&promise);
void invite_group_call_members(GroupCallId group_call_id, vector<UserId> &&user_ids, Promise<Unit> &&promise);
void toggle_group_call_member_is_muted(InputGroupCallId group_call_id, UserId user_id, bool is_muted,
void toggle_group_call_member_is_muted(GroupCallId group_call_id, UserId user_id, bool is_muted,
Promise<Unit> &&promise);
void check_group_call_source(InputGroupCallId group_call_id, int32 source, Promise<Unit> &&promise);
void check_group_call_source(GroupCallId group_call_id, int32 source, Promise<Unit> &&promise);
void leave_group_call(InputGroupCallId group_call_id, int32 source, Promise<Unit> &&promise);
void leave_group_call(GroupCallId group_call_id, int32 source, Promise<Unit> &&promise);
void discard_group_call(InputGroupCallId group_call_id, Promise<Unit> &&promise);
void discard_group_call(GroupCallId group_call_id, Promise<Unit> &&promise);
void on_update_group_call(tl_object_ptr<telegram_api::GroupCall> group_call_ptr);
void process_join_group_call_response(InputGroupCallId group_call_id, uint64 generation,
void process_join_group_call_response(InputGroupCallId input_group_call_id, uint64 generation,
tl_object_ptr<telegram_api::Updates> &&updates, Promise<Unit> &&promise);
private:
@ -63,32 +66,41 @@ class GroupCallManager : public Actor {
void tear_down() override;
const GroupCall *get_group_call(InputGroupCallId group_call_id) const;
GroupCall *get_group_call(InputGroupCallId group_call_id);
Result<InputGroupCallId> get_input_group_call_id(GroupCallId group_call_id);
void reload_group_call(InputGroupCallId group_call_id, Promise<td_api::object_ptr<td_api::groupCall>> &&promise);
GroupCallId get_next_group_call_id(InputGroupCallId input_group_call_id);
void finish_get_group_call(InputGroupCallId group_call_id,
GroupCall *add_group_call(InputGroupCallId input_group_call_id);
const GroupCall *get_group_call(InputGroupCallId input_group_call_id) const;
GroupCall *get_group_call(InputGroupCallId input_group_call_id);
void reload_group_call(InputGroupCallId input_group_call_id,
Promise<td_api::object_ptr<td_api::groupCall>> &&promise);
void finish_get_group_call(InputGroupCallId input_group_call_id,
Result<tl_object_ptr<telegram_api::phone_groupCall>> &&result);
void on_join_group_call_response(InputGroupCallId group_call_id, string json_response);
void on_join_group_call_response(InputGroupCallId input_group_call_id, string json_response);
void finish_join_group_call(InputGroupCallId group_call_id, uint64 generation, Status error);
void finish_join_group_call(InputGroupCallId input_group_call_id, uint64 generation, Status error);
InputGroupCallId update_group_call(const tl_object_ptr<telegram_api::GroupCall> &group_call_ptr);
static Result<td_api::object_ptr<td_api::groupCallJoinResponse>> get_group_call_join_response_object(
string json_response);
static tl_object_ptr<td_api::updateGroupCall> get_update_group_call_object(InputGroupCallId group_call_id,
const GroupCall *group_call);
static tl_object_ptr<td_api::updateGroupCall> get_update_group_call_object(const GroupCall *group_call);
static tl_object_ptr<td_api::groupCall> get_group_call_object(InputGroupCallId group_call_id,
const GroupCall *group_call);
static tl_object_ptr<td_api::groupCall> get_group_call_object(const GroupCall *group_call);
Td *td_;
ActorShared<> parent_;
GroupCallId max_group_call_id_;
vector<InputGroupCallId> input_group_call_ids_;
std::unordered_map<InputGroupCallId, unique_ptr<GroupCall>, InputGroupCallIdHash> group_calls_;
std::unordered_map<InputGroupCallId, vector<Promise<td_api::object_ptr<td_api::groupCall>>>, InputGroupCallIdHash>

View File

@ -15,37 +15,12 @@ InputGroupCallId::InputGroupCallId(const tl_object_ptr<telegram_api::inputGroupC
: group_call_id(input_group_call->id_), access_hash(input_group_call->access_hash_) {
}
Result<InputGroupCallId> InputGroupCallId::from_group_call_id(const string &group_call_id, bool allow_empty) {
if (group_call_id.empty()) {
if (!allow_empty) {
return Status::Error(400, "Empty group call identifier specified");
}
return InputGroupCallId();
}
auto splitted = split(group_call_id, '_');
auto r_group_call_id = to_integer_safe<int64>(splitted.first);
auto r_access_hash = to_integer_safe<int64>(splitted.second);
if (r_group_call_id.is_error() || r_access_hash.is_error()) {
return Status::Error(400, "Invalid group call identifier specified");
}
return InputGroupCallId{r_group_call_id.ok(), r_access_hash.ok()};
}
string InputGroupCallId::get_group_call_id() const {
if (is_valid()) {
return PSTRING() << group_call_id << '_' << access_hash;
}
return string();
}
tl_object_ptr<telegram_api::inputGroupCall> InputGroupCallId::get_input_group_call() const {
return make_tl_object<telegram_api::inputGroupCall>(group_call_id, access_hash);
}
StringBuilder &operator<<(StringBuilder &string_builder, InputGroupCallId input_group_call_id) {
return string_builder << "group call " << input_group_call_id.group_call_id;
return string_builder << "input group call " << input_group_call_id.group_call_id;
}
} // namespace td

View File

@ -9,7 +9,6 @@
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
#include <functional>
@ -28,10 +27,6 @@ class InputGroupCallId {
InputGroupCallId(int64 group_call_id, int64 access_hash) : group_call_id(group_call_id), access_hash(access_hash) {
}
static Result<InputGroupCallId> from_group_call_id(const string &group_call_id, bool allow_empty = false);
string get_group_call_id() const;
bool operator==(const InputGroupCallId &other) const {
return group_call_id == other.group_call_id;
}

View File

@ -27,6 +27,8 @@
#include "td/telegram/Game.h"
#include "td/telegram/Game.hpp"
#include "td/telegram/Global.h"
#include "td/telegram/GroupCallId.h"
#include "td/telegram/GroupCallManager.h"
#include "td/telegram/HashtagHints.h"
#include "td/telegram/InputGroupCallId.h"
#include "td/telegram/InputMessageText.h"
@ -709,11 +711,12 @@ class MessageProximityAlertTriggered : public MessageContent {
class MessageGroupCall : public MessageContent {
public:
InputGroupCallId group_call_id;
InputGroupCallId input_group_call_id;
int32 duration = -1;
MessageGroupCall() = default;
MessageGroupCall(InputGroupCallId group_call_id, int32 duration) : group_call_id(group_call_id), duration(duration) {
MessageGroupCall(InputGroupCallId input_group_call_id, int32 duration)
: input_group_call_id(input_group_call_id), duration(duration) {
}
MessageContentType get_type() const override {
@ -723,12 +726,12 @@ class MessageGroupCall : public MessageContent {
class MessageInviteToGroupCall : public MessageContent {
public:
InputGroupCallId group_call_id;
InputGroupCallId input_group_call_id;
vector<UserId> user_ids;
MessageInviteToGroupCall() = default;
MessageInviteToGroupCall(InputGroupCallId group_call_id, vector<UserId> &&user_ids)
: group_call_id(group_call_id), user_ids(std::move(user_ids)) {
MessageInviteToGroupCall(InputGroupCallId input_group_call_id, vector<UserId> &&user_ids)
: input_group_call_id(input_group_call_id), user_ids(std::move(user_ids)) {
}
MessageContentType get_type() const override {
@ -1014,7 +1017,7 @@ static void store(const MessageContent *content, StorerT &storer) {
BEGIN_STORE_FLAGS();
STORE_FLAG(has_duration);
END_STORE_FLAGS();
store(m->group_call_id, storer);
store(m->input_group_call_id, storer);
if (has_duration) {
store(m->duration, storer);
}
@ -1022,7 +1025,7 @@ static void store(const MessageContent *content, StorerT &storer) {
}
case MessageContentType::InviteToGroupCall: {
auto m = static_cast<const MessageInviteToGroupCall *>(content);
store(m->group_call_id, storer);
store(m->input_group_call_id, storer);
store(m->user_ids, storer);
break;
}
@ -1406,7 +1409,7 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_duration);
END_PARSE_FLAGS();
parse(m->group_call_id, parser);
parse(m->input_group_call_id, parser);
if (has_duration) {
parse(m->duration, parser);
}
@ -1415,7 +1418,7 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
}
case MessageContentType::InviteToGroupCall: {
auto m = make_unique<MessageInviteToGroupCall>();
parse(m->group_call_id, parser);
parse(m->input_group_call_id, parser);
parse(m->user_ids, parser);
content = std::move(m);
break;
@ -3300,10 +3303,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::GroupCall: {
auto old_ = static_cast<const MessageGroupCall *>(old_content);
auto new_ = static_cast<const MessageGroupCall *>(new_content);
if (old_->group_call_id != new_->group_call_id || old_->duration != new_->duration) {
if (old_->input_group_call_id != new_->input_group_call_id || old_->duration != new_->duration) {
need_update = true;
}
if (!old_->group_call_id.is_identical(new_->group_call_id)) {
if (!old_->input_group_call_id.is_identical(new_->input_group_call_id)) {
is_content_changed = true;
}
break;
@ -3311,10 +3314,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::InviteToGroupCall: {
auto old_ = static_cast<const MessageInviteToGroupCall *>(old_content);
auto new_ = static_cast<const MessageInviteToGroupCall *>(new_content);
if (old_->group_call_id != new_->group_call_id || old_->user_ids != new_->user_ids) {
if (old_->input_group_call_id != new_->input_group_call_id || old_->user_ids != new_->user_ids) {
need_update = true;
}
if (!old_->group_call_id.is_identical(new_->group_call_id)) {
if (!old_->input_group_call_id.is_identical(new_->input_group_call_id)) {
is_content_changed = true;
}
break;
@ -4783,13 +4786,14 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::GroupCall: {
auto *m = static_cast<const MessageGroupCall *>(content);
return make_tl_object<td_api::messageGroupCall>(m->group_call_id.get_group_call_id(),
m->duration >= 0 ? max(m->duration, 1) : 0);
return make_tl_object<td_api::messageGroupCall>(
td->group_call_manager_->get_group_call_id(m->input_group_call_id).get(),
m->duration >= 0 ? max(m->duration, 1) : 0);
}
case MessageContentType::InviteToGroupCall: {
auto *m = static_cast<const MessageInviteToGroupCall *>(content);
return make_tl_object<td_api::messageInviteGroupCallMembers>(
m->group_call_id.get_group_call_id(),
td->group_call_manager_->get_group_call_id(m->input_group_call_id).get(),
td->contacts_manager_->get_user_ids_object(m->user_ids, "MessageInviteToGroupCall"));
}
default:

View File

@ -6030,11 +6030,11 @@ void Td::on_request(uint64 id, td_api::sendCallDebugInformation &request) {
void Td::on_request(uint64 id, const td_api::createVoiceChat &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<InputGroupCallId> result) mutable {
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<GroupCallId> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(td_api::make_object<td_api::groupCallId>(result.ok().get_group_call_id()));
promise.set_value(td_api::make_object<td_api::groupCallId>(result.ok().get()));
}
});
@ -6044,71 +6044,66 @@ void Td::on_request(uint64 id, const td_api::createVoiceChat &request) {
void Td::on_request(uint64 id, const td_api::getGroupCall &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
group_call_manager_->get_group_call(group_call_id, std::move(promise));
group_call_manager_->get_group_call(GroupCallId(request.group_call_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::joinGroupCall &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
group_call_manager_->join_group_call(group_call_id, std::move(request.payload_), request.source_, request.is_muted_,
std::move(promise));
group_call_manager_->join_group_call(GroupCallId(request.group_call_id_), std::move(request.payload_),
request.source_, request.is_muted_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::toggleGroupCallMuteNewMembers &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
group_call_manager_->toggle_group_call_mute_new_members(group_call_id, request.mute_new_members_, std::move(promise));
group_call_manager_->toggle_group_call_mute_new_members(GroupCallId(request.group_call_id_),
request.mute_new_members_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::inviteGroupCallMembers &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
vector<UserId> user_ids;
for (auto &user_id : request.user_ids_) {
user_ids.emplace_back(user_id);
}
group_call_manager_->invite_group_call_members(group_call_id, std::move(user_ids), std::move(promise));
group_call_manager_->invite_group_call_members(GroupCallId(request.group_call_id_), std::move(user_ids),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::toggleGroupCallMemberIsMuted &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
group_call_manager_->toggle_group_call_member_is_muted(group_call_id, UserId(request.user_id_), request.is_muted_,
std::move(promise));
group_call_manager_->toggle_group_call_member_is_muted(GroupCallId(request.group_call_id_), UserId(request.user_id_),
request.is_muted_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::checkGroupCallSource &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
group_call_manager_->check_group_call_source(group_call_id, request.source_, std::move(promise));
group_call_manager_->check_group_call_source(GroupCallId(request.group_call_id_), request.source_,
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::leaveGroupCall &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
group_call_manager_->leave_group_call(group_call_id, request.source_, std::move(promise));
group_call_manager_->leave_group_call(GroupCallId(request.group_call_id_), request.source_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::discardGroupCall &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_));
group_call_manager_->discard_group_call(group_call_id, std::move(promise));
group_call_manager_->discard_group_call(GroupCallId(request.group_call_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request) {

View File

@ -904,25 +904,25 @@ vector<const tl_object_ptr<telegram_api::Message> *> UpdatesManager::get_new_mes
}
vector<InputGroupCallId> UpdatesManager::get_update_new_group_call_ids(const telegram_api::Updates *updates_ptr) {
vector<InputGroupCallId> group_call_ids;
vector<InputGroupCallId> input_group_call_ids;
auto updates = get_updates(updates_ptr);
if (updates != nullptr) {
for (auto &update : *updates) {
InputGroupCallId group_call_id;
InputGroupCallId input_group_call_id;
if (update->get_id() == telegram_api::updateGroupCall::ID) {
auto group_call_ptr = static_cast<const telegram_api::updateGroupCall *>(update.get())->call_.get();
if (group_call_ptr->get_id() == telegram_api::groupCall::ID) {
auto group_call = static_cast<const telegram_api::groupCall *>(group_call_ptr);
group_call_id = InputGroupCallId(group_call->id_, group_call->access_hash_);
input_group_call_id = InputGroupCallId(group_call->id_, group_call->access_hash_);
}
}
if (group_call_id.is_valid()) {
group_call_ids.push_back(group_call_id);
if (input_group_call_id.is_valid()) {
input_group_call_ids.push_back(input_group_call_id);
}
}
}
return group_call_ids;
return input_group_call_ids;
}
vector<DialogId> UpdatesManager::get_update_notify_settings_dialog_ids(const telegram_api::Updates *updates_ptr) {

View File

@ -632,8 +632,8 @@ class CliClient final : public Actor {
return to_integer<int32>(trim(std::move(str)));
}
static string as_group_call_id(string str) {
return trim(std::move(str));
static int32 as_group_call_id(string str) {
return to_integer<int32>(trim(std::move(str)));
}
static int32 as_proxy_id(string str) {