From 3c9cd417762e3f7918baacc47b405c8a2d0024bf Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 Nov 2020 17:29:09 +0300 Subject: [PATCH 1/6] Add GroupCallId. --- td/generate/scheme/td_api.tl | 11 +++++++---- td/generate/scheme/td_api.tlo | Bin 185548 -> 185780 bytes td/telegram/InputGroupCallId.cpp | 26 ++++++++++++++++++++++++++ td/telegram/InputGroupCallId.h | 5 +++++ td/telegram/MessageContent.cpp | 22 ++++++++++++++-------- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 93f303939..9bf3120f0 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1627,11 +1627,11 @@ messageInvoice title:string description:string photo:photo currency:string total //@description A message with information about an ended call @is_video True, if the call was a video call @discard_reason Reason why the call was discarded @duration Call duration, in seconds messageCall is_video:Bool discard_reason:CallDiscardReason duration:int32 = MessageContent; -//@description A message with information about a group call -messageGroupCall = MessageContent; +//@description A message with information about a group call @group_call_id Group call identifier +messageGroupCall group_call_id:string = MessageContent; -//@description A message with information about an invite to a group call -messageInviteToGroupCall = MessageContent; +//@description A message with information about an invite to a group call @group_call_id Group call identifier @user_id Invited user identifier +messageInviteToGroupCall group_call_id:string user_id: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 = MessageContent; @@ -2032,6 +2032,9 @@ callServer id:int64 ip_address:string ipv6_address:string port:int32 type:CallSe //@description Contains the call identifier @id Call identifier callId id:int32 = CallId; +//@description Contains the group call identifier @id Group call identifier +groupCallId id:string = GroupCallId; + //@class CallState @description Describes the current call state diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 98e28653a62d7cbd1f244115e9ba131dab25429d..6c3fc23bb95abbe36448017cdb54846e6f6f4bf2 100644 GIT binary patch delta 1314 zcmaJ=Ur1A76z`bUYzn(N=jQJ8Zf^d;fkr+ou^Me@pEyLZXbARXj&iDI$=X|do zYGaSIm0xbPcWqNX%ah7APWO1-{#4r=IDc`{Gwk;t8I5MRA3IB5-|3o+CQON17>Hil zz2}NaE*sC6N&g?7SM>wA@T`GM9@msgNOUP0J}Hx_z`+SQTI>OyEUoG20}fhPF3W+P zMSnO5u_#mp0*i!R=w94kqGx|O5ighINT-#M8Fw4$|D>?})yRodLy*;L^k6q)z2r3D z+2PdeyPA?P>eVX@lDXHx2)7ZUNj)}k)f8(I6tfDq2Er`j4PaMgZYS4MZPY0$r#B2} zI%y~{Qbtm52dJwS-N$NCS9o2~RbfPP9Y*M|OY(7Y@9KB?_6BASYR`>LO%0EadC!cD z$@XTAkY##&Cg52VHi6P{S;aCcR$5n}s+%jojCyml{_do?ye;!!}&gv<+FmY%s@8oNiRG_;Mpm00VgkIJdsA zQw}sV??B;c70Wrm%euIl@VJR4@H6av6ArPW8D-5i7kRGnbTee{mdR^ItuLSO^6a<81|iZ%hCm%^=Fb%$DekLCbT*vWh88{LK1WAV6Z~c1}=%ah14EoiP%F# zG0}IZgIjx9@=&`0H$_qG9;qEUqT5zc5<$?n)18vmv*cjj; zFArMTw%$E8p;h+U^~_{4o$f?I%fV@@DRteL#=`H@L~sJX``tWo;#$ZakjPIbL}{#u z3kzu%<}bJ)K&u+|$c>QX#jS^Td?9;`BF wX+aP%i7Y~zVpS1G`9s9SnZS^@uv`ql<}>vZwDT6+<&_%DbNxW%E9Bb$04G3^`~Uy| diff --git a/td/telegram/InputGroupCallId.cpp b/td/telegram/InputGroupCallId.cpp index b50b039d7..69f05a66d 100644 --- a/td/telegram/InputGroupCallId.cpp +++ b/td/telegram/InputGroupCallId.cpp @@ -7,6 +7,7 @@ #include "td/telegram/InputGroupCallId.h" #include "td/utils/logging.h" +#include "td/utils/misc.h" namespace td { @@ -14,6 +15,31 @@ InputGroupCallId::InputGroupCallId(const tl_object_ptrid_), access_hash(input_group_call->access_hash_) { } +Result InputGroupCallId::from_group_call_id(const string &group_call_id) { + if (group_call_id.empty()) { + return InputGroupCallId(); + } + + auto splitted = split(group_call_id, '_'); + auto r_group_call_id = to_integer_safe(splitted.first); + auto r_access_hash = to_integer_safe(splitted.second); + if (r_group_call_id.is_error() || r_access_hash.is_error()) { + return Status::Error("Invalid group call identifier specified"); + } + + InputGroupCallId result; + result.group_call_id = r_group_call_id.ok(); + result.access_hash = r_access_hash.ok(); + return result; +} + +string InputGroupCallId::get_group_call_id() const { + if (is_valid()) { + return PSTRING() << group_call_id << '_' << access_hash; + } + return string(); +} + tl_object_ptr InputGroupCallId::get_input_group_call() const { return make_tl_object(group_call_id, access_hash); } diff --git a/td/telegram/InputGroupCallId.h b/td/telegram/InputGroupCallId.h index a1db1a5bb..7107f764d 100644 --- a/td/telegram/InputGroupCallId.h +++ b/td/telegram/InputGroupCallId.h @@ -9,6 +9,7 @@ #include "td/telegram/telegram_api.h" #include "td/utils/common.h" +#include "td/utils/Status.h" #include "td/utils/StringBuilder.h" namespace td { @@ -22,6 +23,10 @@ class InputGroupCallId { explicit InputGroupCallId(const tl_object_ptr &input_group_call); + static Result from_group_call_id(const string &group_call_id); + + string get_group_call_id() const; + bool operator==(const InputGroupCallId &other) const { return group_call_id == other.group_call_id && access_hash == other.access_hash; } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index cc52b6708..62f4a48cc 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4024,7 +4024,7 @@ unique_ptr get_message_content(Td *td, FormattedText message, auto message_contact = move_tl_object_as(media); if (message_contact->user_id_ != 0) { td->contacts_manager_->get_user_id_object(UserId(message_contact->user_id_), - "messageMediaContact"); // to ensure updateUser + "MessageMediaContact"); // to ensure updateUser } return make_unique(Contact( std::move(message_contact->phone_number_), std::move(message_contact->first_name_), @@ -4677,12 +4677,12 @@ tl_object_ptr get_message_content_object(const MessageCo case MessageContentType::ChatDeleteUser: { const MessageChatDeleteUser *m = static_cast(content); return make_tl_object( - td->contacts_manager_->get_user_id_object(m->user_id, "messageChatDeleteMember")); + td->contacts_manager_->get_user_id_object(m->user_id, "MessageChatDeleteMember")); } case MessageContentType::ChatMigrateTo: { const MessageChatMigrateTo *m = static_cast(content); return make_tl_object( - td->contacts_manager_->get_supergroup_id_object(m->migrated_to_channel_id, "messageChatUpgradeTo")); + td->contacts_manager_->get_supergroup_id_object(m->migrated_to_channel_id, "MessageChatUpgradeTo")); } case MessageContentType::ChannelCreate: { const MessageChannelCreate *m = static_cast(content); @@ -4692,7 +4692,7 @@ tl_object_ptr get_message_content_object(const MessageCo const MessageChannelMigrateFrom *m = static_cast(content); return make_tl_object( m->title, - td->contacts_manager_->get_basic_group_id_object(m->migrated_from_chat_id, "messageChatUpgradeFrom")); + td->contacts_manager_->get_basic_group_id_object(m->migrated_from_chat_id, "MessageChatUpgradeFrom")); } case MessageContentType::PinMessage: { const MessagePinMessage *m = static_cast(content); @@ -4768,10 +4768,16 @@ tl_object_ptr get_message_content_object(const MessageCo td->messages_manager_->get_message_sender_object(m->traveler_dialog_id), td->messages_manager_->get_message_sender_object(m->watcher_dialog_id), m->distance); } - case MessageContentType::GroupCall: - return make_tl_object(); - case MessageContentType::InviteToGroupCall: - return make_tl_object(); + case MessageContentType::GroupCall: { + auto *m = static_cast(content); + return make_tl_object(m->group_call_id.get_group_call_id()); + } + case MessageContentType::InviteToGroupCall: { + auto *m = static_cast(content); + return make_tl_object( + m->group_call_id.get_group_call_id(), + td->contacts_manager_->get_user_id_object(m->user_id, "MessageInviteToGroupCall")); + } default: UNREACHABLE(); return nullptr; From bd75c4b062b58ed98fa65cc71ef354e355369e2b Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 Nov 2020 18:22:00 +0300 Subject: [PATCH 2/6] Add GroupCallManager. --- CMakeLists.txt | 2 ++ td/telegram/Td.cpp | 8 ++++++++ td/telegram/Td.h | 3 +++ 3 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e5253e85..2b6972eb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -319,6 +319,7 @@ set(TDLIB_SOURCE td/telegram/files/ResourceManager.cpp td/telegram/Game.cpp td/telegram/Global.cpp + td/telegram/GroupCallManager.cpp td/telegram/HashtagHints.cpp td/telegram/InlineQueriesManager.cpp td/telegram/InputDialogId.cpp @@ -492,6 +493,7 @@ set(TDLIB_SOURCE td/telegram/FullMessageId.h td/telegram/Game.h td/telegram/Global.h + td/telegram/GroupCallManager.h td/telegram/HashtagHints.h td/telegram/InlineQueriesManager.h td/telegram/InputDialogId.h diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 1570ae3e0..7320118ae 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -43,6 +43,7 @@ #include "td/telegram/FolderId.h" #include "td/telegram/FullMessageId.h" #include "td/telegram/Global.h" +#include "td/telegram/GroupCallManager.h" #include "td/telegram/HashtagHints.h" #include "td/telegram/InlineQueriesManager.h" #include "td/telegram/JsonValue.h" @@ -3893,6 +3894,8 @@ void Td::dec_actor_refcnt() { LOG(DEBUG) << "FileManager was cleared" << timer; file_reference_manager_.reset(); LOG(DEBUG) << "FileReferenceManager was cleared" << timer; + group_call_manager_.reset(); + LOG(DEBUG) << "GroupCallManager was cleared" << timer; inline_queries_manager_.reset(); LOG(DEBUG) << "InlineQueriesManager was cleared" << timer; messages_manager_.reset(); @@ -4077,6 +4080,8 @@ void Td::clear() { LOG(DEBUG) << "FileManager actor was cleared" << timer; file_reference_manager_actor_.reset(); LOG(DEBUG) << "FileReferenceManager actor was cleared" << timer; + group_call_manager_actor_.reset(); + LOG(DEBUG) << "GroupCallManager actor was cleared" << timer; inline_queries_manager_actor_.reset(); LOG(DEBUG) << "InlineQueriesManager actor was cleared" << timer; messages_manager_actor_.reset(); // TODO: Stop silent @@ -4510,6 +4515,8 @@ void Td::init_managers() { G()->set_contacts_manager(contacts_manager_actor_.get()); country_info_manager_ = make_unique(this, create_reference()); country_info_manager_actor_ = register_actor("CountryInfoManager", country_info_manager_.get()); + group_call_manager_ = make_unique(this, create_reference()); + group_call_manager_actor_ = register_actor("GroupCallManager", group_call_manager_.get()); inline_queries_manager_ = make_unique(this, create_reference()); inline_queries_manager_actor_ = register_actor("InlineQueriesManager", inline_queries_manager_.get()); messages_manager_ = make_unique(this, create_reference()); @@ -4925,6 +4932,7 @@ void Td::on_request(uint64 id, const td_api::getCurrentState &request) { // TODO updateFileGenerationStart generation_id:int64 original_path:string destination_path:string conversion:string = Update; // TODO updateCall call:call = Update; + // TODO updateGroupCall call:groupCall = Update; } auto update_terms_of_service = get_update_terms_of_service_object(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 7ac4f8b2e..e3df46310 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -51,6 +51,7 @@ class DeviceTokenManager; class DocumentsManager; class FileManager; class FileReferenceManager; +class GroupCallManager; class InlineQueriesManager; class HashtagHints; class LanguagePackManager; @@ -157,6 +158,8 @@ class Td final : public NetQueryCallback { ActorOwn file_manager_actor_; unique_ptr file_reference_manager_; ActorOwn file_reference_manager_actor_; + unique_ptr group_call_manager_; + ActorOwn group_call_manager_actor_; unique_ptr inline_queries_manager_; ActorOwn inline_queries_manager_actor_; unique_ptr messages_manager_; From cc47f9b63f1db8b3f851909542ca5ae790dc429a Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 25 Nov 2020 17:04:32 +0300 Subject: [PATCH 3/6] Support updateGroupCall. --- td/generate/scheme/td_api.tl | 14 +++++++-- td/generate/scheme/td_api.tlo | Bin 185780 -> 186180 bytes td/telegram/ContactsManager.cpp | 47 ++++++++++++++++++++++++++----- td/telegram/ContactsManager.h | 6 ++++ td/telegram/Global.h | 9 ++++++ td/telegram/InputGroupCallId.cpp | 7 ++--- td/telegram/InputGroupCallId.h | 21 +++++++++++++- td/telegram/MessageContent.cpp | 9 +++++- td/telegram/Td.cpp | 1 + td/telegram/UpdatesManager.cpp | 8 ++++-- td/telegram/UpdatesManager.h | 4 +-- 11 files changed, 104 insertions(+), 22 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 9bf3120f0..48270c432 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -566,13 +566,14 @@ basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int32 memb //@member_count Number of members in the supergroup or channel; 0 if unknown. Currently it is guaranteed to be known only if the supergroup or channel was received through searchPublicChats, searchChatsNearby, getInactiveSupergroupChats, getSuitableDiscussionChats, getGroupsInCommon, or getUserPrivacySettingRules //@has_linked_chat True, if the channel has a discussion group, or the supergroup is the designated discussion group for a channel //@has_location True, if the supergroup is connected to a location, i.e. the supergroup is a location-based supergroup +//@has_active_call True, if the supergroup has active group call //@sign_messages True, if messages sent to the channel should contain information about the sender. This field is only applicable to channels //@is_slow_mode_enabled True, if the slow mode is enabled in the supergroup //@is_channel True, if the supergroup is a channel //@is_verified True, if the supergroup or channel is verified //@restriction_reason If non-empty, contains a human-readable description of the reason why access to this supergroup or channel must be restricted //@is_scam True, if many users reported this supergroup as a scam -supergroup id:int32 username:string date:int32 status:ChatMemberStatus member_count:int32 has_linked_chat:Bool has_location:Bool sign_messages:Bool is_slow_mode_enabled:Bool is_channel:Bool is_verified:Bool restriction_reason:string is_scam:Bool = Supergroup; +supergroup id:int32 username:string date:int32 status:ChatMemberStatus member_count:int32 has_linked_chat:Bool has_location:Bool has_active_call:Bool sign_messages:Bool is_slow_mode_enabled:Bool is_channel:Bool is_verified:Bool restriction_reason:string is_scam:Bool = Supergroup; //@description Contains full information about a supergroup or channel //@photo Chat photo; may be null @@ -1627,8 +1628,8 @@ messageInvoice title:string description:string photo:photo currency:string total //@description A message with information about an ended call @is_video True, if the call was a video call @discard_reason Reason why the call was discarded @duration Call duration, in seconds 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 -messageGroupCall group_call_id:string = 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; //@description A message with information about an invite to a group call @group_call_id Group call identifier @user_id Invited user identifier messageInviteToGroupCall group_call_id:string user_id:int32 = MessageContent; @@ -2057,6 +2058,10 @@ callStateDiscarded reason:CallDiscardReason need_rating:Bool need_debug_informat callStateError error:error = CallState; +//@description Describes a group call @id Group call identifier @is_active True, if the call is active @member_count Number of members in the group call @duration Call duration; for ended calls only +groupCall id:string is_active:Bool member_count:int32 duration:int32 = GroupCall; + + //@class CallProblem @description Describes the exact type of a problem with a call //@description The user heard their own voice @@ -3334,6 +3339,9 @@ updateFileGenerationStop generation_id:int64 = Update; //@description New call was created or information about a call was updated @call New data about a call updateCall call:call = Update; +//@description Information about a group call was updated @group_call New data about the call +updateGroupCall group_call:groupCall = Update; + //@description New call signaling data arrived @call_id The call identifier @data The data updateNewCallSignalingData call_id:int32 data:bytes = Update; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 6c3fc23bb95abbe36448017cdb54846e6f6f4bf2..d2a08422109488fca903546ae03081a4944e907f 100644 GIT binary patch delta 3335 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 @@ -3784,6 +3791,7 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) { bool is_slow_mode_delay_active; bool has_stats_dc_id; bool has_photo; + bool has_active_group_call_id; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_description); PARSE_FLAG(has_administrator_count); @@ -3808,6 +3816,7 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) { PARSE_FLAG(has_photo); PARSE_FLAG(is_can_view_statistics_inited); PARSE_FLAG(can_view_statistics); + PARSE_FLAG(has_active_group_call_id); END_PARSE_FLAGS(); if (has_description) { parse(description, parser); @@ -3856,6 +3865,9 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) { if (has_photo) { parse(photo, parser); } + if (has_active_group_call_id) { + parse(active_group_call_id, parser); + } if (legacy_can_view_statistics) { LOG(DEBUG) << "Ignore legacy can view statistics flag"; @@ -9532,6 +9544,10 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c LOG(ERROR) << "Receive can_view_statistics == true, but invalid statistics DC ID in " << channel_id; can_view_statistics = false; } + InputGroupCallId group_call_id; + if (channel_full->call_ != nullptr) { + group_call_id = InputGroupCallId(channel_full->call_); + } channel->repair_request_version = 0; channel->expires_at = Time::now() + CHANNEL_FULL_EXPIRE_TIME; @@ -9568,6 +9584,17 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&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 (c->has_active_group_call != has_active_group_call) { + LOG(ERROR) << "Receive invalid has_active_group_call flag " << c->has_active_group_call; + c->has_active_group_call = has_active_group_call; + c->is_changed = true; + update_channel(c, channel_id); + } + } + on_update_channel_full_photo( channel, channel_id, get_photo(td_->file_manager_.get(), std::move(channel_full->chat_photo_), DialogId(channel_id))); @@ -13822,6 +13849,7 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char bool has_linked_channel = (channel.flags_ & CHANNEL_FLAG_HAS_LINKED_CHAT) != 0; bool has_location = (channel.flags_ & CHANNEL_FLAG_HAS_LOCATION) != 0; + bool has_active_group_call = (channel.flags_ & CHANNEL_FLAG_HAS_ACTIVE_GROUP_CALL) != 0; bool sign_messages = (channel.flags_ & CHANNEL_FLAG_SIGN_MESSAGES) != 0; bool is_slow_mode_enabled = (channel.flags_ & CHANNEL_FLAG_IS_SLOW_MODE_ENABLED) != 0; bool is_megagroup = (channel.flags_ & CHANNEL_FLAG_IS_MEGAGROUP) != 0; @@ -13926,10 +13954,12 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char bool need_invalidate_channel_full = false; if (c->has_linked_channel != has_linked_channel || c->has_location != has_location || - c->sign_messages != sign_messages || c->is_megagroup != is_megagroup || c->is_verified != is_verified || + c->has_active_group_call != has_active_group_call || c->sign_messages != sign_messages || + c->is_megagroup != is_megagroup || c->is_verified != is_verified || c->restriction_reasons != restriction_reasons || c->is_scam != is_scam) { c->has_linked_channel = has_linked_channel; c->has_location = has_location; + c->has_active_group_call = has_active_group_call; c->sign_messages = sign_messages; c->is_slow_mode_enabled = is_slow_mode_enabled; c->is_megagroup = is_megagroup; @@ -13990,6 +14020,7 @@ void ContactsManager::on_chat_update(telegram_api::channelForbidden &channel, co tl_object_ptr banned_rights; // == nullptr on_update_channel_default_permissions(c, channel_id, get_restricted_rights(banned_rights)); + bool has_active_group_call = false; bool sign_messages = false; bool is_slow_mode_enabled = false; bool is_megagroup = (channel.flags_ & CHANNEL_FLAG_IS_MEGAGROUP) != 0; @@ -14013,11 +14044,12 @@ void ContactsManager::on_chat_update(telegram_api::channelForbidden &channel, co } bool need_invalidate_channel_full = false; - if (c->sign_messages != sign_messages || c->is_slow_mode_enabled != is_slow_mode_enabled || - c->is_megagroup != is_megagroup || c->is_verified != is_verified || !c->restriction_reasons.empty() || - c->is_scam != is_scam) { + if (c->has_active_group_call != has_active_group_call || c->sign_messages != sign_messages || + c->is_slow_mode_enabled != is_slow_mode_enabled || c->is_megagroup != is_megagroup || + c->is_verified != is_verified || !c->restriction_reasons.empty() || c->is_scam != is_scam) { // c->has_linked_channel = has_linked_channel; // c->has_location = has_location; + c->has_active_group_call = has_active_group_call; c->sign_messages = sign_messages; c->is_slow_mode_enabled = is_slow_mode_enabled; c->is_megagroup = is_megagroup; @@ -14243,7 +14275,7 @@ td_api::object_ptr ContactsManager::get_update_unknown ChannelId channel_id) { return td_api::make_object(td_api::make_object( channel_id.get(), string(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), 0, false, - false, false, false, true, false, "", false)); + false, false, false, false, true, false, "", false)); } int32 ContactsManager::get_supergroup_id_object(ChannelId channel_id, const char *source) const { @@ -14265,8 +14297,9 @@ tl_object_ptr ContactsManager::get_supergroup_object(Channel } return td_api::make_object( channel_id.get(), c->username, c->date, get_channel_status(c).get_chat_member_status_object(), - c->participant_count, c->has_linked_channel, c->has_location, c->sign_messages, c->is_slow_mode_enabled, - !c->is_megagroup, c->is_verified, get_restriction_reason_description(c->restriction_reasons), c->is_scam); + c->participant_count, c->has_linked_channel, c->has_location, c->has_active_group_call, c->sign_messages, + c->is_slow_mode_enabled, !c->is_megagroup, c->is_verified, + get_restriction_reason_description(c->restriction_reasons), c->is_scam); } tl_object_ptr ContactsManager::get_supergroup_full_info_object(ChannelId channel_id) const { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index e73ba3e3c..2dab53930 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -21,6 +21,7 @@ #include "td/telegram/files/FileSourceId.h" #include "td/telegram/FolderId.h" #include "td/telegram/FullMessageId.h" +#include "td/telegram/InputGroupCallId.h" #include "td/telegram/Location.h" #include "td/telegram/MessageId.h" #include "td/telegram/net/DcId.h" @@ -789,6 +790,7 @@ class ContactsManager : public Actor { bool has_linked_channel = false; bool has_location = false; + bool has_active_group_call = false; bool sign_messages = false; bool is_slow_mode_enabled = false; @@ -847,6 +849,8 @@ class ContactsManager : public Actor { DcId stats_dc_id; + InputGroupCallId active_group_call_id; + int32 slow_mode_delay = 0; int32 slow_mode_next_send_date = 0; @@ -1017,6 +1021,7 @@ class ContactsManager : public Actor { static constexpr int32 CHANNEL_FLAG_HAS_LINKED_CHAT = 1 << 20; static constexpr int32 CHANNEL_FLAG_HAS_LOCATION = 1 << 21; static constexpr int32 CHANNEL_FLAG_IS_SLOW_MODE_ENABLED = 1 << 22; + static constexpr int32 CHANNEL_FLAG_HAS_ACTIVE_GROUP_CALL = 1 << 23; static constexpr int32 CHANNEL_FULL_FLAG_HAS_PARTICIPANT_COUNT = 1 << 0; static constexpr int32 CHANNEL_FULL_FLAG_HAS_ADMINISTRATOR_COUNT = 1 << 1; @@ -1039,6 +1044,7 @@ class ContactsManager : public Actor { static constexpr int32 CHANNEL_FULL_FLAG_HAS_SLOW_MODE_NEXT_SEND_DATE = 1 << 18; static constexpr int32 CHANNEL_FULL_FLAG_HAS_SCHEDULED_MESSAGES = 1 << 19; static constexpr int32 CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS = 1 << 20; + static constexpr int32 CHANNEL_FULL_FLAG_HAS_ACTIVE_GROUP_CALL = 1 << 21; static constexpr int32 CHANNEL_FULL_FLAG_IS_BLOCKED = 1 << 22; static constexpr int32 CHAT_INVITE_FLAG_IS_CHANNEL = 1 << 0; diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 85d2a2e04..5c5f211bc 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -38,6 +38,7 @@ class ConnectionCreator; class ContactsManager; class FileManager; class FileReferenceManager; +class GroupCallManager; class LanguagePackManager; class MessagesManager; class MtprotoHeader; @@ -215,6 +216,13 @@ class Global : public ActorContext { file_reference_manager_ = std::move(file_reference_manager); } + ActorId group_call_manager() const { + return group_call_manager_; + } + void set_group_call_manager(ActorId group_call_manager) { + group_call_manager_ = group_call_manager; + } + ActorId language_pack_manager() const { return language_pack_manager_; } @@ -385,6 +393,7 @@ class Global : public ActorContext { ActorId contacts_manager_; ActorId file_manager_; ActorId file_reference_manager_; + ActorId group_call_manager_; ActorId language_pack_manager_; ActorId messages_manager_; ActorId notification_manager_; diff --git a/td/telegram/InputGroupCallId.cpp b/td/telegram/InputGroupCallId.cpp index 69f05a66d..296dc3d89 100644 --- a/td/telegram/InputGroupCallId.cpp +++ b/td/telegram/InputGroupCallId.cpp @@ -27,10 +27,7 @@ Result InputGroupCallId::from_group_call_id(const string &grou return Status::Error("Invalid group call identifier specified"); } - InputGroupCallId result; - result.group_call_id = r_group_call_id.ok(); - result.access_hash = r_access_hash.ok(); - return result; + return InputGroupCallId{r_group_call_id.ok(), r_access_hash.ok()}; } string InputGroupCallId::get_group_call_id() const { @@ -45,7 +42,7 @@ tl_object_ptr InputGroupCallId::get_input_group_ca } StringBuilder &operator<<(StringBuilder &string_builder, InputGroupCallId input_group_call_id) { - return string_builder << "input group call " << input_group_call_id.group_call_id; + return string_builder << "group call " << input_group_call_id.group_call_id; } } // namespace td diff --git a/td/telegram/InputGroupCallId.h b/td/telegram/InputGroupCallId.h index 7107f764d..b8583e1e6 100644 --- a/td/telegram/InputGroupCallId.h +++ b/td/telegram/InputGroupCallId.h @@ -12,6 +12,8 @@ #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" +#include + namespace td { class InputGroupCallId { @@ -23,22 +25,33 @@ class InputGroupCallId { explicit InputGroupCallId(const tl_object_ptr &input_group_call); + InputGroupCallId(int64 group_call_id, int64 access_hash) : group_call_id(group_call_id), access_hash(access_hash) { + } + static Result from_group_call_id(const string &group_call_id); string get_group_call_id() const; bool operator==(const InputGroupCallId &other) const { - return group_call_id == other.group_call_id && access_hash == other.access_hash; + return group_call_id == other.group_call_id; } bool operator!=(const InputGroupCallId &other) const { return !(*this == other); } + bool is_identical(const InputGroupCallId &other) const { + return group_call_id == other.group_call_id && access_hash == other.access_hash; + } + bool is_valid() const { return group_call_id != 0; } + std::size_t get_hash() const { + return std::hash()(group_call_id); + } + tl_object_ptr get_input_group_call() const; template @@ -56,4 +69,10 @@ class InputGroupCallId { friend StringBuilder &operator<<(StringBuilder &string_builder, InputGroupCallId input_group_call_id); }; +struct InputGroupCallIdHash { + std::size_t operator()(InputGroupCallId input_group_call_id) const { + return input_group_call_id.get_hash(); + } +}; + } // namespace td diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 62f4a48cc..95ef9d25f 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3303,6 +3303,9 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo if (old_->group_call_id != new_->group_call_id || old_->duration != new_->duration) { need_update = true; } + if (!old_->group_call_id.is_identical(new_->group_call_id)) { + is_content_changed = true; + } break; } case MessageContentType::InviteToGroupCall: { @@ -3311,6 +3314,9 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo if (old_->group_call_id != new_->group_call_id || old_->user_id != new_->user_id) { need_update = true; } + if (!old_->group_call_id.is_identical(new_->group_call_id)) { + is_content_changed = true; + } break; } case MessageContentType::Unsupported: { @@ -4770,7 +4776,8 @@ tl_object_ptr get_message_content_object(const MessageCo } case MessageContentType::GroupCall: { auto *m = static_cast(content); - return make_tl_object(m->group_call_id.get_group_call_id()); + return make_tl_object(m->group_call_id.get_group_call_id(), + m->duration >= 0 ? max(m->duration, 1) : 0); } case MessageContentType::InviteToGroupCall: { auto *m = static_cast(content); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7320118ae..502fa9dfc 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4517,6 +4517,7 @@ void Td::init_managers() { country_info_manager_actor_ = register_actor("CountryInfoManager", country_info_manager_.get()); group_call_manager_ = make_unique(this, create_reference()); group_call_manager_actor_ = register_actor("GroupCallManager", group_call_manager_.get()); + G()->set_group_call_manager(group_call_manager_actor_.get()); inline_queries_manager_ = make_unique(this, create_reference()); inline_queries_manager_actor_ = register_actor("InlineQueriesManager", inline_queries_manager_.get()); messages_manager_ = make_unique(this, create_reference()); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 7191d924e..8e54ba631 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -21,6 +21,7 @@ #include "td/telegram/DialogId.h" #include "td/telegram/FolderId.h" #include "td/telegram/Global.h" +#include "td/telegram/GroupCallManager.h" #include "td/telegram/InlineQueriesManager.h" #include "td/telegram/LanguagePackManager.h" #include "td/telegram/Location.h" @@ -2122,6 +2123,10 @@ void UpdatesManager::on_update(tl_object_ptrdata_.as_slice().str()); } +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { + send_closure(G()->group_call_manager(), &GroupCallManager::on_update_group_call, std::move(update->call_)); +} + void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { td_->contacts_manager_->on_update_contacts_reset(); } @@ -2184,7 +2189,4 @@ void UpdatesManager::on_update(tl_object_ptr update, void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { -} - } // namespace td diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index efe3f3dbf..9cc8ec416 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -298,6 +298,8 @@ class UpdatesManager : public Actor { void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/); @@ -320,8 +322,6 @@ class UpdatesManager : public Actor { void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/); - - void on_update(tl_object_ptr update, bool /*force_apply*/); }; } // namespace td From 5d6e55e939c5001ecd3ca965d62914e3522f6c66 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 25 Nov 2020 23:07:10 +0300 Subject: [PATCH 4/6] Add group_call_id to supergroupFullInfo. --- td/generate/scheme/td_api.tl | 3 ++- td/generate/scheme/td_api.tlo | Bin 186180 -> 186220 bytes td/telegram/ContactsManager.cpp | 32 +++++++++++++++++++++++--------- td/telegram/ContactsManager.h | 3 ++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 48270c432..c6f86ba36 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -583,6 +583,7 @@ supergroup id:int32 username:string date:int32 status:ChatMemberStatus member_co //@restricted_count Number of restricted users in the supergroup; 0 if unknown //@banned_count Number of users banned from chat; 0 if unknown //@linked_chat_id Chat identifier of a discussion group for the channel, or a channel, for which the supergroup is the designated discussion group; 0 if none or unknown +//@group_call_id Identifier of an active group call; empty if none or unknown //@slow_mode_delay Delay between consecutive sent messages for non-administrator supergroup members, in seconds //@slow_mode_delay_expires_in Time left before next message can be sent in the supergroup, in seconds. An updateSupergroupFullInfo update is not triggered when value of this field changes, but both new and old values are non-zero //@can_get_members True, if members of the chat can be retrieved @@ -596,7 +597,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 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: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; //@class SecretChatState @description Describes the current secret chat state diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index d2a08422109488fca903546ae03081a4944e907f..337b639ce9cb2807878cd6e38b4571d7965a4bb6 100644 GIT binary patch delta 133 zcmX@Ij{D6z?hOyLSSG15H#a}g+Wtg~v7l8E#1kqmEl4d&FUl`1a4XHp@ytuhX8?)c zJSOBLIyunId-{P5j2EV#kY&`EF0+kEWs(!i_8l7;RhYnLZGW(t@r5CnIeo)vMuqKf Wo-)pu0^uuEFvHhO8hpjMG1!VwB%5@{DoD6tLWM0ShJz Lh^jYLObsyrPFFG< diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ced796ecd..4ccc33d1a 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -8707,7 +8707,13 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s channel_full->expires_at = 0.0; } } - on_update_channel_full_photo(channel_full, channel_id, std::move(channel_full->photo)); + auto photo = std::move(channel_full->photo); + on_update_channel_full_photo(channel_full, channel_id, std::move(photo)); + + if (!c->has_active_group_call && channel_full->active_group_call_id.is_valid()) { + channel_full->active_group_call_id = InputGroupCallId(); + channel_full->expires_at = 0.0; + } update_channel_full(channel_full, channel_id, true); @@ -9588,11 +9594,13 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c channel->active_group_call_id = group_call_id; bool has_active_group_call = 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; + LOG(ERROR) << "Receive invalid has_active_group_call flag " << c->has_active_group_call << ", but have " + << group_call_id; c->has_active_group_call = has_active_group_call; c->is_changed = true; update_channel(c, channel_id); } + channel->is_changed = true; } on_update_channel_full_photo( @@ -10966,7 +10974,8 @@ void ContactsManager::drop_channel_photos(ChannelId channel_id, bool is_empty, b } } -void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool drop_invite_link, bool drop_slow_mode_delay) { +void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool drop_invite_link, bool drop_slow_mode_delay, + bool drop_active_group_call_id) { LOG(INFO) << "Invalidate supergroup full for " << channel_id; // drop channel full cache auto channel_full = get_channel_full_force(channel_id, "invalidate_channel_full"); @@ -10981,6 +10990,10 @@ void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool drop_in channel_full->is_slow_mode_next_send_date_changed = true; channel_full->is_changed = true; } + if (drop_active_group_call_id && channel_full->active_group_call_id.is_valid()) { + channel_full->active_group_call_id = InputGroupCallId(); + channel_full->is_changed = true; + } update_channel_full(channel_full, channel_id); } if (drop_invite_link) { @@ -13953,6 +13966,7 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char } bool need_invalidate_channel_full = false; + bool need_drop_active_group_call_id = c->has_active_group_call != has_active_group_call; if (c->has_linked_channel != has_linked_channel || c->has_location != has_location || c->has_active_group_call != has_active_group_call || c->sign_messages != sign_messages || c->is_megagroup != is_megagroup || c->is_verified != is_verified || @@ -13979,7 +13993,7 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char update_channel(c, channel_id); if (need_invalidate_channel_full) { - invalidate_channel_full(channel_id, false, !c->is_slow_mode_enabled); + invalidate_channel_full(channel_id, false, !c->is_slow_mode_enabled, need_drop_active_group_call_id); } } @@ -14316,11 +14330,11 @@ tl_object_ptr ContactsManager::get_supergroup_full_i return td_api::make_object( 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->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, + 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, get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"), channel_full->migrated_from_max_message_id.get()); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 2dab53930..0c7415e6b 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -216,7 +216,8 @@ class ContactsManager : public Actor { void speculative_delete_channel_participant(ChannelId channel_id, UserId deleted_user_id, bool by_me); - void invalidate_channel_full(ChannelId channel_id, bool drop_invite_link, bool drop_slow_mode_delay); + void invalidate_channel_full(ChannelId channel_id, bool drop_invite_link, bool drop_slow_mode_delay, + bool drop_active_group_call_id = false); bool on_get_channel_error(ChannelId channel_id, const Status &status, const string &source); From e1271c7fa51e0430bb46d2afe1c7562894b2a482 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 26 Nov 2020 10:56:13 +0300 Subject: [PATCH 5/6] Add createChatGroupCall. --- td/generate/scheme/td_api.tl | 4 ++ td/generate/scheme/td_api.tlo | Bin 186220 -> 186312 bytes td/telegram/ContactsManager.cpp | 69 +++++++++++++++++++++++++++++++- td/telegram/ContactsManager.h | 5 +++ td/telegram/Td.cpp | 14 +++++++ td/telegram/Td.h | 2 + td/telegram/UpdatesManager.cpp | 24 +++++++++++ td/telegram/UpdatesManager.h | 3 ++ td/telegram/cli.cpp | 2 + 9 files changed, 122 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c6f86ba36..648287590 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4290,6 +4290,10 @@ sendCallRating call_id:int32 rating:int32 comment:string problems:vectorLug@iM{;j$~pPmYM diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 4ccc33d1a..3082dfb41 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -19,6 +19,7 @@ #include "td/telegram/files/FileType.h" #include "td/telegram/FolderId.h" #include "td/telegram/Global.h" +#include "td/telegram/GroupCallManager.h" #include "td/telegram/InlineQueriesManager.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/logevent/LogEventHelper.h" @@ -5913,6 +5914,68 @@ void ContactsManager::set_channel_slow_mode_delay(DialogId dialog_id, int32 slow td_->create_handler(std::move(promise))->send(channel_id, slow_mode_delay); } +void ContactsManager::create_channel_group_call(DialogId dialog_id, Promise &&promise) { + if (!dialog_id.is_valid()) { + return promise.set_error(Status::Error(400, "Invalid chat identifier specified")); + } + if (!td_->messages_manager_->have_dialog_force(dialog_id)) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + + if (dialog_id.get_type() != DialogType::Channel) { + return promise.set_error(Status::Error(400, "Chat is not a supergroup")); + } + + auto channel_id = dialog_id.get_channel_id(); + const Channel *c = get_channel(channel_id); + if (c == nullptr) { + return promise.set_error(Status::Error(400, "Chat info not found")); + } + if (!c->is_megagroup) { + return promise.set_error(Status::Error(400, "Chat is not a supergroup")); + } + if (!get_channel_permissions(c).can_manage_calls()) { + return promise.set_error(Status::Error(400, "Not enough rights in the supergroup")); + } + + auto new_promise = PromiseCreator::lambda( + [actor_id = actor_id(this), channel_id, promise = std::move(promise)](Result result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + send_closure(actor_id, &ContactsManager::on_create_channel_group_call, channel_id, result.move_as_ok(), + std::move(promise)); + } + }); + send_closure(G()->group_call_manager(), &GroupCallManager::create_group_call, channel_id, std::move(new_promise)); +} + +void ContactsManager::on_create_channel_group_call(ChannelId channel_id, InputGroupCallId group_call_id, + Promise &&promise) { + if (G()->close_flag()) { + return promise.set_error(Status::Error(500, "Request aborted")); + } + if (!group_call_id.is_valid()) { + return promise.set_error(Status::Error(500, "Receive invalid group call identifier")); + } + + Channel *c = get_channel(channel_id); + CHECK(c != nullptr); + if (!c->has_active_group_call) { + c->has_active_group_call = true; + c->is_changed = true; + update_channel(c, channel_id); + } + + 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; + channel_full->is_changed = true; + update_channel_full(channel_full, channel_id); + } + promise.set_value(std::move(group_call_id)); +} + void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics, Promise &&promise) { if (!dialog_id.is_valid()) { @@ -9553,6 +9616,10 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c InputGroupCallId 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(); + } } channel->repair_request_version = 0; @@ -9595,7 +9662,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c bool has_active_group_call = 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; + << group_call_id << " in " << channel_id; c->has_active_group_call = has_active_group_call; c->is_changed = true; update_channel(c, channel_id); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 0c7415e6b..e1981f4f0 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -365,6 +365,8 @@ class ContactsManager : public Actor { void set_channel_slow_mode_delay(DialogId dialog_id, int32 slow_mode_delay, Promise &&promise); + void create_channel_group_call(DialogId dialog_id, Promise &&promise); + void report_channel_spam(ChannelId channel_id, UserId user_id, const vector &message_ids, Promise &&promise); @@ -1315,6 +1317,9 @@ 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 &&promise); + bool is_chat_full_outdated(const ChatFull *chat_full, const Chat *c, ChatId chat_id); bool is_user_contact(const User *u, UserId user_id) const; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 502fa9dfc..d61fd3ca9 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6027,6 +6027,20 @@ void Td::on_request(uint64 id, td_api::sendCallDebugInformation &request) { std::move(request.debug_information_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::createChatGroupCall &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(td_api::make_object(result.ok().get_group_call_id())); + } + }); + + contacts_manager_->create_channel_group_call(DialogId(request.chat_id_), std::move(query_promise)); +} + void Td::on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request) { CHECK_IS_USER(); CREATE_REQUEST(UpgradeGroupChatToSupergroupChatRequest, request.chat_id_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index e3df46310..b2dffcd9a 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -692,6 +692,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::sendCallDebugInformation &request); + void on_request(uint64 id, const td_api::createChatGroupCall &request); + void on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request); void on_request(uint64 id, const td_api::getChatListsToAddChat &request); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 8e54ba631..b516143a1 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -901,6 +901,30 @@ vector *> UpdatesManager::get_new_mes return messages; } +vector UpdatesManager::get_update_new_group_call_ids(const telegram_api::Updates *updates_ptr) { + vector group_call_ids; + auto updates = get_updates(updates_ptr); + if (updates != nullptr) { + for (auto &update : *updates) { + InputGroupCallId group_call_id; + if (update->get_id() == telegram_api::updateGroupCall::ID) { + auto group_call_ptr = static_cast(update.get())->call_.get(); + if (group_call_ptr->get_id() == telegram_api::groupCall::ID) { + auto group_call = static_cast(group_call_ptr); + 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); + } else { + LOG(ERROR) << "Receive unexpected " << to_string(update); + } + } + } + return group_call_ids; +} + vector UpdatesManager::get_update_notify_settings_dialog_ids(const telegram_api::Updates *updates_ptr) { vector dialog_ids; auto updates = get_updates(updates_ptr); diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 9cc8ec416..1a58c698c 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -9,6 +9,7 @@ #include "td/telegram/ChannelId.h" #include "td/telegram/ChatId.h" #include "td/telegram/DialogId.h" +#include "td/telegram/InputGroupCallId.h" #include "td/telegram/PtsManager.h" #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" @@ -44,6 +45,8 @@ class UpdatesManager : public Actor { static vector *> get_new_messages( const telegram_api::Updates *updates_ptr); + static vector get_update_new_group_call_ids(const telegram_api::Updates *updates_ptr); + static vector get_update_notify_settings_dialog_ids(const telegram_api::Updates *updates_ptr); static vector get_chat_dialog_ids(const telegram_api::Updates *updates_ptr); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index d7c032afc..56d7bb13b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2834,6 +2834,8 @@ class CliClient final : public Actor { as_call_id(call_id), to_integer(rating), "Wow, such good call! (TDLib test)", std::move(problems))); } else if (op == "scdi" || op == "SendCallDebugInformation") { send_request(td_api::make_object(as_call_id(args), "{}")); + } else if (op == "ccgc") { + send_request(td_api::make_object(as_chat_id(args))); } else if (op == "gcil") { send_request(td_api::make_object(as_chat_id(args))); } else if (op == "ccil") { From 2144560f9d930dca41cd8cb1e57a8ac024f56527 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Fri, 25 Dec 2020 19:09:24 +0100 Subject: [PATCH 6/6] Change nullptr --- td/telegram/ContactsManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 3082dfb41..200a24a38 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -5960,7 +5960,9 @@ void ContactsManager::on_create_channel_group_call(ChannelId channel_id, InputGr } Channel *c = get_channel(channel_id); - CHECK(c != nullptr); + if (c == nullptr) { + return promise.set_error(Status::Error(500, "Channel not found")); + } if (!c->has_active_group_call) { c->has_active_group_call = true; c->is_changed = true;