2022-10-25 14:03:35 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2022-10-25 14:03:35 +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
|
|
|
|
|
2022-12-09 10:12:49 +01:00
|
|
|
#include "td/telegram/ChannelId.h"
|
2022-10-27 15:53:23 +02:00
|
|
|
#include "td/telegram/CustomEmojiId.h"
|
2022-10-25 15:10:15 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
2022-12-09 10:12:49 +01:00
|
|
|
#include "td/telegram/DialogNotificationSettings.h"
|
2022-12-05 15:37:09 +01:00
|
|
|
#include "td/telegram/ForumTopic.h"
|
2022-10-27 18:03:58 +02:00
|
|
|
#include "td/telegram/ForumTopicEditedData.h"
|
2022-10-25 15:10:15 +02:00
|
|
|
#include "td/telegram/ForumTopicInfo.h"
|
2022-11-02 17:51:41 +01:00
|
|
|
#include "td/telegram/MessageId.h"
|
2022-12-07 17:58:12 +01:00
|
|
|
#include "td/telegram/MessagesInfo.h"
|
2022-10-25 15:10:15 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
2022-11-15 14:00:19 +01:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2022-10-25 15:10:15 +02:00
|
|
|
|
2022-10-25 14:03:35 +02:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Promise.h"
|
2022-11-02 17:51:41 +01:00
|
|
|
#include "td/utils/Status.h"
|
2022-10-27 13:58:21 +02:00
|
|
|
#include "td/utils/WaitFreeHashMap.h"
|
2022-12-14 00:24:38 +01:00
|
|
|
#include "td/utils/WaitFreeHashSet.h"
|
2022-10-25 14:03:35 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
|
|
|
class ForumTopicManager final : public Actor {
|
|
|
|
public:
|
|
|
|
ForumTopicManager(Td *td, ActorShared<> parent);
|
|
|
|
ForumTopicManager(const ForumTopicManager &) = delete;
|
|
|
|
ForumTopicManager &operator=(const ForumTopicManager &) = delete;
|
|
|
|
ForumTopicManager(ForumTopicManager &&) = delete;
|
|
|
|
ForumTopicManager &operator=(ForumTopicManager &&) = delete;
|
|
|
|
~ForumTopicManager() final;
|
|
|
|
|
2022-10-25 15:10:15 +02:00
|
|
|
void create_forum_topic(DialogId dialog_id, string &&title, td_api::object_ptr<td_api::forumTopicIcon> &&icon,
|
|
|
|
Promise<td_api::object_ptr<td_api::forumTopicInfo>> &&promise);
|
|
|
|
|
2022-10-27 13:58:21 +02:00
|
|
|
void on_forum_topic_created(DialogId dialog_id, unique_ptr<ForumTopicInfo> &&forum_topic_info,
|
2022-10-25 15:10:15 +02:00
|
|
|
Promise<td_api::object_ptr<td_api::forumTopicInfo>> &&promise);
|
|
|
|
|
2022-10-27 15:53:23 +02:00
|
|
|
void edit_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, string &&title,
|
2022-11-30 14:53:01 +01:00
|
|
|
bool edit_icon_custom_emoji, CustomEmojiId icon_custom_emoji_id, Promise<Unit> &&promise);
|
2022-10-27 15:53:23 +02:00
|
|
|
|
2022-12-02 15:04:24 +01:00
|
|
|
void get_forum_topic(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
Promise<td_api::object_ptr<td_api::forumTopic>> &&promise);
|
|
|
|
|
2022-12-07 17:58:12 +01:00
|
|
|
void on_get_forum_topic(ChannelId channel_id, MessageId expected_top_thread_message_id, MessagesInfo &&info,
|
|
|
|
telegram_api::object_ptr<telegram_api::ForumTopic> &&topic,
|
|
|
|
Promise<td_api::object_ptr<td_api::forumTopic>> &&promise);
|
|
|
|
|
2022-12-07 18:20:06 +01:00
|
|
|
void on_get_forum_topics(ChannelId channel_id, bool order_by_creation_date, MessagesInfo &&info,
|
|
|
|
vector<telegram_api::object_ptr<telegram_api::ForumTopic>> &&topics,
|
|
|
|
Promise<td_api::object_ptr<td_api::forumTopics>> &&promise);
|
|
|
|
|
2022-12-26 13:11:55 +01:00
|
|
|
void get_forum_topic_link(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
Promise<td_api::object_ptr<td_api::messageLink>> &&promise);
|
2022-12-05 11:03:38 +01:00
|
|
|
|
2022-12-06 16:16:22 +01:00
|
|
|
void get_forum_topics(DialogId dialog_id, string query, int32 offset_date, MessageId offset_message_id,
|
|
|
|
MessageId offset_top_thread_message_id, int32 limit,
|
|
|
|
Promise<td_api::object_ptr<td_api::forumTopics>> promise);
|
|
|
|
|
2022-10-27 16:31:05 +02:00
|
|
|
void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2022-12-06 12:53:54 +01:00
|
|
|
const DialogNotificationSettings *get_forum_topic_notification_settings(DialogId dialog_id,
|
|
|
|
MessageId top_thread_message_id) const;
|
|
|
|
|
|
|
|
Status set_forum_topic_notification_settings(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
tl_object_ptr<td_api::chatNotificationSettings> &¬ification_settings)
|
|
|
|
TD_WARN_UNUSED_RESULT;
|
|
|
|
|
2022-11-30 16:52:31 +01:00
|
|
|
void toggle_forum_topic_is_hidden(DialogId dialog_id, bool is_hidden, Promise<Unit> &&promise);
|
|
|
|
|
2022-12-29 21:23:09 +01:00
|
|
|
void toggle_forum_topic_is_pinned(DialogId dialog_id, MessageId top_thread_message_id, bool is_pinned,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2022-12-29 21:48:19 +01:00
|
|
|
void set_pinned_forum_topics(DialogId dialog_id, vector<MessageId> top_thread_message_ids, Promise<Unit> &&promise);
|
|
|
|
|
2022-10-29 23:35:37 +02:00
|
|
|
void delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
|
|
|
|
|
2022-11-16 15:35:12 +01:00
|
|
|
void delete_all_dialog_topics(DialogId dialog_id);
|
|
|
|
|
2023-09-04 14:34:54 +02:00
|
|
|
void read_forum_topic_messages(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
MessageId last_read_inbox_message_id);
|
|
|
|
|
2022-12-14 12:25:04 +01:00
|
|
|
void on_update_forum_topic_unread(DialogId dialog_id, MessageId top_thread_message_id, MessageId last_message_id,
|
|
|
|
MessageId last_read_inbox_message_id, MessageId last_read_outbox_message_id,
|
|
|
|
int32 unread_count);
|
|
|
|
|
2022-12-06 12:53:54 +01:00
|
|
|
void on_update_forum_topic_notify_settings(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
tl_object_ptr<telegram_api::peerNotifySettings> &&peer_notify_settings,
|
|
|
|
const char *source);
|
|
|
|
|
2022-12-29 23:06:05 +01:00
|
|
|
void on_update_forum_topic_is_pinned(DialogId dialog_id, MessageId top_thread_message_id, bool is_pinned);
|
|
|
|
|
|
|
|
void on_update_pinned_forum_topics(DialogId dialog_id, vector<MessageId> top_thread_message_ids);
|
|
|
|
|
2022-10-27 18:03:58 +02:00
|
|
|
void on_forum_topic_edited(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
const ForumTopicEditedData &edited_data);
|
|
|
|
|
2022-12-02 15:47:08 +01:00
|
|
|
void on_get_forum_topic_info(DialogId dialog_id, const ForumTopicInfo &topic_info, const char *source);
|
|
|
|
|
2022-12-05 15:37:09 +01:00
|
|
|
void on_get_forum_topic_infos(DialogId dialog_id, vector<tl_object_ptr<telegram_api::ForumTopic>> &&forum_topics,
|
|
|
|
const char *source);
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::forumTopic> get_forum_topic_object(DialogId dialog_id,
|
|
|
|
MessageId top_thread_message_id) const;
|
2022-11-15 14:00:19 +01:00
|
|
|
|
2022-11-15 15:37:31 +01:00
|
|
|
void on_topic_message_count_changed(DialogId dialog_id, MessageId top_thread_message_id, int diff);
|
|
|
|
|
2022-10-25 14:03:35 +02:00
|
|
|
private:
|
2022-10-25 15:10:15 +02:00
|
|
|
static constexpr size_t MAX_FORUM_TOPIC_TITLE_LENGTH = 128; // server side limit for forum topic title
|
|
|
|
|
2022-11-15 14:59:32 +01:00
|
|
|
struct Topic {
|
|
|
|
unique_ptr<ForumTopicInfo> info_;
|
2022-12-05 15:37:09 +01:00
|
|
|
unique_ptr<ForumTopic> topic_;
|
2022-11-15 15:37:31 +01:00
|
|
|
int32 message_count_ = 0;
|
2022-12-05 16:46:07 +01:00
|
|
|
mutable bool need_save_to_database_ = true;
|
2022-11-16 15:26:51 +01:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
|
|
|
|
|
|
|
int32 MAGIC = 0x1fac3901;
|
2022-11-15 14:59:32 +01:00
|
|
|
};
|
|
|
|
|
2022-10-27 13:58:21 +02:00
|
|
|
struct DialogTopics {
|
2022-11-15 14:59:32 +01:00
|
|
|
WaitFreeHashMap<MessageId, unique_ptr<Topic>, MessageIdHash> topics_;
|
2022-12-14 00:24:38 +01:00
|
|
|
WaitFreeHashSet<MessageId, MessageIdHash> deleted_topic_ids_;
|
2022-10-27 13:58:21 +02:00
|
|
|
};
|
|
|
|
|
2022-10-25 14:03:35 +02:00
|
|
|
void tear_down() final;
|
|
|
|
|
2022-10-25 15:10:15 +02:00
|
|
|
Status is_forum(DialogId dialog_id);
|
|
|
|
|
2022-11-15 15:07:05 +01:00
|
|
|
bool can_be_forum(DialogId dialog_id) const;
|
|
|
|
|
2022-12-05 11:22:32 +01:00
|
|
|
static Status can_be_message_thread_id(MessageId top_thread_message_id);
|
|
|
|
|
2022-11-15 14:59:32 +01:00
|
|
|
DialogTopics *add_dialog_topics(DialogId dialog_id);
|
2022-11-15 14:00:19 +01:00
|
|
|
|
2022-12-29 23:06:05 +01:00
|
|
|
DialogTopics *get_dialog_topics(DialogId dialog_id);
|
|
|
|
|
2022-11-15 14:59:32 +01:00
|
|
|
static Topic *add_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id);
|
2022-10-27 22:30:24 +02:00
|
|
|
|
2022-12-29 23:06:05 +01:00
|
|
|
static Topic *get_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id);
|
|
|
|
|
2022-11-15 15:37:31 +01:00
|
|
|
Topic *add_topic(DialogId dialog_id, MessageId top_thread_message_id);
|
|
|
|
|
2022-11-16 14:02:22 +01:00
|
|
|
Topic *get_topic(DialogId dialog_id, MessageId top_thread_message_id);
|
|
|
|
|
|
|
|
const Topic *get_topic(DialogId dialog_id, MessageId top_thread_message_id) const;
|
|
|
|
|
2022-10-27 13:58:21 +02:00
|
|
|
ForumTopicInfo *get_topic_info(DialogId dialog_id, MessageId top_thread_message_id);
|
|
|
|
|
|
|
|
const ForumTopicInfo *get_topic_info(DialogId dialog_id, MessageId top_thread_message_id) const;
|
|
|
|
|
2022-12-05 16:46:07 +01:00
|
|
|
void set_topic_info(DialogId dialog_id, Topic *topic, unique_ptr<ForumTopicInfo> forum_topic_info);
|
2022-12-05 16:40:08 +01:00
|
|
|
|
2022-12-07 18:20:06 +01:00
|
|
|
MessageId on_get_forum_topic_impl(DialogId dialog_id, tl_object_ptr<telegram_api::ForumTopic> &&forum_topic);
|
|
|
|
|
2022-12-06 12:53:54 +01:00
|
|
|
DialogNotificationSettings *get_forum_topic_notification_settings(DialogId dialog_id,
|
|
|
|
MessageId top_thread_message_id);
|
|
|
|
|
|
|
|
bool update_forum_topic_notification_settings(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
DialogNotificationSettings *current_settings,
|
|
|
|
DialogNotificationSettings &&new_settings);
|
|
|
|
|
2022-11-16 15:45:47 +01:00
|
|
|
void on_delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
|
|
|
|
|
2022-10-27 23:12:44 +02:00
|
|
|
td_api::object_ptr<td_api::updateForumTopicInfo> get_update_forum_topic_info(DialogId dialog_id,
|
|
|
|
const ForumTopicInfo *topic_info) const;
|
|
|
|
|
|
|
|
void send_update_forum_topic_info(DialogId dialog_id, const ForumTopicInfo *topic_info) const;
|
|
|
|
|
2022-11-16 15:26:51 +01:00
|
|
|
void save_topic_to_database(DialogId dialog_id, const Topic *topic);
|
|
|
|
|
2022-11-16 15:45:47 +01:00
|
|
|
void delete_topic_from_database(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
|
|
|
|
|
2022-10-25 14:03:35 +02:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
2022-10-27 13:58:21 +02:00
|
|
|
|
|
|
|
WaitFreeHashMap<DialogId, unique_ptr<DialogTopics>, DialogIdHash> dialog_topics_;
|
2022-10-25 14:03:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|