Move voice chat creation to GroupCallManager.
This commit is contained in:
parent
6fdf68bad4
commit
00eed8928c
@ -4351,7 +4351,7 @@ sendCallRating call_id:int32 rating:int32 comment:string problems:vector<CallPro
|
|||||||
sendCallDebugInformation call_id:int32 debug_information:string = Ok;
|
sendCallDebugInformation call_id:int32 debug_information:string = Ok;
|
||||||
|
|
||||||
|
|
||||||
//@description Creates a voice chat (a group call bound to a chat). Available only for supergroups; requires can_manage_voice_chats rights @chat_id Chat identifier
|
//@description Creates a voice chat (a group call bound to a chat). Available only for basic groups and supergroups; requires can_manage_voice_chats rights @chat_id Chat identifier
|
||||||
createVoiceChat chat_id:int53 = GroupCallId;
|
createVoiceChat chat_id:int53 = GroupCallId;
|
||||||
|
|
||||||
//@description Returns information about a group call @group_call_id Group call identifier
|
//@description Returns information about a group call @group_call_id Group call identifier
|
||||||
|
@ -5916,69 +5916,6 @@ 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);
|
td_->create_handler<ToggleSlowModeQuery>(std::move(promise))->send(channel_id, slow_mode_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
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<InputGroupCallId> 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_voice_chat, dialog_id, std::move(new_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 (!input_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->is_group_call_empty) {
|
|
||||||
c->has_active_group_call = true;
|
|
||||||
c->is_group_call_empty = 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 != 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(td_->group_call_manager_->get_group_call_id(input_group_call_id, DialogId(channel_id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics,
|
void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics,
|
||||||
Promise<DcId> &&promise) {
|
Promise<DcId> &&promise) {
|
||||||
if (!dialog_id.is_valid()) {
|
if (!dialog_id.is_valid()) {
|
||||||
|
@ -367,8 +367,6 @@ class ContactsManager : public Actor {
|
|||||||
|
|
||||||
void set_channel_slow_mode_delay(DialogId dialog_id, int32 slow_mode_delay, Promise<Unit> &&promise);
|
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<GroupCallId> &&promise);
|
|
||||||
|
|
||||||
void report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
|
void report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
@ -1322,9 +1320,6 @@ class ContactsManager : public Actor {
|
|||||||
|
|
||||||
void update_bot_info(BotInfo *bot_info, UserId user_id, bool send_update, bool from_database);
|
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 input_group_call_id,
|
|
||||||
Promise<GroupCallId> &&promise);
|
|
||||||
|
|
||||||
bool is_chat_full_outdated(const ChatFull *chat_full, const Chat *c, ChatId chat_id);
|
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;
|
bool is_user_contact(const User *u, UserId user_id) const;
|
||||||
|
@ -590,8 +590,69 @@ GroupCallManager::GroupCall *GroupCallManager::get_group_call(InputGroupCallId i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCallManager::create_voice_chat(DialogId dialog_id, Promise<InputGroupCallId> &&promise) {
|
void GroupCallManager::create_voice_chat(DialogId dialog_id, Promise<GroupCallId> &&promise) {
|
||||||
td_->create_handler<CreateGroupCallQuery>(std::move(promise))->send(dialog_id);
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (dialog_id.get_type()) {
|
||||||
|
case DialogType::Channel: {
|
||||||
|
auto channel_id = dialog_id.get_channel_id();
|
||||||
|
switch (td_->contacts_manager_->get_channel_type(channel_id)) {
|
||||||
|
case ChannelType::Unknown:
|
||||||
|
return promise.set_error(Status::Error(400, "Chat info not found"));
|
||||||
|
case ChannelType::Megagroup:
|
||||||
|
// OK
|
||||||
|
break;
|
||||||
|
case ChannelType::Broadcast:
|
||||||
|
return promise.set_error(Status::Error(400, "Chat is not a group"));
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!td_->contacts_manager_->get_channel_permissions(channel_id).can_manage_calls()) {
|
||||||
|
return promise.set_error(Status::Error(400, "Not enough rights in the chat"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DialogType::Chat:
|
||||||
|
case DialogType::User:
|
||||||
|
case DialogType::SecretChat:
|
||||||
|
return promise.set_error(Status::Error(400, "Chat can't have a voice chat"));
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto query_promise = PromiseCreator::lambda(
|
||||||
|
[actor_id = actor_id(this), dialog_id, promise = std::move(promise)](Result<InputGroupCallId> result) mutable {
|
||||||
|
if (result.is_error()) {
|
||||||
|
promise.set_error(result.move_as_error());
|
||||||
|
} else {
|
||||||
|
send_closure(actor_id, &GroupCallManager::on_voice_chat_created, dialog_id, result.move_as_ok(),
|
||||||
|
std::move(promise));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
td_->create_handler<CreateGroupCallQuery>(std::move(query_promise))->send(dialog_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupCallManager::on_voice_chat_created(DialogId dialog_id, InputGroupCallId input_group_call_id,
|
||||||
|
Promise<GroupCallId> &&promise) {
|
||||||
|
if (G()->close_flag()) {
|
||||||
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
||||||
|
}
|
||||||
|
if (!input_group_call_id.is_valid()) {
|
||||||
|
return promise.set_error(Status::Error(500, "Receive invalid group call identifier"));
|
||||||
|
}
|
||||||
|
|
||||||
|
td_->contacts_manager_->on_update_channel_group_call(dialog_id.get_channel_id(), true, true);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// td_->messages_manager_->on_update_chat_group_call(dialog_id, input_group_call_id);
|
||||||
|
|
||||||
|
promise.set_value(get_group_call_id(input_group_call_id, dialog_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCallManager::get_group_call(GroupCallId group_call_id,
|
void GroupCallManager::get_group_call(GroupCallId group_call_id,
|
||||||
|
@ -37,7 +37,7 @@ class GroupCallManager : public Actor {
|
|||||||
|
|
||||||
GroupCallId get_group_call_id(InputGroupCallId input_group_call_id, DialogId dialog_id);
|
GroupCallId get_group_call_id(InputGroupCallId input_group_call_id, DialogId dialog_id);
|
||||||
|
|
||||||
void create_voice_chat(DialogId dialog_id, Promise<InputGroupCallId> &&promise);
|
void create_voice_chat(DialogId dialog_id, Promise<GroupCallId> &&promise);
|
||||||
|
|
||||||
void get_group_call(GroupCallId 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);
|
||||||
|
|
||||||
@ -109,6 +109,8 @@ class GroupCallManager : public Actor {
|
|||||||
const GroupCall *get_group_call(InputGroupCallId input_group_call_id) const;
|
const GroupCall *get_group_call(InputGroupCallId input_group_call_id) const;
|
||||||
GroupCall *get_group_call(InputGroupCallId input_group_call_id);
|
GroupCall *get_group_call(InputGroupCallId input_group_call_id);
|
||||||
|
|
||||||
|
void on_voice_chat_created(DialogId dialog_id, InputGroupCallId input_group_call_id, Promise<GroupCallId> &&promise);
|
||||||
|
|
||||||
void reload_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);
|
Promise<td_api::object_ptr<td_api::groupCall>> &&promise);
|
||||||
|
|
||||||
|
@ -6037,7 +6037,7 @@ void Td::on_request(uint64 id, const td_api::createVoiceChat &request) {
|
|||||||
promise.set_value(td_api::make_object<td_api::groupCallId>(result.ok().get()));
|
promise.set_value(td_api::make_object<td_api::groupCallId>(result.ok().get()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
contacts_manager_->create_channel_voice_chat(DialogId(request.chat_id_), std::move(query_promise));
|
group_call_manager_->create_voice_chat(DialogId(request.chat_id_), std::move(query_promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getGroupCall &request) {
|
void Td::on_request(uint64 id, const td_api::getGroupCall &request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user