Add SponsoredMessageManager.
This commit is contained in:
parent
218c693910
commit
ae6b79d57b
@ -400,7 +400,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/SendCodeHelper.cpp
|
td/telegram/SendCodeHelper.cpp
|
||||||
td/telegram/SequenceDispatcher.cpp
|
td/telegram/SequenceDispatcher.cpp
|
||||||
td/telegram/SpecialStickerSetType.cpp
|
td/telegram/SpecialStickerSetType.cpp
|
||||||
td/telegram/SponsoredMessages.cpp
|
td/telegram/SponsoredMessageManager.cpp
|
||||||
td/telegram/StateManager.cpp
|
td/telegram/StateManager.cpp
|
||||||
td/telegram/StickersManager.cpp
|
td/telegram/StickersManager.cpp
|
||||||
td/telegram/StorageManager.cpp
|
td/telegram/StorageManager.cpp
|
||||||
@ -615,7 +615,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/ServerMessageId.h
|
td/telegram/ServerMessageId.h
|
||||||
td/telegram/SetWithPosition.h
|
td/telegram/SetWithPosition.h
|
||||||
td/telegram/SpecialStickerSetType.h
|
td/telegram/SpecialStickerSetType.h
|
||||||
td/telegram/SponsoredMessages.h
|
td/telegram/SponsoredMessageManager.h
|
||||||
td/telegram/StateManager.h
|
td/telegram/StateManager.h
|
||||||
td/telegram/StickerSetId.h
|
td/telegram/StickerSetId.h
|
||||||
td/telegram/StickersManager.h
|
td/telegram/StickersManager.h
|
||||||
|
@ -301,6 +301,7 @@ function split_file($file, $chunks, $undo) {
|
|||||||
'PublicDialogType|get_public_dialog_type' => 'PublicDialogType',
|
'PublicDialogType|get_public_dialog_type' => 'PublicDialogType',
|
||||||
'SecretChatActor' => 'SecretChatActor',
|
'SecretChatActor' => 'SecretChatActor',
|
||||||
'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager',
|
'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager',
|
||||||
|
'sponsored_message_manager[_(-][^.]|SponsoredMessageManager' => 'SponsoredMessageManager',
|
||||||
'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager',
|
'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager',
|
||||||
'[>](td_db[(][)]|get_td_db_impl[(])|TdDb[^A-Za-z]' => 'TdDb',
|
'[>](td_db[(][)]|get_td_db_impl[(])|TdDb[^A-Za-z]' => 'TdDb',
|
||||||
'theme_manager[_(-][^.]|ThemeManager' => "ThemeManager",
|
'theme_manager[_(-][^.]|ThemeManager' => "ThemeManager",
|
||||||
|
@ -48,6 +48,7 @@ class NetQueryDispatcher;
|
|||||||
class NotificationManager;
|
class NotificationManager;
|
||||||
class PasswordManager;
|
class PasswordManager;
|
||||||
class SecretChatsManager;
|
class SecretChatsManager;
|
||||||
|
class SponsoredMessageManager;
|
||||||
class StateManager;
|
class StateManager;
|
||||||
class StickersManager;
|
class StickersManager;
|
||||||
class StorageManager;
|
class StorageManager;
|
||||||
@ -275,6 +276,13 @@ class Global final : public ActorContext {
|
|||||||
secret_chats_manager_ = secret_chats_manager;
|
secret_chats_manager_ = secret_chats_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActorId<SponsoredMessageManager> sponsored_message_manager() const {
|
||||||
|
return sponsored_message_manager_;
|
||||||
|
}
|
||||||
|
void set_sponsored_message_manager(ActorId<SponsoredMessageManager> sponsored_message_manager) {
|
||||||
|
sponsored_message_manager_ = sponsored_message_manager;
|
||||||
|
}
|
||||||
|
|
||||||
ActorId<StickersManager> stickers_manager() const {
|
ActorId<StickersManager> stickers_manager() const {
|
||||||
return stickers_manager_;
|
return stickers_manager_;
|
||||||
}
|
}
|
||||||
@ -425,6 +433,7 @@ class Global final : public ActorContext {
|
|||||||
ActorId<NotificationManager> notification_manager_;
|
ActorId<NotificationManager> notification_manager_;
|
||||||
ActorId<PasswordManager> password_manager_;
|
ActorId<PasswordManager> password_manager_;
|
||||||
ActorId<SecretChatsManager> secret_chats_manager_;
|
ActorId<SecretChatsManager> secret_chats_manager_;
|
||||||
|
ActorId<SponsoredMessageManager> sponsored_message_manager_;
|
||||||
ActorId<StickersManager> stickers_manager_;
|
ActorId<StickersManager> stickers_manager_;
|
||||||
ActorId<StorageManager> storage_manager_;
|
ActorId<StorageManager> storage_manager_;
|
||||||
ActorId<ThemeManager> theme_manager_;
|
ActorId<ThemeManager> theme_manager_;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
#include "td/telegram/SponsoredMessages.h"
|
#include "td/telegram/SponsoredMessageManager.h"
|
||||||
|
|
||||||
#include "td/telegram/ChannelId.h"
|
#include "td/telegram/ChannelId.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
@ -116,30 +116,40 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void get_dialog_sponsored_messages(Td *td, DialogId dialog_id,
|
SponsoredMessageManager::SponsoredMessageManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||||
Promise<td_api::object_ptr<td_api::sponsoredMessages>> &&promise) {
|
}
|
||||||
if (!td->messages_manager_->have_dialog_force(dialog_id, "get_sponsored_messages")) {
|
|
||||||
|
SponsoredMessageManager::~SponsoredMessageManager() = default;
|
||||||
|
|
||||||
|
void SponsoredMessageManager::tear_down() {
|
||||||
|
parent_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SponsoredMessageManager::get_dialog_sponsored_messages(
|
||||||
|
DialogId dialog_id, Promise<td_api::object_ptr<td_api::sponsoredMessages>> &&promise) {
|
||||||
|
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_sponsored_messages")) {
|
||||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||||
}
|
}
|
||||||
if (dialog_id.get_type() != DialogType::Channel ||
|
if (dialog_id.get_type() != DialogType::Channel ||
|
||||||
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ContactsManager::ChannelType::Broadcast) {
|
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ContactsManager::ChannelType::Broadcast) {
|
||||||
return promise.set_value(td_api::make_object<td_api::sponsoredMessages>());
|
return promise.set_value(td_api::make_object<td_api::sponsoredMessages>());
|
||||||
}
|
}
|
||||||
|
|
||||||
td->create_handler<GetSponsoredMessagesQuery>(std::move(promise))->send(dialog_id.get_channel_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) {
|
void SponsoredMessageManager::view_sponsored_message(DialogId dialog_id, const string &message_id,
|
||||||
if (!td->messages_manager_->have_dialog_force(dialog_id, "view_sponsored_message")) {
|
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"));
|
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||||
}
|
}
|
||||||
if (dialog_id.get_type() != DialogType::Channel ||
|
if (dialog_id.get_type() != DialogType::Channel ||
|
||||||
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ContactsManager::ChannelType::Broadcast ||
|
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ContactsManager::ChannelType::Broadcast ||
|
||||||
message_id.empty()) {
|
message_id.empty()) {
|
||||||
return promise.set_error(Status::Error(400, "Message not found"));
|
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);
|
td_->create_handler<ViewSponsoredMessageQuery>(std::move(promise))->send(dialog_id.get_channel_id(), message_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
42
td/telegram/SponsoredMessageManager.h
Normal file
42
td/telegram/SponsoredMessageManager.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/DialogId.h"
|
||||||
|
#include "td/telegram/td_api.h"
|
||||||
|
|
||||||
|
#include "td/actor/actor.h"
|
||||||
|
#include "td/actor/PromiseFuture.h"
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class Td;
|
||||||
|
|
||||||
|
class SponsoredMessageManager final : public Actor {
|
||||||
|
public:
|
||||||
|
SponsoredMessageManager(Td *td, ActorShared<> parent);
|
||||||
|
SponsoredMessageManager(const SponsoredMessageManager &) = delete;
|
||||||
|
SponsoredMessageManager &operator=(const SponsoredMessageManager &) = delete;
|
||||||
|
SponsoredMessageManager(SponsoredMessageManager &&) = delete;
|
||||||
|
SponsoredMessageManager &operator=(SponsoredMessageManager &&) = delete;
|
||||||
|
~SponsoredMessageManager() final;
|
||||||
|
|
||||||
|
void get_dialog_sponsored_messages(DialogId dialog_id,
|
||||||
|
Promise<td_api::object_ptr<td_api::sponsoredMessages>> &&promise);
|
||||||
|
|
||||||
|
void view_sponsored_message(DialogId dialog_id, const string &message_id, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void tear_down() final;
|
||||||
|
|
||||||
|
Td *td_;
|
||||||
|
ActorShared<> parent_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace td
|
@ -1,25 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
|
||||||
//
|
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "td/telegram/DialogId.h"
|
|
||||||
#include "td/telegram/td_api.h"
|
|
||||||
|
|
||||||
#include "td/actor/PromiseFuture.h"
|
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
|
|
||||||
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
|
|
@ -91,7 +91,7 @@
|
|||||||
#include "td/telegram/SecretChatsManager.h"
|
#include "td/telegram/SecretChatsManager.h"
|
||||||
#include "td/telegram/SecureManager.h"
|
#include "td/telegram/SecureManager.h"
|
||||||
#include "td/telegram/SecureValue.h"
|
#include "td/telegram/SecureValue.h"
|
||||||
#include "td/telegram/SponsoredMessages.h"
|
#include "td/telegram/SponsoredMessageManager.h"
|
||||||
#include "td/telegram/StateManager.h"
|
#include "td/telegram/StateManager.h"
|
||||||
#include "td/telegram/StickerSetId.h"
|
#include "td/telegram/StickerSetId.h"
|
||||||
#include "td/telegram/StickersManager.h"
|
#include "td/telegram/StickersManager.h"
|
||||||
@ -3639,6 +3639,8 @@ void Td::dec_actor_refcnt() {
|
|||||||
LOG(DEBUG) << "NotificationManager was cleared" << timer;
|
LOG(DEBUG) << "NotificationManager was cleared" << timer;
|
||||||
poll_manager_.reset();
|
poll_manager_.reset();
|
||||||
LOG(DEBUG) << "PollManager was cleared" << timer;
|
LOG(DEBUG) << "PollManager was cleared" << timer;
|
||||||
|
sponsored_message_manager_.reset();
|
||||||
|
LOG(DEBUG) << "SponsoredMessageManager was cleared" << timer;
|
||||||
stickers_manager_.reset();
|
stickers_manager_.reset();
|
||||||
LOG(DEBUG) << "StickersManager was cleared" << timer;
|
LOG(DEBUG) << "StickersManager was cleared" << timer;
|
||||||
theme_manager_.reset();
|
theme_manager_.reset();
|
||||||
@ -3831,6 +3833,8 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "NotificationManager actor was cleared" << timer;
|
LOG(DEBUG) << "NotificationManager actor was cleared" << timer;
|
||||||
poll_manager_actor_.reset();
|
poll_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "PollManager actor was cleared" << timer;
|
LOG(DEBUG) << "PollManager actor was cleared" << timer;
|
||||||
|
sponsored_message_manager_actor_.reset();
|
||||||
|
LOG(DEBUG) << "SponsoredMessageManager actor was cleared" << timer;
|
||||||
stickers_manager_actor_.reset();
|
stickers_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "StickersManager actor was cleared" << timer;
|
LOG(DEBUG) << "StickersManager actor was cleared" << timer;
|
||||||
theme_manager_actor_.reset();
|
theme_manager_actor_.reset();
|
||||||
@ -4287,6 +4291,9 @@ void Td::init_managers() {
|
|||||||
poll_manager_ = make_unique<PollManager>(this, create_reference());
|
poll_manager_ = make_unique<PollManager>(this, create_reference());
|
||||||
poll_manager_actor_ = register_actor("PollManager", poll_manager_.get());
|
poll_manager_actor_ = register_actor("PollManager", poll_manager_.get());
|
||||||
G()->set_notification_manager(notification_manager_actor_.get());
|
G()->set_notification_manager(notification_manager_actor_.get());
|
||||||
|
sponsored_message_manager_ = make_unique<SponsoredMessageManager>(this, create_reference());
|
||||||
|
sponsored_message_manager_actor_ = register_actor("SponsoredMessageManager", sponsored_message_manager_.get());
|
||||||
|
G()->set_sponsored_message_manager(sponsored_message_manager_actor_.get());
|
||||||
stickers_manager_ = make_unique<StickersManager>(this, create_reference());
|
stickers_manager_ = make_unique<StickersManager>(this, create_reference());
|
||||||
stickers_manager_actor_ = register_actor("StickersManager", stickers_manager_.get());
|
stickers_manager_actor_ = register_actor("StickersManager", stickers_manager_.get());
|
||||||
G()->set_stickers_manager(stickers_manager_actor_.get());
|
G()->set_stickers_manager(stickers_manager_actor_.get());
|
||||||
@ -4992,13 +4999,14 @@ void Td::on_request(uint64 id, const td_api::getMessages &request) {
|
|||||||
void Td::on_request(uint64 id, const td_api::getChatSponsoredMessages &request) {
|
void Td::on_request(uint64 id, const td_api::getChatSponsoredMessages &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_REQUEST_PROMISE();
|
CREATE_REQUEST_PROMISE();
|
||||||
get_dialog_sponsored_messages(this, 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::viewSponsoredMessage &request) {
|
void Td::on_request(uint64 id, const td_api::viewSponsoredMessage &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
view_sponsored_message(this, DialogId(request.chat_id_), request.message_id_, std::move(promise));
|
sponsored_message_manager_->view_sponsored_message(DialogId(request.chat_id_), 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) {
|
||||||
|
@ -66,6 +66,7 @@ class PollManager;
|
|||||||
class PrivacyManager;
|
class PrivacyManager;
|
||||||
class SecureManager;
|
class SecureManager;
|
||||||
class SecretChatsManager;
|
class SecretChatsManager;
|
||||||
|
class SponsoredMessageManager;
|
||||||
class StickersManager;
|
class StickersManager;
|
||||||
class StorageManager;
|
class StorageManager;
|
||||||
class ThemeManager;
|
class ThemeManager;
|
||||||
@ -173,6 +174,8 @@ class Td final : public NetQueryCallback {
|
|||||||
ActorOwn<NotificationManager> notification_manager_actor_;
|
ActorOwn<NotificationManager> notification_manager_actor_;
|
||||||
unique_ptr<PollManager> poll_manager_;
|
unique_ptr<PollManager> poll_manager_;
|
||||||
ActorOwn<PollManager> poll_manager_actor_;
|
ActorOwn<PollManager> poll_manager_actor_;
|
||||||
|
unique_ptr<SponsoredMessageManager> sponsored_message_manager_;
|
||||||
|
ActorOwn<SponsoredMessageManager> sponsored_message_manager_actor_;
|
||||||
unique_ptr<StickersManager> stickers_manager_;
|
unique_ptr<StickersManager> stickers_manager_;
|
||||||
ActorOwn<StickersManager> stickers_manager_actor_;
|
ActorOwn<StickersManager> stickers_manager_actor_;
|
||||||
unique_ptr<ThemeManager> theme_manager_;
|
unique_ptr<ThemeManager> theme_manager_;
|
||||||
|
Loading…
Reference in New Issue
Block a user