diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 16b35e80c..30bf0e76f 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -97,6 +97,37 @@ class GetGroupCallQuery : public Td::ResultHandler { } }; +class GetGroupCallParticipantQuery : public Td::ResultHandler { + Promise promise_; + InputGroupCallId input_group_call_id_; + + public: + explicit GetGroupCallParticipantQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(InputGroupCallId input_group_call_id, vector user_ids, vector sources) { + input_group_call_id_ = input_group_call_id; + auto limit = narrow_cast(max(user_ids.size(), sources.size())); + send_query(G()->net_query_creator().create(telegram_api::phone_getGroupParticipants( + input_group_call_id.get_input_group_call(), std::move(user_ids), std::move(sources), string(), limit))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + td->group_call_manager_->on_get_group_call_participants(input_group_call_id_, result_ptr.move_as_ok(), false); + + promise_.set_value(Unit()); + } + + void on_error(uint64 id, Status status) override { + promise_.set_error(std::move(status)); + } +}; + class JoinGroupCallQuery : public Td::ResultHandler { Promise promise_; InputGroupCallId input_group_call_id_; @@ -552,6 +583,26 @@ void GroupCallManager::finish_get_group_call(InputGroupCallId input_group_call_i } } +void GroupCallManager::on_get_group_call_participants( + InputGroupCallId input_group_call_id, tl_object_ptr &&participants, + bool is_load) { + LOG(INFO) << "Receive group call members: " << to_string(participants); + + CHECK(participants != nullptr); + td_->contacts_manager_->on_get_users(std::move(participants->users_), "on_get_group_call_participants"); + + process_group_call_participants(std::move(participants->participants_)); + + if (is_load) { + // TODO use count, next_offset, version + } +} + +void GroupCallManager::process_group_call_participants( + vector> &&participants) { + // TODO +} + void GroupCallManager::join_group_call(GroupCallId group_call_id, td_api::object_ptr &&payload, int32 source, bool is_muted, @@ -976,7 +1027,11 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptrclose_flag()) { + return; + } if (date < G()->unix_time() - RECENT_SPEAKER_TIMEOUT) { return; } @@ -988,6 +1043,23 @@ void GroupCallManager::on_user_speaking_in_group_call(GroupCallId group_call_id, return; } + if (!td_->contacts_manager_->have_user_force(user_id)) { + if (recursive) { + LOG(ERROR) << "Failed to find speaking " << user_id << " from " << input_group_call_id << " in " + << group_call->channel_id; + } else { + auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), group_call_id, user_id, + date](Result &&result) { + if (!G()->close_flag() && result.is_ok()) { + send_closure(actor_id, &GroupCallManager::on_user_speaking_in_group_call, group_call_id, user_id, date, true); + } + }); + td_->create_handler(std::move(query_promise)) + ->send(input_group_call_id, {user_id.get()}, {}); + } + return; + } + auto &recent_speakers = group_call_recent_speakers_[group_call_id]; if (recent_speakers == nullptr) { recent_speakers = make_unique(); @@ -1012,8 +1084,6 @@ void GroupCallManager::on_user_speaking_in_group_call(GroupCallId group_call_id, } } - td_->contacts_manager_->get_user_id_object(user_id, "on_user_speaking_in_group_call"); - for (size_t i = 0; i < recent_speakers->users.size(); i++) { if (recent_speakers->users[i].second <= date) { recent_speakers->users.insert(recent_speakers->users.begin() + i, {user_id, date}); diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 3c1f26190..83c81f121 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -61,7 +61,11 @@ class GroupCallManager : public Actor { void on_update_group_call(tl_object_ptr group_call_ptr, ChannelId channel_id); - void on_user_speaking_in_group_call(GroupCallId group_call_id, UserId user_id, int32 date); + void on_user_speaking_in_group_call(GroupCallId group_call_id, UserId user_id, int32 date, bool recursive = false); + + void on_get_group_call_participants(InputGroupCallId input_group_call_id, + tl_object_ptr &&participants, + bool is_load); void process_join_group_call_response(InputGroupCallId input_group_call_id, uint64 generation, tl_object_ptr &&updates, Promise &&promise); @@ -98,6 +102,8 @@ class GroupCallManager : public Actor { void finish_get_group_call(InputGroupCallId input_group_call_id, Result> &&result); + void process_group_call_participants(vector> &&participants); + bool on_join_group_call_response(InputGroupCallId input_group_call_id, string json_response); void finish_join_group_call(InputGroupCallId input_group_call_id, uint64 generation, Status error); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 9f2ad94d4..2d1347ded 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6993,10 +6993,6 @@ void MessagesManager::on_user_dialog_action(DialogId dialog_id, MessageId top_th if (td_->auth_manager_->is_bot() || !user_id.is_valid() || is_broadcast_channel(dialog_id)) { return; } - if (!td_->contacts_manager_->have_min_user(user_id)) { - LOG(DEBUG) << "Ignore typing of unknown " << user_id; - return; - } if (top_thread_message_id != MessageId() && !top_thread_message_id.is_valid()) { LOG(ERROR) << "Ignore typing in the message thread of " << top_thread_message_id; return; @@ -7015,6 +7011,10 @@ void MessagesManager::on_user_dialog_action(DialogId dialog_id, MessageId top_th return; } + if (!td_->contacts_manager_->have_min_user(user_id)) { + LOG(DEBUG) << "Ignore typing of unknown " << user_id; + return; + } if (!have_dialog(dialog_id)) { LOG(DEBUG) << "Ignore typing in unknown " << dialog_id; return;