Add getMessageFileType method.
This commit is contained in:
parent
bff723436a
commit
1159323ecc
@ -2615,6 +2615,18 @@ checkChatUsernameResultPublicChatsTooMuch = CheckChatUsernameResult;
|
||||
checkChatUsernameResultPublicGroupsUnavailable = CheckChatUsernameResult;
|
||||
|
||||
|
||||
//@class MessageFileType @description Contains information about a file with messages exported from another app
|
||||
|
||||
//@description The messages was exported from a private chat
|
||||
messageFileTypePrivate = MessageFileType;
|
||||
|
||||
//@description The messages was exported from a group chat @title Title of the group chat
|
||||
messageFileTypeGroup title:string = MessageFileType;
|
||||
|
||||
//@description The messages was exported from a chat of unknown type
|
||||
messageFileTypeUnknown = MessageFileType;
|
||||
|
||||
|
||||
//@class PushMessageContent @description Contains content of a push message notification
|
||||
|
||||
//@description A general message with hidden content @is_pinned True, if the message is a pinned message with the specified content
|
||||
@ -4388,6 +4400,9 @@ readFilePart file_id:int32 offset:int32 count:int32 = FilePart;
|
||||
deleteFile file_id:int32 = Ok;
|
||||
|
||||
|
||||
//@description Returns information about a file with messages exported from another app @message_file_head Beginning of the message file; up to 100 first lines
|
||||
getMessageFileType message_file_head:string = MessageFileType;
|
||||
|
||||
//@description Imports messages exported from another app
|
||||
//@chat_id Identifier of a chat to which the messages will be imported. It must be an identifier of a private chat with a mutual contact or an identifier of a created supergroup chat
|
||||
//@message_file File with messages to import. Only inputFileLocal and inputFileGenerated are supported. The file must not be previously uploaded
|
||||
|
Binary file not shown.
@ -1009,6 +1009,43 @@ class CreateChannelQuery : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class CheckHistoryImportQuery : public Td::ResultHandler {
|
||||
Promise<tl_object_ptr<td_api::MessageFileType>> promise_;
|
||||
|
||||
public:
|
||||
explicit CheckHistoryImportQuery(Promise<tl_object_ptr<td_api::MessageFileType>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &message_file_head) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_checkHistoryImport(message_file_head)));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) override {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_checkHistoryImport>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for CheckHistoryImportQuery: " << to_string(ptr);
|
||||
auto file_type = [&]() -> td_api::object_ptr<td_api::MessageFileType> {
|
||||
if (ptr->pm_) {
|
||||
return td_api::make_object<td_api::messageFileTypePrivate>();
|
||||
} else if (ptr->group_) {
|
||||
return td_api::make_object<td_api::messageFileTypeGroup>(ptr->title_);
|
||||
} else {
|
||||
return td_api::make_object<td_api::messageFileTypeUnknown>();
|
||||
}
|
||||
}();
|
||||
promise_.set_value(std::move(file_type));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class InitHistoryImportQuery : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
FileId file_id_;
|
||||
@ -26405,6 +26442,11 @@ Result<MessageId> MessagesManager::add_local_message(
|
||||
return message_id;
|
||||
}
|
||||
|
||||
void MessagesManager::get_message_file_type(const string &message_file_head,
|
||||
Promise<td_api::object_ptr<td_api::MessageFileType>> &&promise) {
|
||||
td_->create_handler<CheckHistoryImportQuery>(std::move(promise))->send(message_file_head);
|
||||
}
|
||||
|
||||
void MessagesManager::import_messages(DialogId dialog_id, const td_api::object_ptr<td_api::InputFile> &message_file,
|
||||
const vector<td_api::object_ptr<td_api::InputFile>> &attached_files,
|
||||
Promise<Unit> &&promise) {
|
||||
|
@ -394,6 +394,9 @@ class MessagesManager : public Actor {
|
||||
tl_object_ptr<td_api::InputMessageContent> &&input_message_content)
|
||||
TD_WARN_UNUSED_RESULT;
|
||||
|
||||
void get_message_file_type(const string &message_file_head,
|
||||
Promise<td_api::object_ptr<td_api::MessageFileType>> &&promise);
|
||||
|
||||
void import_messages(DialogId dialog_id, const td_api::object_ptr<td_api::InputFile> &message_file,
|
||||
const vector<td_api::object_ptr<td_api::InputFile>> &attached_files, Promise<Unit> &&promise);
|
||||
|
||||
|
@ -6535,6 +6535,13 @@ void Td::on_request(uint64 id, const td_api::deleteFile &request) {
|
||||
"td_api::deleteFile");
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getMessageFileType &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.message_file_head_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
messages_manager_->get_message_file_type(request.message_file_head_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::importMessages &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -836,6 +836,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, const td_api::deleteFile &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getMessageFileType &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::importMessages &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::blockMessageSenderFromReplies &request);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "td/utils/crypto.h"
|
||||
#include "td/utils/ExitGuard.h"
|
||||
#include "td/utils/FileLog.h"
|
||||
#include "td/utils/filesystem.h"
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/JsonBuilder.h"
|
||||
#include "td/utils/logging.h"
|
||||
@ -41,6 +42,7 @@
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/Time.h"
|
||||
#include "td/utils/utf8.h"
|
||||
|
||||
#ifndef USE_READLINE
|
||||
#include "td/utils/find_boundary.h"
|
||||
@ -2971,6 +2973,17 @@ class CliClient final : public Actor {
|
||||
as_input_file(document), nullptr, true, as_caption(""));
|
||||
return content;
|
||||
})));
|
||||
} else if (op == "gmft") {
|
||||
auto r_message_file_head = read_file_str(args, 2 << 10);
|
||||
if (r_message_file_head.is_error()) {
|
||||
LOG(ERROR) << r_message_file_head.error();
|
||||
} else {
|
||||
auto message_file_head = r_message_file_head.move_as_ok();
|
||||
while (!check_utf8(message_file_head)) {
|
||||
message_file_head.pop_back();
|
||||
}
|
||||
send_request(td_api::make_object<td_api::getMessageFileType>(message_file_head));
|
||||
}
|
||||
} else if (op == "im") {
|
||||
string chat_id;
|
||||
string message_file;
|
||||
|
Loading…
x
Reference in New Issue
Block a user