Add td_api::clickSponsoredMessage.

This commit is contained in:
levlam 2023-05-04 17:21:50 +03:00
parent 10338c0490
commit 1a5f81163d
6 changed files with 72 additions and 0 deletions

View File

@ -6201,6 +6201,11 @@ 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 //@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; getChatSponsoredMessages chat_id:int53 = SponsoredMessages;
//@description Informs TDLib that the user opened the sponsored chat via the button, the name, the photo, or a mention in the sponsored message
//@chat_id Chat identifier of the sponsored message
//@message_id Identifier of the sponsored message
clickChatSponsoredMessage chat_id:int53 message_id:int53 = 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 //@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; removeNotification notification_group_id:int32 notification_id:int32 = Ok;

View File

@ -88,6 +88,38 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
} }
}; };
class ClickSponsoredMessageQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
public:
explicit ClickSponsoredMessageQuery(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_value(Unit());
}
send_query(G()->net_query_creator().create(
telegram_api::channels_clickSponsoredMessage(std::move(input_channel), BufferSlice(message_id))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_clickSponsoredMessage>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(Status status) final {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ClickSponsoredMessageQuery");
promise_.set_error(std::move(status));
}
};
struct SponsoredMessageManager::SponsoredMessage { struct SponsoredMessageManager::SponsoredMessage {
int64 local_id = 0; int64 local_id = 0;
bool is_recommended = false; bool is_recommended = false;
@ -385,4 +417,23 @@ void SponsoredMessageManager::view_sponsored_message(DialogId dialog_id, Message
td_->create_handler<ViewSponsoredMessageQuery>()->send(dialog_id.get_channel_id(), random_id); td_->create_handler<ViewSponsoredMessageQuery>()->send(dialog_id.get_channel_id(), random_id);
} }
void SponsoredMessageManager::click_sponsored_message(DialogId dialog_id, MessageId sponsored_message_id,
Promise<Unit> &&promise) {
if (!dialog_id.is_valid() || !sponsored_message_id.is_valid_sponsored()) {
return promise.set_error(Status::Error(400, "Invalid message specified"));
}
auto it = dialog_sponsored_messages_.find(dialog_id);
if (it == dialog_sponsored_messages_.end()) {
return promise.set_value(Unit());
}
auto random_id_it = it->second->message_random_ids.find(sponsored_message_id.get());
if (random_id_it == it->second->message_random_ids.end()) {
return promise.set_value(Unit());
}
auto random_id = std::move(random_id_it->second);
it->second->message_random_ids.erase(random_id_it);
td_->create_handler<ClickSponsoredMessageQuery>(std::move(promise))->send(dialog_id.get_channel_id(), random_id);
}
} // namespace td } // namespace td

View File

@ -37,6 +37,8 @@ class SponsoredMessageManager final : public Actor {
void view_sponsored_message(DialogId dialog_id, MessageId sponsored_message_id); void view_sponsored_message(DialogId dialog_id, MessageId sponsored_message_id);
void click_sponsored_message(DialogId dialog_id, MessageId sponsored_message_id, Promise<Unit> &&promise);
private: private:
struct SponsoredMessage; struct SponsoredMessage;
struct DialogSponsoredMessages; struct DialogSponsoredMessages;

View File

@ -4664,6 +4664,13 @@ void Td::on_request(uint64 id, const td_api::getChatSponsoredMessages &request)
sponsored_message_manager_->get_dialog_sponsored_messages(DialogId(request.chat_id_), std::move(promise)); sponsored_message_manager_->get_dialog_sponsored_messages(DialogId(request.chat_id_), std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::clickChatSponsoredMessage &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
sponsored_message_manager_->click_sponsored_message(DialogId(request.chat_id_), MessageId(request.message_id_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getMessageThread &request) { void Td::on_request(uint64 id, const td_api::getMessageThread &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST(GetMessageThreadRequest, request.chat_id_, request.message_id_); CREATE_REQUEST(GetMessageThreadRequest, request.chat_id_, request.message_id_);

View File

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

View File

@ -3239,6 +3239,11 @@ 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::getChatSponsoredMessages>(chat_id)); send_request(td_api::make_object<td_api::getChatSponsoredMessages>(chat_id));
} else if (op == "ccspm") {
ChatId chat_id;
MessageId message_id;
get_args(args, chat_id, message_id);
send_request(td_api::make_object<td_api::clickChatSponsoredMessage>(chat_id, message_id));
} else if (op == "gmlink") { } else if (op == "gmlink") {
ChatId chat_id; ChatId chat_id;
MessageId message_id; MessageId message_id;