2022-10-24 20:10:12 +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-24 20:10:12 +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)
|
|
|
|
//
|
|
|
|
#include "td/telegram/ForumTopic.h"
|
|
|
|
|
|
|
|
#include "td/telegram/DraftMessage.h"
|
2022-12-07 07:45:37 +01:00
|
|
|
#include "td/telegram/MessagesManager.h"
|
2022-11-02 17:51:41 +01:00
|
|
|
#include "td/telegram/ServerMessageId.h"
|
2022-10-24 20:10:12 +02:00
|
|
|
#include "td/telegram/Td.h"
|
|
|
|
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2022-12-06 13:23:11 +01:00
|
|
|
ForumTopic::ForumTopic(Td *td, tl_object_ptr<telegram_api::ForumTopic> &&forum_topic_ptr,
|
|
|
|
const DialogNotificationSettings *current_notification_settings) {
|
2022-10-24 20:10:12 +02:00
|
|
|
CHECK(forum_topic_ptr != nullptr);
|
|
|
|
if (forum_topic_ptr->get_id() != telegram_api::forumTopic::ID) {
|
|
|
|
LOG(INFO) << "Receive " << to_string(forum_topic_ptr);
|
|
|
|
return;
|
|
|
|
}
|
2022-11-30 12:44:00 +01:00
|
|
|
|
2022-10-24 20:10:12 +02:00
|
|
|
auto *forum_topic = static_cast<telegram_api::forumTopic *>(forum_topic_ptr.get());
|
2022-11-15 12:54:57 +01:00
|
|
|
is_short_ = forum_topic->short_;
|
2022-11-30 12:44:00 +01:00
|
|
|
is_pinned_ = forum_topic->pinned_;
|
|
|
|
notification_settings_ =
|
2022-12-06 13:23:11 +01:00
|
|
|
get_dialog_notification_settings(std::move(forum_topic->notify_settings_), current_notification_settings);
|
2023-10-16 19:12:33 +02:00
|
|
|
draft_message_ = get_draft_message(td, std::move(forum_topic->draft_));
|
2022-11-30 12:44:00 +01:00
|
|
|
|
2022-11-15 12:54:57 +01:00
|
|
|
if (is_short_) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-24 20:10:12 +02:00
|
|
|
|
|
|
|
last_message_id_ = MessageId(ServerMessageId(forum_topic->top_message_));
|
|
|
|
unread_count_ = forum_topic->unread_count_;
|
|
|
|
last_read_inbox_message_id_ = MessageId(ServerMessageId(forum_topic->read_inbox_max_id_));
|
|
|
|
last_read_outbox_message_id_ = MessageId(ServerMessageId(forum_topic->read_outbox_max_id_));
|
|
|
|
unread_mention_count_ = forum_topic->unread_mentions_count_;
|
|
|
|
unread_reaction_count_ = forum_topic->unread_reactions_count_;
|
|
|
|
}
|
|
|
|
|
2022-12-14 12:25:04 +01:00
|
|
|
bool ForumTopic::update_last_read_outbox_message_id(MessageId last_read_outbox_message_id) {
|
|
|
|
if (last_read_outbox_message_id <= last_read_outbox_message_id_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
last_read_outbox_message_id_ = last_read_outbox_message_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ForumTopic::update_last_read_inbox_message_id(MessageId last_read_inbox_message_id, int32 unread_count) {
|
|
|
|
if (last_read_inbox_message_id <= last_read_inbox_message_id_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
last_read_inbox_message_id_ = last_read_inbox_message_id;
|
|
|
|
if (unread_count >= 0) {
|
|
|
|
unread_count_ = unread_count;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-02 15:58:00 +01:00
|
|
|
td_api::object_ptr<td_api::forumTopic> ForumTopic::get_forum_topic_object(Td *td, DialogId dialog_id,
|
|
|
|
const ForumTopicInfo &info) const {
|
2022-11-15 14:14:57 +01:00
|
|
|
if (info.is_empty()) {
|
2022-10-24 20:10:12 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-11-02 17:51:41 +01:00
|
|
|
// TODO draft_message = can_send_message(dialog_id, info_.get_top_thread_message_id()).is_ok() ? ... : nullptr;
|
2022-12-06 13:23:11 +01:00
|
|
|
auto last_message =
|
|
|
|
td->messages_manager_->get_message_object({dialog_id, last_message_id_}, "get_forum_topic_object");
|
2022-10-24 20:10:12 +02:00
|
|
|
auto draft_message = get_draft_message_object(draft_message_);
|
|
|
|
return td_api::make_object<td_api::forumTopic>(
|
2022-12-02 15:58:00 +01:00
|
|
|
info.get_forum_topic_info_object(td), std::move(last_message), is_pinned_, unread_count_,
|
|
|
|
last_read_inbox_message_id_.get(), last_read_outbox_message_id_.get(), unread_mention_count_,
|
|
|
|
unread_reaction_count_, get_chat_notification_settings_object(¬ification_settings_), std::move(draft_message));
|
2022-10-24 20:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|