Add td_api::getChatBoostLink.

This commit is contained in:
levlam 2023-09-15 16:37:17 +03:00
parent 714397da80
commit 069f8607df
6 changed files with 54 additions and 0 deletions

View File

@ -5224,6 +5224,10 @@ messageLink link:string is_public:Bool = MessageLink;
messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:message media_timestamp:int32 for_album:Bool = MessageLinkInfo; messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:message media_timestamp:int32 for_album:Bool = MessageLinkInfo;
//@description Contains an HTTPS link to boost a chat @link The link @is_public True, if the link will work for non-members of the chat
chatBoostLink link:string is_public:Bool = ChatBoostLink;
//@class BlockList @description Describes a type of a block list //@class BlockList @description Describes a type of a block list
//@description The main block list that disallows writing messages to the current user, receiving their status and photo, viewing of stories, and some other actions //@description The main block list that disallows writing messages to the current user, receiving their status and photo, viewing of stories, and some other actions
@ -7689,6 +7693,9 @@ canBoostChat chat_id:int53 = CanBoostChatResult;
//@description Boosts a chat @chat_id Identifier of the chat //@description Boosts a chat @chat_id Identifier of the chat
boostChat chat_id:int53 = Ok; boostChat chat_id:int53 = Ok;
//@description Returns an HTTPS link to boost the specified channel chat @chat_id Identifier of the chat
getChatBoostLink chat_id:int53 = ChatBoostLink;
//@description Returns information about a bot that can be added to attachment or side menu @bot_user_id Bot's user identifier //@description Returns information about a bot that can be added to attachment or side menu @bot_user_id Bot's user identifier
getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot; getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot;

View File

@ -14,6 +14,7 @@
#include "td/telegram/FileReferenceManager.h" #include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/LinkManager.h"
#include "td/telegram/logevent/LogEvent.h" #include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/logevent/LogEventHelper.h" #include "td/telegram/logevent/LogEventHelper.h"
#include "td/telegram/MediaArea.hpp" #include "td/telegram/MediaArea.hpp"
@ -48,6 +49,7 @@
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/Random.h" #include "td/utils/Random.h"
#include "td/utils/Slice.h" #include "td/utils/Slice.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h" #include "td/utils/Status.h"
#include "td/utils/Time.h" #include "td/utils/Time.h"
#include "td/utils/tl_helpers.h" #include "td/utils/tl_helpers.h"
@ -2987,6 +2989,33 @@ void StoryManager::boost_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
td_->create_handler<ApplyBoostQuery>(std::move(promise))->send(dialog_id); td_->create_handler<ApplyBoostQuery>(std::move(promise))->send(dialog_id);
} }
Result<std::pair<string, bool>> StoryManager::get_dialog_boost_link(DialogId dialog_id) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_boost_status")) {
return Status::Error(400, "Chat not found");
}
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
return Status::Error(400, "Can't access the chat");
}
if (dialog_id.get_type() != DialogType::Channel ||
!td_->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
return Status::Error(400, "Can't boost the chat");
}
SliceBuilder sb;
sb << LinkManager::get_t_me_url();
auto username = td_->contacts_manager_->get_channel_first_username(dialog_id.get_channel_id());
bool is_public = !username.empty();
if (is_public) {
sb << username;
} else {
sb << "c/" << dialog_id.get_channel_id().get();
}
sb << "?boost";
return std::make_pair(sb.as_cslice().str(), is_public);
}
bool StoryManager::have_story(StoryFullId story_full_id) const { bool StoryManager::have_story(StoryFullId story_full_id) const {
return get_story(story_full_id) != nullptr; return get_story(story_full_id) != nullptr;
} }

View File

@ -276,6 +276,8 @@ class StoryManager final : public Actor {
void boost_dialog(DialogId dialog_id, Promise<Unit> &&promise); void boost_dialog(DialogId dialog_id, Promise<Unit> &&promise);
Result<std::pair<string, bool>> get_dialog_boost_link(DialogId dialog_id);
void remove_story_notifications_by_story_ids(DialogId dialog_id, const vector<StoryId> &story_ids); void remove_story_notifications_by_story_ids(DialogId dialog_id, const vector<StoryId> &story_ids);
StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr); StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr);

View File

@ -6604,6 +6604,16 @@ void Td::on_request(uint64 id, const td_api::boostChat &request) {
story_manager_->boost_dialog(DialogId(request.chat_id_), std::move(promise)); story_manager_->boost_dialog(DialogId(request.chat_id_), std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getChatBoostLink &request) {
auto r_boost_link = story_manager_->get_dialog_boost_link(DialogId(request.chat_id_));
if (r_boost_link.is_error()) {
send_closure(actor_id(this), &Td::send_error, id, r_boost_link.move_as_error());
} else {
send_closure(actor_id(this), &Td::send_result, id,
td_api::make_object<td_api::chatBoostLink>(r_boost_link.ok().first, r_boost_link.ok().second));
}
}
void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) { void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();

View File

@ -1046,6 +1046,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::boostChat &request); void on_request(uint64 id, const td_api::boostChat &request);
void on_request(uint64 id, const td_api::getChatBoostLink &request);
void on_request(uint64 id, const td_api::getAttachmentMenuBot &request); void on_request(uint64 id, const td_api::getAttachmentMenuBot &request);
void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request); void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request);

View File

@ -4302,6 +4302,10 @@ class CliClient final : public Actor {
ChatId chat_id; ChatId chat_id;
get_args(args, chat_id); get_args(args, chat_id);
send_request(td_api::make_object<td_api::boostChat>(chat_id)); send_request(td_api::make_object<td_api::boostChat>(chat_id));
} else if (op == "gcbl") {
ChatId chat_id;
get_args(args, chat_id);
send_request(td_api::make_object<td_api::getChatBoostLink>(chat_id));
} else if (op == "gamb") { } else if (op == "gamb") {
UserId user_id; UserId user_id;
get_args(args, user_id); get_args(args, user_id);