Skip to content

Commit 554cfd7

Browse files
committed
Send server-side request when update forum topic.
1 parent d5cffad commit 554cfd7

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

td/telegram/ForumTopic.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ForumTopic::ForumTopic(Td *td, tl_object_ptr<telegram_api::ForumTopic> &&forum_t
3030
is_pinned_ = forum_topic->pinned_;
3131
notification_settings_ =
3232
get_dialog_notification_settings(std::move(forum_topic->notify_settings_), current_notification_settings);
33-
draft_message_ = get_draft_message(td, std::move(forum_topic->draft_));
33+
draft_message_ = ::td::get_draft_message(td, std::move(forum_topic->draft_));
3434

3535
if (is_short_) {
3636
return;
@@ -89,6 +89,16 @@ bool ForumTopic::update_unread_reaction_count(int32 count, bool is_relative) {
8989
return true;
9090
}
9191

92+
bool ForumTopic::set_draft_message(unique_ptr<DraftMessage> &&draft_message) {
93+
bool from_update = false;
94+
if (!need_update_draft_message(draft_message_, draft_message, from_update)) {
95+
return false;
96+
}
97+
98+
draft_message_ = std::move(draft_message);
99+
return true;
100+
}
101+
92102
int64 ForumTopic::get_forum_topic_order(Td *td, DialogId dialog_id) const {
93103
int64 order = DEFAULT_ORDER;
94104
if (last_message_id_ != MessageId()) {

td/telegram/ForumTopic.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class ForumTopic {
6161
return true;
6262
}
6363

64+
bool set_draft_message(unique_ptr<DraftMessage> &&draft_message);
65+
6466
DialogNotificationSettings *get_notification_settings() {
6567
return &notification_settings_;
6668
}
@@ -69,6 +71,10 @@ class ForumTopic {
6971
return &notification_settings_;
7072
}
7173

74+
const unique_ptr<DraftMessage> &get_draft_message() const {
75+
return draft_message_;
76+
}
77+
7278
td_api::object_ptr<td_api::forumTopic> get_forum_topic_object(Td *td, DialogId dialog_id,
7379
const ForumTopicInfo &info) const;
7480

td/telegram/ForumTopicManager.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ void ForumTopicManager::on_update_pinned_forum_topics(DialogId dialog_id, vector
721721

722722
Status ForumTopicManager::set_forum_topic_notification_settings(
723723
DialogId dialog_id, ForumTopicId forum_topic_id,
724-
tl_object_ptr<td_api::chatNotificationSettings> &&notification_settings) {
724+
td_api::object_ptr<td_api::chatNotificationSettings> &&notification_settings) {
725725
CHECK(!td_->auth_manager_->is_bot());
726726
TRY_STATUS(is_forum(dialog_id, true));
727727
TRY_STATUS(can_be_forum_topic_id(forum_topic_id));
@@ -758,6 +758,22 @@ bool ForumTopicManager::update_forum_topic_notification_settings(DialogId dialog
758758
return need_update.need_update_server;
759759
}
760760

761+
Status ForumTopicManager::set_forum_topic_draft_message(DialogId dialog_id, ForumTopicId forum_topic_id,
762+
unique_ptr<DraftMessage> &&draft_message) {
763+
TRY_STATUS(is_forum(dialog_id, true));
764+
TRY_STATUS(can_be_forum_topic_id(forum_topic_id));
765+
auto topic = get_topic(dialog_id, forum_topic_id);
766+
if (topic == nullptr || topic->topic_ == nullptr) {
767+
return Status::Error(400, "Topic not found");
768+
}
769+
if (topic->topic_->set_draft_message(std::move(draft_message))) {
770+
save_draft_message(td_, dialog_id, MessageTopic::forum(dialog_id, forum_topic_id),
771+
topic->topic_->get_draft_message(), Promise<Unit>());
772+
on_forum_topic_changed(dialog_id, topic);
773+
}
774+
return Status::OK();
775+
}
776+
761777
void ForumTopicManager::get_forum_topic(DialogId dialog_id, ForumTopicId forum_topic_id,
762778
Promise<td_api::object_ptr<td_api::forumTopic>> &&promise) {
763779
TRY_STATUS_PROMISE(promise, is_forum(dialog_id, true));

td/telegram/ForumTopicManager.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ class ForumTopicManager final : public Actor {
7676
void toggle_forum_topic_is_closed(DialogId dialog_id, ForumTopicId forum_topic_id, bool is_closed,
7777
Promise<Unit> &&promise);
7878

79-
Status set_forum_topic_notification_settings(DialogId dialog_id, ForumTopicId forum_topic_id,
80-
tl_object_ptr<td_api::chatNotificationSettings> &&notification_settings)
81-
TD_WARN_UNUSED_RESULT;
79+
Status set_forum_topic_notification_settings(
80+
DialogId dialog_id, ForumTopicId forum_topic_id,
81+
td_api::object_ptr<td_api::chatNotificationSettings> &&notification_settings) TD_WARN_UNUSED_RESULT;
82+
83+
Status set_forum_topic_draft_message(DialogId dialog_id, ForumTopicId forum_topic_id,
84+
unique_ptr<DraftMessage> &&draft_message);
8285

8386
void toggle_forum_topic_is_hidden(DialogId dialog_id, bool is_hidden, Promise<Unit> &&promise);
8487

td/telegram/MessagesManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15487,8 +15487,8 @@ Status MessagesManager::set_dialog_draft_message(Dialog *d, const MessageTopic &
1548715487
return Status::OK();
1548815488
}
1548915489
if (message_topic.is_forum()) {
15490-
// TODO
15491-
return Status::OK();
15490+
return td_->forum_topic_manager_->set_forum_topic_draft_message(d->dialog_id, message_topic.get_forum_topic_id(),
15491+
std::move(draft_message));
1549215492
}
1549315493
if (message_topic.is_monoforum()) {
1549415494
return td_->saved_messages_manager_->set_monoforum_topic_draft_message(

0 commit comments

Comments
 (0)