Remove viewSponsoredMessage in favor of viewMessages.
This commit is contained in:
parent
23d537052e
commit
a81ab8abba
@ -830,11 +830,11 @@ messageCalendar total_count:int32 days:vector<messageCalendarDay> = MessageCalen
|
||||
|
||||
|
||||
//@description Describes a sponsored message
|
||||
//@id Unique sponsored message identifier
|
||||
//@message_id Message identifier; unique for the chat to which the sponsored message belongs among both ordinary and sponsored messages
|
||||
//@sponsor_chat_id Chat identifier
|
||||
//@link An internal link to be opened when the sponsored message is clicked; may be null. If null, the sponsor chat needs to be opened instead
|
||||
//@content Content of the message. Currently, can be only of the type messageText
|
||||
sponsoredMessage id:int53 sponsor_chat_id:int53 link:InternalLinkType content:MessageContent = SponsoredMessage;
|
||||
sponsoredMessage message_id:int53 sponsor_chat_id:int53 link:InternalLinkType content:MessageContent = SponsoredMessage;
|
||||
|
||||
|
||||
//@class NotificationSettingsScope @description Describes the types of chats to which notification settings are relevant
|
||||
@ -4360,9 +4360,6 @@ getMessagePublicForwards chat_id:int53 message_id:int53 offset:string limit:int3
|
||||
//@description Returns sponsored message to be shown in a chat; for channel chats only. Returns a 404 error if there is no sponsored message in the chat @chat_id Identifier of the chat
|
||||
getChatSponsoredMessage chat_id:int53 = SponsoredMessage;
|
||||
|
||||
//@description Informs TDLib that a sponsored message was viewed by the user @chat_id Identifier of the chat with the sponsored message @sponsored_message_id The identifier of the sponsored message being viewed
|
||||
viewSponsoredMessage chat_id:int53 sponsored_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
|
||||
removeNotification notification_group_id:int32 notification_id:int32 = Ok;
|
||||
@ -4669,7 +4666,7 @@ openChat chat_id:int53 = Ok;
|
||||
//@description Informs TDLib that the chat is closed by the user. Many useful activities depend on the chat being opened or closed @chat_id Chat identifier
|
||||
closeChat chat_id:int53 = Ok;
|
||||
|
||||
//@description Informs TDLib that messages are being viewed by the user. Many useful activities depend on whether the messages are currently being viewed or not (e.g., marking messages as read, incrementing a view counter, updating a view counter, removing deleted messages in supergroups and channels)
|
||||
//@description Informs TDLib that messages are being viewed by the user. Sponsored messages must be marked as viewed only when the entire text of the message is shown on the screen (excluding the button). Many useful activities depend on whether the messages are currently being viewed or not (e.g., marking messages as read, incrementing a view counter, updating a view counter, removing deleted messages in supergroups and channels)
|
||||
//@chat_id Chat identifier
|
||||
//@message_thread_id If not 0, a message thread identifier in which the messages are being viewed
|
||||
//@message_ids The identifiers of the messages being viewed
|
||||
|
@ -43,6 +43,14 @@ bool MessageId::is_valid_scheduled() const {
|
||||
return type == SCHEDULED_MASK || type == (SCHEDULED_MASK | TYPE_YET_UNSENT) || type == (SCHEDULED_MASK | TYPE_LOCAL);
|
||||
}
|
||||
|
||||
bool MessageId::is_valid_sponsored() const {
|
||||
if (id <= max().get() || id > (static_cast<int64>(1) << 51)) {
|
||||
return false;
|
||||
}
|
||||
int32 type = (id & TYPE_MASK);
|
||||
return type == TYPE_LOCAL;
|
||||
}
|
||||
|
||||
MessageType MessageId::get_type() const {
|
||||
if (id <= 0 || id > (static_cast<int64>(1) << 51)) {
|
||||
return MessageType::None;
|
||||
|
@ -41,6 +41,10 @@ class MessageId {
|
||||
// |-------30-------|----18---|1|--2-|
|
||||
// |send_date-2**30 |server_id|1|type|
|
||||
|
||||
// sponsored message ID layout
|
||||
// |-------31--------|---17---|1|-2|
|
||||
// |11111111111111111|local_id|0|10|
|
||||
|
||||
ServerMessageId get_server_message_id_force() const;
|
||||
|
||||
ScheduledServerMessageId get_scheduled_server_message_id_force() const {
|
||||
@ -73,6 +77,8 @@ class MessageId {
|
||||
|
||||
bool is_valid_scheduled() const;
|
||||
|
||||
bool is_valid_sponsored() const;
|
||||
|
||||
int64 get() const {
|
||||
return id;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "td/telegram/ReplyMarkup.hpp"
|
||||
#include "td/telegram/SecretChatsManager.h"
|
||||
#include "td/telegram/SequenceDispatcher.h"
|
||||
#include "td/telegram/SponsoredMessageManager.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/TdDb.h"
|
||||
#include "td/telegram/TdParameters.h"
|
||||
@ -19819,6 +19820,12 @@ Status MessagesManager::view_messages(DialogId dialog_id, MessageId top_thread_m
|
||||
}
|
||||
for (auto message_id : message_ids) {
|
||||
if (!message_id.is_valid() && !message_id.is_valid_scheduled()) {
|
||||
if (message_id.is_valid_sponsored()) {
|
||||
if (d->is_opened) {
|
||||
td_->sponsored_message_manager_->view_sponsored_message(dialog_id, message_id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return Status::Error(400, "Invalid message identifier");
|
||||
}
|
||||
}
|
||||
|
@ -64,18 +64,14 @@ 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(400, "Chat info not found"));
|
||||
return;
|
||||
}
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::channels_viewSponsoredMessage(std::move(input_channel), BufferSlice(message_id))));
|
||||
@ -86,13 +82,10 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
|
||||
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, "ViewSponsoredMessageQuery");
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
@ -274,12 +267,15 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
|
||||
}
|
||||
CHECK(disable_web_page_preview);
|
||||
|
||||
auto local_id = ++current_sponsored_message_id_ + MessageId::max().get();
|
||||
if (local_id >= (1ll << 52)) {
|
||||
current_sponsored_message_id_ = current_sponsored_message_id_.get_next_message_id(MessageType::Local);
|
||||
if (!current_sponsored_message_id_.is_valid_sponsored()) {
|
||||
LOG(ERROR) << "Sponsored message ID overflowed";
|
||||
current_sponsored_message_id_ = 1;
|
||||
local_id = MessageId::max().get() + 1;
|
||||
current_sponsored_message_id_ = MessageId::max().get_next_message_id(MessageType::Local);
|
||||
CHECK(current_sponsored_message_id_.is_valid_sponsored());
|
||||
}
|
||||
auto local_id = current_sponsored_message_id_.get();
|
||||
CHECK(!current_sponsored_message_id_.is_valid());
|
||||
CHECK(!current_sponsored_message_id_.is_scheduled());
|
||||
CHECK(messages->message_random_ids.count(local_id) == 0);
|
||||
messages->message_random_ids[local_id] = sponsored_message->random_id_.as_slice().str();
|
||||
messages->messages.emplace_back(local_id, sponsor_dialog_id, server_message_id,
|
||||
@ -292,27 +288,19 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
|
||||
delete_cached_sponsored_messages_timeout_.set_timeout_in(dialog_id.get(), 300.0);
|
||||
}
|
||||
|
||||
void SponsoredMessageManager::view_sponsored_message(DialogId dialog_id, int64 sponsored_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 (!td_->messages_manager_->is_dialog_opened(dialog_id)) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
void SponsoredMessageManager::view_sponsored_message(DialogId dialog_id, MessageId sponsored_message_id) {
|
||||
auto it = dialog_sponsored_messages_.find(dialog_id);
|
||||
if (it == dialog_sponsored_messages_.end()) {
|
||||
return promise.set_value(Unit());
|
||||
return;
|
||||
}
|
||||
auto random_id_it = it->second->message_random_ids.find(sponsored_message_id);
|
||||
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());
|
||||
return;
|
||||
}
|
||||
|
||||
auto random_id = std::move(random_id_it->second);
|
||||
it->second->message_random_ids.erase(random_id_it);
|
||||
td_->create_handler<ViewSponsoredMessageQuery>(std::move(promise))->send(dialog_id.get_channel_id(), random_id);
|
||||
td_->create_handler<ViewSponsoredMessageQuery>()->send(dialog_id.get_channel_id(), random_id);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/MessageId.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
@ -35,7 +36,7 @@ class SponsoredMessageManager final : public Actor {
|
||||
void get_dialog_sponsored_message(DialogId dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::sponsoredMessage>> &&promise);
|
||||
|
||||
void view_sponsored_message(DialogId dialog_id, int64 sponsored_message_id, Promise<Unit> &&promise);
|
||||
void view_sponsored_message(DialogId dialog_id, MessageId sponsored_message_id);
|
||||
|
||||
private:
|
||||
struct SponsoredMessage;
|
||||
@ -59,7 +60,7 @@ class SponsoredMessageManager final : public Actor {
|
||||
|
||||
std::unordered_map<DialogId, unique_ptr<DialogSponsoredMessages>, DialogIdHash> dialog_sponsored_messages_;
|
||||
|
||||
int32 current_sponsored_message_id_ = 0;
|
||||
MessageId current_sponsored_message_id_ = MessageId::max();
|
||||
|
||||
MultiTimeout delete_cached_sponsored_messages_timeout_{"DeleteCachedSponsoredMessagesTimeout"};
|
||||
|
||||
|
@ -4708,13 +4708,6 @@ void Td::on_request(uint64 id, const td_api::getChatSponsoredMessage &request) {
|
||||
sponsored_message_manager_->get_dialog_sponsored_message(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();
|
||||
sponsored_message_manager_->view_sponsored_message(DialogId(request.chat_id_), request.sponsored_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_);
|
||||
|
@ -527,8 +527,6 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::getChatSponsoredMessage &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);
|
||||
|
@ -2671,12 +2671,6 @@ 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::getChatSponsoredMessage>(as_chat_id(args)));
|
||||
} else if (op == "vsm") {
|
||||
string chat_id;
|
||||
string sponsored_message_id;
|
||||
get_args(args, chat_id, sponsored_message_id);
|
||||
send_request(td_api::make_object<td_api::viewSponsoredMessage>(as_chat_id(chat_id),
|
||||
to_integer<int64>(sponsored_message_id)));
|
||||
} else if (op == "gmlink") {
|
||||
string chat_id;
|
||||
string message_id;
|
||||
|
Loading…
Reference in New Issue
Block a user