Add td_api::viewSponsoredMessage.

This commit is contained in:
levlam 2021-08-25 22:34:18 +03:00
parent 658d172256
commit e3f55a71cd
6 changed files with 68 additions and 0 deletions

View File

@ -4212,6 +4212,9 @@ getMessagePublicForwards chat_id:int53 message_id:int53 offset:string limit:int3
//@description Returns sponsored messages to be shown in a chat; for channel chats only @chat_id Identifier of the chat
getChatSponsoredMessages chat_id:int53 = SponsoredMessages;
//@description Informs TDLib that a sponsored message was viewed by the user @chat_id Chat identifier @message_id The identifier of the sponsored message being viewed
viewSponsoredMessage chat_id:int53 message_id:bytes = Ok;
//@description Removes an active notification from notification list. Needs to be called only if the notification is removed by the current user @notification_group_id Identifier of notification group to which the notification belongs @notification_id Identifier of removed notification
removeNotification notification_group_id:int32 notification_id:int32 = Ok;

View File

@ -7,11 +7,15 @@
#include "td/telegram/SponsoredMessages.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/net/NetQueryCreator.h"
#include "td/telegram/Td.h"
//#include "td/utils/buffer.h"
namespace td {
class GetSponsoredMessagesQuery final : public Td::ResultHandler {
@ -75,6 +79,39 @@ class GetSponsoredMessagesQuery final : public Td::ResultHandler {
}
};
class ViewSponsoredMessageQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
public:
explicit ViewSponsoredMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, const string &message_id) {
channel_id_ = channel_id;
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(3, "Chat info not found"));
}
send_query(G()->net_query_creator().create(
telegram_api::channels_viewSponsoredMessage(std::move(input_channel), BufferSlice(message_id))));
}
void on_result(uint64 id, BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_viewSponsoredMessage>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) final {
td->contacts_manager_->on_get_channel_error(channel_id_, status, "ViewSponsoredMessageQuery");
promise_.set_error(std::move(status));
}
};
void get_dialog_sponsored_messages(Td *td, DialogId dialog_id,
Promise<td_api::object_ptr<td_api::sponsoredMessages>> &&promise) {
if (!td->messages_manager_->have_dialog_force(dialog_id, "get_sponsored_messages")) {
@ -88,4 +125,17 @@ void get_dialog_sponsored_messages(Td *td, DialogId dialog_id,
td->create_handler<GetSponsoredMessagesQuery>(std::move(promise))->send(dialog_id.get_channel_id());
}
void view_sponsored_message(Td *td, DialogId dialog_id, const string &message_id, Promise<Unit> &&promise) {
if (!td->messages_manager_->have_dialog_force(dialog_id, "view_sponsored_message")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (dialog_id.get_type() != DialogType::Channel ||
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ContactsManager::ChannelType::Broadcast ||
message_id.empty()) {
return promise.set_error(Status::Error(400, "Message not found"));
}
td->create_handler<ViewSponsoredMessageQuery>(std::move(promise))->send(dialog_id.get_channel_id(), message_id);
}
} // namespace td

View File

@ -20,4 +20,6 @@ class Td;
void get_dialog_sponsored_messages(Td *td, DialogId dialog_id,
Promise<td_api::object_ptr<td_api::sponsoredMessages>> &&promise);
void view_sponsored_message(Td *td, DialogId dialog_id, const string &message_id, Promise<Unit> &&promise);
} // namespace td

View File

@ -5072,6 +5072,12 @@ void Td::on_request(uint64 id, const td_api::getChatSponsoredMessages &request)
get_dialog_sponsored_messages(this, DialogId(request.chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::viewSponsoredMessage &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
view_sponsored_message(this, DialogId(request.chat_id_), request.message_id_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getMessageThread &request) {
CHECK_IS_USER();
CREATE_REQUEST(GetMessageThreadRequest, request.chat_id_, request.message_id_);

View File

@ -514,6 +514,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::getChatSponsoredMessages &request);
void on_request(uint64 id, const td_api::viewSponsoredMessage &request);
void on_request(uint64 id, const td_api::getMessageLink &request);
void on_request(uint64 id, const td_api::getMessageEmbeddingCode &request);

View File

@ -2588,6 +2588,11 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getMessages>(as_chat_id(chat_id), as_message_ids(message_ids)));
} else if (op == "gsm") {
send_request(td_api::make_object<td_api::getChatSponsoredMessages>(as_chat_id(args)));
} else if (op == "vsm") {
string chat_id;
string message_id;
get_args(args, chat_id, message_id);
send_request(td_api::make_object<td_api::viewSponsoredMessage>(as_chat_id(chat_id), message_id));
} else if (op == "gmlink") {
string chat_id;
string message_id;