Add td_api::getGroupCallStreamSegment.

This commit is contained in:
levlam 2021-03-10 22:50:14 +03:00
parent cd2fbc19e6
commit 67889cdcbc
7 changed files with 84 additions and 3 deletions

View File

@ -455,7 +455,7 @@ chatMemberStatusCreator custom_title:string is_anonymous:Bool is_member:Bool = C
//@description The user is a member of a chat and has some additional privileges. In basic groups, administrators can edit and delete messages sent by others, add new members, ban unprivileged members, and manage voice chats. In supergroups and channels, there are more detailed options for administrator privileges //@description The user is a member of a chat and has some additional privileges. In basic groups, administrators can edit and delete messages sent by others, add new members, ban unprivileged members, and manage voice chats. In supergroups and channels, there are more detailed options for administrator privileges
//@custom_title A custom title of the administrator; 0-16 characters without emojis; applicable to supergroups only //@custom_title A custom title of the administrator; 0-16 characters without emojis; applicable to supergroups only
//@can_be_edited True, if the current user can edit the administrator privileges for the called user //@can_be_edited True, if the current user can edit the administrator privileges for the called user
//@can_manage_chat True, if the administrator can get chat event log, get chat statistics, get message statistics in channels, get channel members, see anonymous administrators in supergoups and ignore slow mode. Implied by any other privilege; applicable to supergroups and channels only //@can_manage_chat True, if the administrator can get chat event log, get chat statistics, get message statistics in channels, get channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other privilege; applicable to supergroups and channels only
//@can_change_info True, if the administrator can change the chat title, photo, and other settings //@can_change_info True, if the administrator can change the chat title, photo, and other settings
//@can_post_messages True, if the administrator can create channel posts; applicable to channels only //@can_post_messages True, if the administrator can create channel posts; applicable to channels only
//@can_edit_messages True, if the administrator can edit messages of other users and pin messages; applicable to channels only //@can_edit_messages True, if the administrator can edit messages of other users and pin messages; applicable to channels only
@ -4604,6 +4604,12 @@ leaveGroupCall group_call_id:int32 = Ok;
//@description Discards a group call. Requires groupCall.can_be_managed @group_call_id Group call identifier //@description Discards a group call. Requires groupCall.can_be_managed @group_call_id Group call identifier
discardGroupCall group_call_id:int32 = Ok; discardGroupCall group_call_id:int32 = Ok;
//@description Returns a file with a segment of a group call stream in a modified OGG format
//@group_call_id Group call identifier
//@time_offset Point in time when the stream segment begins; Unix timestamp in milliseconds
//@scale Segment duration scale; 0-1. Segment's duration is 1000/(2**scale) milliseconds
getGroupCallStreamSegment group_call_id:int32 time_offset:int53 scale:int32 = FilePart;
//@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 //@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
toggleMessageSenderIsBlocked sender:MessageSender is_blocked:Bool = Ok; toggleMessageSenderIsBlocked sender:MessageSender is_blocked:Bool = Ok;

View File

@ -32,6 +32,42 @@
namespace td { namespace td {
class GetGroupCallStreamQuery : public Td::ResultHandler {
Promise<string> promise_;
public:
explicit GetGroupCallStreamQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
}
void send(InputGroupCallId input_group_call_id, DcId stream_dc_id, int64 time_offset, int32 scale) {
auto input_stream = make_tl_object<telegram_api::inputGroupCallStream>(input_group_call_id.get_input_group_call(),
time_offset, scale);
int32 flags = 0;
send_query(G()->net_query_creator().create(
telegram_api::upload_getFile(flags, false /*ignored*/, false /*ignored*/, std::move(input_stream), 0, 1 << 20),
stream_dc_id, NetQuery::Type::DownloadSmall));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::upload_getFile>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
if (ptr->get_id() != telegram_api::upload_file::ID) {
return on_error(id, Status::Error(500, "Receive unexpected server response"));
}
auto file = move_tl_object_as<telegram_api::upload_file>(ptr);
promise_.set_value(file->bytes_.as_slice().str());
}
void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status));
}
};
class GetGroupCallJoinAsQuery : public Td::ResultHandler { class GetGroupCallJoinAsQuery : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::messageSenders>> promise_; Promise<td_api::object_ptr<td_api::messageSenders>> promise_;
DialogId dialog_id_; DialogId dialog_id_;
@ -1653,6 +1689,21 @@ int32 GroupCallManager::cancel_join_group_call_request(InputGroupCallId input_gr
return audio_source; return audio_source;
} }
void GroupCallManager::get_group_call_stream_segment(GroupCallId group_call_id, int64 time_offset, int32 scale,
Promise<string> &&promise) {
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);
CHECK(group_call != nullptr);
if (!group_call->stream_dc_id.is_exact()) {
return promise.set_error(Status::Error(400, "Group call can't be streamed"));
}
td_->create_handler<GetGroupCallStreamQuery>(std::move(promise))
->send(input_group_call_id, group_call->stream_dc_id, time_offset, scale);
}
void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_dialog_id, void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_dialog_id,
td_api::object_ptr<td_api::groupCallPayload> &&payload, int32 audio_source, td_api::object_ptr<td_api::groupCallPayload> &&payload, int32 audio_source,
bool is_muted, bool is_muted,

View File

@ -56,6 +56,9 @@ class GroupCallManager : public Actor {
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);
void get_group_call_stream_segment(GroupCallId group_call_id, int64 time_offset, int32 scale,
Promise<string> &&promise);
void join_group_call(GroupCallId group_call_id, DialogId as_dialog_id, void join_group_call(GroupCallId group_call_id, DialogId as_dialog_id,
td_api::object_ptr<td_api::groupCallPayload> &&payload, int32 audio_source, bool is_muted, td_api::object_ptr<td_api::groupCallPayload> &&payload, int32 audio_source, bool is_muted,
Promise<td_api::object_ptr<td_api::groupCallJoinResponse>> &&promise); Promise<td_api::object_ptr<td_api::groupCallJoinResponse>> &&promise);

View File

@ -6065,6 +6065,22 @@ void Td::on_request(uint64 id, const td_api::discardGroupCall &request) {
group_call_manager_->discard_group_call(GroupCallId(request.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::getGroupCallStreamSegment &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
td_api::object_ptr<td_api::filePart> file_part;
file_part->data_ = result.move_as_ok();
promise.set_value(std::move(file_part));
}
});
group_call_manager_->get_group_call_stream_segment(GroupCallId(request.group_call_id_), request.time_offset_,
request.scale_, std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request) { void Td::on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST(UpgradeGroupChatToSupergroupChatRequest, request.chat_id_); CREATE_REQUEST(UpgradeGroupChatToSupergroupChatRequest, request.chat_id_);

View File

@ -725,6 +725,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::discardGroupCall &request); void on_request(uint64 id, const td_api::discardGroupCall &request);
void on_request(uint64 id, const td_api::getGroupCallStreamSegment &request);
void on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request); void on_request(uint64 id, const td_api::upgradeBasicGroupChatToSupergroupChat &request);
void on_request(uint64 id, const td_api::getChatListsToAddChat &request); void on_request(uint64 id, const td_api::getChatListsToAddChat &request);

View File

@ -2671,6 +2671,9 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::createVoiceChat>(as_chat_id(args))); send_request(td_api::make_object<td_api::createVoiceChat>(as_chat_id(args)));
} else if (op == "ggc") { } else if (op == "ggc") {
send_request(td_api::make_object<td_api::getGroupCall>(as_group_call_id(args))); send_request(td_api::make_object<td_api::getGroupCall>(as_group_call_id(args)));
} else if (op == "ggcss") {
send_request(td_api::make_object<td_api::getGroupCallStreamSegment>(as_group_call_id(args),
(std::time(nullptr) - 5) * 1000, 0));
} else if (op == "jgc") { } else if (op == "jgc") {
string group_call_id; string group_call_id;
string participant_alias; string participant_alias;

View File

@ -3167,8 +3167,8 @@ Result<FileId> FileManager::get_map_thumbnail_file_id(Location location, int32 z
x = clamp(x, 0, size - 1); // just in case x = clamp(x, 0, size - 1); // just in case
y = clamp(y, 0, size - 1); // just in case y = clamp(y, 0, size - 1); // just in case
string conversion = PSTRING() << "#map#" << zoom << "#" << x << "#" << y << "#" << width << "#" << height << "#" string conversion = PSTRING() << "#map#" << zoom << '#' << x << '#' << y << '#' << width << '#' << height << '#'
<< scale << "#"; << scale << '#';
return register_generate( return register_generate(
owner_dialog_id.get_type() == DialogType::SecretChat ? FileType::EncryptedThumbnail : FileType::Thumbnail, owner_dialog_id.get_type() == DialogType::SecretChat ? FileType::EncryptedThumbnail : FileType::Thumbnail,
FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0); FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0);