Add td_api::getUserSupportInfo.

This commit is contained in:
levlam 2022-08-15 14:32:35 +03:00
parent 383359d767
commit 5af4fcc35e
7 changed files with 115 additions and 0 deletions

View File

@ -437,6 +437,7 @@ set(TDLIB_SOURCE
td/telegram/StickerType.cpp td/telegram/StickerType.cpp
td/telegram/StorageManager.cpp td/telegram/StorageManager.cpp
td/telegram/SuggestedAction.cpp td/telegram/SuggestedAction.cpp
td/telegram/Support.cpp
td/telegram/Td.cpp td/telegram/Td.cpp
td/telegram/TdDb.cpp td/telegram/TdDb.cpp
td/telegram/TermsOfService.cpp td/telegram/TermsOfService.cpp
@ -685,6 +686,7 @@ set(TDLIB_SOURCE
td/telegram/StickerType.h td/telegram/StickerType.h
td/telegram/StorageManager.h td/telegram/StorageManager.h
td/telegram/SuggestedAction.h td/telegram/SuggestedAction.h
td/telegram/Support.h
td/telegram/Td.h td/telegram/Td.h
td/telegram/TdCallback.h td/telegram/TdCallback.h
td/telegram/TdDb.h td/telegram/TdDb.h

View File

@ -4550,6 +4550,10 @@ logVerbosityLevel verbosity_level:int32 = LogVerbosityLevel;
logTags tags:vector<string> = LogTags; logTags tags:vector<string> = LogTags;
//@description Contains custom information about the user @message Information message @author Information author @date Information change date
userSupportInfo message:formattedText author:string date:int32 = UserSupportInfo;
//@description A simple object containing a number; for testing only @value Number //@description A simple object containing a number; for testing only @value Number
testInt value:int32 = TestInt; testInt value:int32 = TestInt;
//@description A simple object containing a string; for testing only @value String //@description A simple object containing a string; for testing only @value String
@ -6584,6 +6588,10 @@ getLogTagVerbosityLevel tag:string = LogVerbosityLevel;
addLogMessage verbosity_level:int32 text:string = Ok; addLogMessage verbosity_level:int32 text:string = Ok;
//@description Returns support information for the given user; for Telegram support only @user_id User identifier
getUserSupportInfo user_id:int53 = UserSupportInfo;
//@description Does nothing; for testing only. This is an offline method. Can be called before authorization //@description Does nothing; for testing only. This is an offline method. Can be called before authorization
testCallEmpty = Ok; testCallEmpty = Ok;
//@description Returns the received string; for testing only. This is an offline method. Can be called before authorization @x String to return //@description Returns the received string; for testing only. This is an offline method. Can be called before authorization @x String to return

71
td/telegram/Support.cpp Normal file
View File

@ -0,0 +1,71 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/Support.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/Td.h"
#include "td/utils/buffer.h"
#include "td/utils/logging.h"
#include "td/utils/Status.h"
namespace td {
static td_api::object_ptr<td_api::userSupportInfo> get_user_support_info_object(
Td *td, telegram_api::object_ptr<telegram_api::help_UserInfo> user_info) {
CHECK(user_info != nullptr);
auto result = td_api::make_object<td_api::userSupportInfo>();
FormattedText message;
if (user_info->get_id() == telegram_api::help_userInfo::ID) {
auto info = telegram_api::move_object_as<telegram_api::help_userInfo>(user_info);
message = get_message_text(td->contacts_manager_.get(), std::move(info->message_), std::move(info->entities_), true,
true, info->date_, false, "get_user_support_info_object");
result->author_ = std::move(info->author_);
result->date_ = info->date_;
}
result->message_ = get_formatted_text_object(message, true, 0);
return result;
}
class GetUserInfoQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::userSupportInfo>> promise_;
public:
explicit GetUserInfoQuery(Promise<td_api::object_ptr<td_api::userSupportInfo>> &&promise)
: promise_(std::move(promise)) {
}
void send(UserId user_id) {
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_error()) {
return on_error(r_input_user.move_as_error());
}
send_query(G()->net_query_creator().create(telegram_api::help_getUserInfo(r_input_user.move_as_ok())));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::help_getUserInfo>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(get_user_support_info_object(td_, result_ptr.move_as_ok()));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
void get_user_info(Td *td, UserId user_id, Promise<td_api::object_ptr<td_api::userSupportInfo>> &&promise) {
td->create_handler<GetUserInfoQuery>(std::move(promise))->send(user_id);
}
} // namespace td

21
td/telegram/Support.h Normal file
View File

@ -0,0 +1,21 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/td_api.h"
#include "td/telegram/UserId.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {
class Td;
void get_user_info(Td *td, UserId user_id, Promise<td_api::object_ptr<td_api::userSupportInfo>> &&promise);
} // namespace td

View File

@ -111,6 +111,7 @@
#include "td/telegram/StickerType.h" #include "td/telegram/StickerType.h"
#include "td/telegram/StorageManager.h" #include "td/telegram/StorageManager.h"
#include "td/telegram/SuggestedAction.h" #include "td/telegram/SuggestedAction.h"
#include "td/telegram/Support.h"
#include "td/telegram/td_api.hpp" #include "td/telegram/td_api.hpp"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/telegram_api.hpp" #include "td/telegram/telegram_api.hpp"
@ -7992,6 +7993,12 @@ void Td::on_request(uint64 id, const td_api::pingProxy &request) {
send_closure(G()->connection_creator(), &ConnectionCreator::ping_proxy, request.proxy_id_, std::move(query_promise)); send_closure(G()->connection_creator(), &ConnectionCreator::ping_proxy, request.proxy_id_, std::move(query_promise));
} }
void Td::on_request(uint64 id, const td_api::getUserSupportInfo &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
get_user_info(this, UserId(request.user_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getTextEntities &request) { void Td::on_request(uint64 id, const td_api::getTextEntities &request) {
UNREACHABLE(); UNREACHABLE();
} }

View File

@ -1347,6 +1347,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::pingProxy &request); void on_request(uint64 id, const td_api::pingProxy &request);
void on_request(uint64 id, const td_api::getUserSupportInfo &request);
void on_request(uint64 id, const td_api::getTextEntities &request); void on_request(uint64 id, const td_api::getTextEntities &request);
void on_request(uint64 id, const td_api::parseTextEntities &request); void on_request(uint64 id, const td_api::parseTextEntities &request);

View File

@ -4820,6 +4820,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getProxyLink>(as_proxy_id(args))); send_request(td_api::make_object<td_api::getProxyLink>(as_proxy_id(args)));
} else if (op == "pproxy") { } else if (op == "pproxy") {
send_request(td_api::make_object<td_api::pingProxy>(as_proxy_id(args))); send_request(td_api::make_object<td_api::pingProxy>(as_proxy_id(args)));
} else if (op == "gusi") {
UserId user_id;
get_args(args, user_id);
send_request(td_api::make_object<td_api::getUserSupportInfo>(user_id));
} else if (op == "touch") { } else if (op == "touch") {
auto r_fd = FileFd::open(args, FileFd::Read | FileFd::Write); auto r_fd = FileFd::open(args, FileFd::Read | FileFd::Write);
if (r_fd.is_error()) { if (r_fd.is_error()) {