2021-09-07 14:49:34 +02:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2021-09-07 14:49:34 +02:00
|
|
|
//
|
|
|
|
// 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"
|
2021-12-27 16:17:02 +01:00
|
|
|
#include "td/telegram/MessageId.h"
|
2021-09-07 14:49:34 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
2021-09-07 16:21:18 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2021-09-07 14:49:34 +02:00
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
|
|
|
#include "td/actor/PromiseFuture.h"
|
2021-09-07 19:27:04 +02:00
|
|
|
#include "td/actor/Timeout.h"
|
2021-09-07 14:49:34 +02:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2021-09-07 16:21:18 +02:00
|
|
|
#include "td/utils/Status.h"
|
2021-09-07 14:49:34 +02:00
|
|
|
|
2021-09-08 15:50:03 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2021-09-07 14:49:34 +02:00
|
|
|
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;
|
|
|
|
|
2021-12-21 12:19:48 +01:00
|
|
|
void get_dialog_sponsored_message(DialogId dialog_id,
|
|
|
|
Promise<td_api::object_ptr<td_api::sponsoredMessage>> &&promise);
|
2021-09-07 14:49:34 +02:00
|
|
|
|
2021-12-27 16:17:02 +01:00
|
|
|
void view_sponsored_message(DialogId dialog_id, MessageId sponsored_message_id);
|
2021-09-07 14:49:34 +02:00
|
|
|
|
|
|
|
private:
|
2021-09-07 16:21:18 +02:00
|
|
|
struct SponsoredMessage;
|
|
|
|
struct DialogSponsoredMessages;
|
|
|
|
|
2021-09-07 14:49:34 +02:00
|
|
|
void tear_down() final;
|
|
|
|
|
2021-09-07 19:27:04 +02:00
|
|
|
static void on_delete_cached_sponsored_messages_timeout_callback(void *sponsored_message_manager_ptr,
|
|
|
|
int64 dialog_id_int);
|
|
|
|
|
|
|
|
void delete_cached_sponsored_messages(DialogId dialog_id);
|
|
|
|
|
2021-09-07 16:21:18 +02:00
|
|
|
td_api::object_ptr<td_api::sponsoredMessage> get_sponsored_message_object(
|
|
|
|
DialogId dialog_id, const SponsoredMessage &sponsored_message) const;
|
|
|
|
|
2021-12-21 12:19:48 +01:00
|
|
|
td_api::object_ptr<td_api::sponsoredMessage> get_sponsored_message_object(
|
2021-09-07 16:21:18 +02:00
|
|
|
DialogId dialog_id, const DialogSponsoredMessages &sponsored_messages) const;
|
|
|
|
|
|
|
|
void on_get_dialog_sponsored_messages(
|
|
|
|
DialogId dialog_id, Result<telegram_api::object_ptr<telegram_api::messages_sponsoredMessages>> &&result);
|
|
|
|
|
|
|
|
std::unordered_map<DialogId, unique_ptr<DialogSponsoredMessages>, DialogIdHash> dialog_sponsored_messages_;
|
|
|
|
|
2021-12-27 16:17:02 +01:00
|
|
|
MessageId current_sponsored_message_id_ = MessageId::max();
|
2021-09-10 10:44:50 +02:00
|
|
|
|
2021-09-07 19:27:04 +02:00
|
|
|
MultiTimeout delete_cached_sponsored_messages_timeout_{"DeleteCachedSponsoredMessagesTimeout"};
|
|
|
|
|
2021-09-07 14:49:34 +02:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|