Use unique 53-bit identifiers for sponsored messages.

This commit is contained in:
levlam 2021-12-27 16:49:11 +03:00
parent 218de37c3a
commit 23d537052e
4 changed files with 15 additions and 10 deletions

View File

@ -834,7 +834,7 @@ messageCalendar total_count:int32 days:vector<messageCalendarDay> = MessageCalen
//@sponsor_chat_id Chat identifier //@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 //@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 //@content Content of the message. Currently, can be only of the type messageText
sponsoredMessage id:int32 sponsor_chat_id:int53 link:InternalLinkType content:MessageContent = SponsoredMessage; sponsoredMessage 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 //@class NotificationSettingsScope @description Describes the types of chats to which notification settings are relevant
@ -4361,7 +4361,7 @@ getMessagePublicForwards chat_id:int53 message_id:int53 offset:string limit:int3
getChatSponsoredMessage chat_id:int53 = SponsoredMessage; 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 //@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:int32 = Ok; 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 //@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

View File

@ -97,14 +97,14 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
}; };
struct SponsoredMessageManager::SponsoredMessage { struct SponsoredMessageManager::SponsoredMessage {
int32 local_id = 0; int64 local_id = 0;
DialogId sponsor_dialog_id; DialogId sponsor_dialog_id;
ServerMessageId server_message_id; ServerMessageId server_message_id;
string start_param; string start_param;
unique_ptr<MessageContent> content; unique_ptr<MessageContent> content;
SponsoredMessage() = default; SponsoredMessage() = default;
SponsoredMessage(int32 local_id, DialogId sponsor_dialog_id, ServerMessageId server_message_id, string start_param, SponsoredMessage(int64 local_id, DialogId sponsor_dialog_id, ServerMessageId server_message_id, string start_param,
unique_ptr<MessageContent> content) unique_ptr<MessageContent> content)
: local_id(local_id) : local_id(local_id)
, sponsor_dialog_id(sponsor_dialog_id) , sponsor_dialog_id(sponsor_dialog_id)
@ -117,7 +117,7 @@ struct SponsoredMessageManager::SponsoredMessage {
struct SponsoredMessageManager::DialogSponsoredMessages { struct SponsoredMessageManager::DialogSponsoredMessages {
vector<Promise<td_api::object_ptr<td_api::sponsoredMessage>>> promises; vector<Promise<td_api::object_ptr<td_api::sponsoredMessage>>> promises;
vector<SponsoredMessage> messages; vector<SponsoredMessage> messages;
std::unordered_map<int32, string> message_random_ids; std::unordered_map<int64, string> message_random_ids;
}; };
SponsoredMessageManager::SponsoredMessageManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { SponsoredMessageManager::SponsoredMessageManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
@ -274,8 +274,13 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
} }
CHECK(disable_web_page_preview); CHECK(disable_web_page_preview);
CHECK(current_sponsored_message_id_ < std::numeric_limits<int32>::max()); auto local_id = ++current_sponsored_message_id_ + MessageId::max().get();
auto local_id = ++current_sponsored_message_id_; if (local_id >= (1ll << 52)) {
LOG(ERROR) << "Sponsored message ID overflowed";
current_sponsored_message_id_ = 1;
local_id = MessageId::max().get() + 1;
}
CHECK(messages->message_random_ids.count(local_id) == 0);
messages->message_random_ids[local_id] = sponsored_message->random_id_.as_slice().str(); 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, messages->messages.emplace_back(local_id, sponsor_dialog_id, server_message_id,
std::move(sponsored_message->start_param_), std::move(content)); std::move(sponsored_message->start_param_), std::move(content));
@ -287,7 +292,7 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
delete_cached_sponsored_messages_timeout_.set_timeout_in(dialog_id.get(), 300.0); delete_cached_sponsored_messages_timeout_.set_timeout_in(dialog_id.get(), 300.0);
} }
void SponsoredMessageManager::view_sponsored_message(DialogId dialog_id, int32 sponsored_message_id, void SponsoredMessageManager::view_sponsored_message(DialogId dialog_id, int64 sponsored_message_id,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "view_sponsored_message")) { if (!td_->messages_manager_->have_dialog_force(dialog_id, "view_sponsored_message")) {
return promise.set_error(Status::Error(400, "Chat not found")); return promise.set_error(Status::Error(400, "Chat not found"));

View File

@ -35,7 +35,7 @@ class SponsoredMessageManager final : public Actor {
void get_dialog_sponsored_message(DialogId dialog_id, void get_dialog_sponsored_message(DialogId dialog_id,
Promise<td_api::object_ptr<td_api::sponsoredMessage>> &&promise); Promise<td_api::object_ptr<td_api::sponsoredMessage>> &&promise);
void view_sponsored_message(DialogId dialog_id, int32 sponsored_message_id, Promise<Unit> &&promise); void view_sponsored_message(DialogId dialog_id, int64 sponsored_message_id, Promise<Unit> &&promise);
private: private:
struct SponsoredMessage; struct SponsoredMessage;

View File

@ -2676,7 +2676,7 @@ class CliClient final : public Actor {
string sponsored_message_id; string sponsored_message_id;
get_args(args, chat_id, 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), send_request(td_api::make_object<td_api::viewSponsoredMessage>(as_chat_id(chat_id),
to_integer<int32>(sponsored_message_id))); to_integer<int64>(sponsored_message_id)));
} else if (op == "gmlink") { } else if (op == "gmlink") {
string chat_id; string chat_id;
string message_id; string message_id;