Process updates about pinned forum topics.
This commit is contained in:
parent
9fb35e8c95
commit
3422ab1082
@ -46,6 +46,14 @@ class ForumTopic {
|
|||||||
|
|
||||||
bool update_last_read_inbox_message_id(MessageId last_read_inbox_message_id, int32 unread_count);
|
bool update_last_read_inbox_message_id(MessageId last_read_inbox_message_id, int32 unread_count);
|
||||||
|
|
||||||
|
bool set_is_pinned(bool is_pinned) {
|
||||||
|
if (is_pinned_ == is_pinned) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
is_pinned_ = is_pinned;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
DialogNotificationSettings *get_notification_settings() {
|
DialogNotificationSettings *get_notification_settings() {
|
||||||
return ¬ification_settings_;
|
return ¬ification_settings_;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
#include "td/telegram/UpdatesManager.h"
|
#include "td/telegram/UpdatesManager.h"
|
||||||
|
|
||||||
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/Random.h"
|
#include "td/utils/Random.h"
|
||||||
@ -600,6 +601,53 @@ void ForumTopicManager::on_update_forum_topic_notify_settings(
|
|||||||
std::move(notification_settings));
|
std::move(notification_settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ForumTopicManager::on_update_forum_topic_is_pinned(DialogId dialog_id, MessageId top_thread_message_id,
|
||||||
|
bool is_pinned) {
|
||||||
|
if (!can_be_forum(dialog_id)) {
|
||||||
|
LOG(ERROR) << "Receive pinned topics in " << dialog_id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (td_->auth_manager_->is_bot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto topic = get_topic(dialog_id, top_thread_message_id);
|
||||||
|
if (topic == nullptr || topic->topic_ == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (topic->topic_->set_is_pinned(is_pinned)) {
|
||||||
|
topic->need_save_to_database_ = true;
|
||||||
|
save_topic_to_database(dialog_id, topic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ForumTopicManager::on_update_pinned_forum_topics(DialogId dialog_id, vector<MessageId> top_thread_message_ids) {
|
||||||
|
if (!can_be_forum(dialog_id)) {
|
||||||
|
LOG(ERROR) << "Receive pinned topics in " << dialog_id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (td_->auth_manager_->is_bot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dialog_topics = get_dialog_topics(dialog_id);
|
||||||
|
if (dialog_topics == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog_topics->topics_.foreach([&](const MessageId &top_thread_message_id, unique_ptr<Topic> &topic) {
|
||||||
|
if (topic->topic_ == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (topic->topic_->set_is_pinned(contains(top_thread_message_ids, top_thread_message_id))) {
|
||||||
|
topic->need_save_to_database_ = true;
|
||||||
|
save_topic_to_database(dialog_id, topic.get());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Status ForumTopicManager::set_forum_topic_notification_settings(
|
Status ForumTopicManager::set_forum_topic_notification_settings(
|
||||||
DialogId dialog_id, MessageId top_thread_message_id,
|
DialogId dialog_id, MessageId top_thread_message_id,
|
||||||
tl_object_ptr<td_api::chatNotificationSettings> &¬ification_settings) {
|
tl_object_ptr<td_api::chatNotificationSettings> &¬ification_settings) {
|
||||||
@ -995,6 +1043,10 @@ ForumTopicManager::DialogTopics *ForumTopicManager::add_dialog_topics(DialogId d
|
|||||||
return dialog_topics;
|
return dialog_topics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ForumTopicManager::DialogTopics *ForumTopicManager::get_dialog_topics(DialogId dialog_id) {
|
||||||
|
return dialog_topics_.get_pointer(dialog_id);
|
||||||
|
}
|
||||||
|
|
||||||
ForumTopicManager::Topic *ForumTopicManager::add_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id) {
|
ForumTopicManager::Topic *ForumTopicManager::add_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id) {
|
||||||
auto topic = dialog_topics->topics_.get_pointer(top_thread_message_id);
|
auto topic = dialog_topics->topics_.get_pointer(top_thread_message_id);
|
||||||
if (topic == nullptr) {
|
if (topic == nullptr) {
|
||||||
@ -1008,6 +1060,10 @@ ForumTopicManager::Topic *ForumTopicManager::add_topic(DialogTopics *dialog_topi
|
|||||||
return topic;
|
return topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ForumTopicManager::Topic *ForumTopicManager::get_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id) {
|
||||||
|
return dialog_topics->topics_.get_pointer(top_thread_message_id);
|
||||||
|
}
|
||||||
|
|
||||||
ForumTopicManager::Topic *ForumTopicManager::add_topic(DialogId dialog_id, MessageId top_thread_message_id) {
|
ForumTopicManager::Topic *ForumTopicManager::add_topic(DialogId dialog_id, MessageId top_thread_message_id) {
|
||||||
return add_topic(add_dialog_topics(dialog_id), top_thread_message_id);
|
return add_topic(add_dialog_topics(dialog_id), top_thread_message_id);
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,10 @@ class ForumTopicManager final : public Actor {
|
|||||||
tl_object_ptr<telegram_api::peerNotifySettings> &&peer_notify_settings,
|
tl_object_ptr<telegram_api::peerNotifySettings> &&peer_notify_settings,
|
||||||
const char *source);
|
const char *source);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
void on_forum_topic_edited(DialogId dialog_id, MessageId top_thread_message_id,
|
void on_forum_topic_edited(DialogId dialog_id, MessageId top_thread_message_id,
|
||||||
const ForumTopicEditedData &edited_data);
|
const ForumTopicEditedData &edited_data);
|
||||||
|
|
||||||
@ -141,8 +145,12 @@ class ForumTopicManager final : public Actor {
|
|||||||
|
|
||||||
DialogTopics *add_dialog_topics(DialogId dialog_id);
|
DialogTopics *add_dialog_topics(DialogId dialog_id);
|
||||||
|
|
||||||
|
DialogTopics *get_dialog_topics(DialogId dialog_id);
|
||||||
|
|
||||||
static Topic *add_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id);
|
static Topic *add_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id);
|
||||||
|
|
||||||
|
static Topic *get_topic(DialogTopics *dialog_topics, MessageId top_thread_message_id);
|
||||||
|
|
||||||
Topic *add_topic(DialogId dialog_id, MessageId top_thread_message_id);
|
Topic *add_topic(DialogId dialog_id, MessageId top_thread_message_id);
|
||||||
|
|
||||||
Topic *get_topic(DialogId dialog_id, MessageId top_thread_message_id);
|
Topic *get_topic(DialogId dialog_id, MessageId top_thread_message_id);
|
||||||
|
@ -3043,6 +3043,27 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelDisc
|
|||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopic> update, Promise<Unit> &&promise) {
|
||||||
|
td_->forum_topic_manager_->on_update_forum_topic_is_pinned(
|
||||||
|
DialogId(ChannelId(update->channel_id_)), MessageId(ServerMessageId(update->topic_id_)), update->pinned_);
|
||||||
|
promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopics> update, Promise<Unit> &&promise) {
|
||||||
|
vector<MessageId> top_thread_message_ids;
|
||||||
|
for (auto &server_message_id : update->order_) {
|
||||||
|
auto message_id = MessageId(ServerMessageId(server_message_id));
|
||||||
|
if (!message_id.is_valid()) {
|
||||||
|
LOG(ERROR) << "Receive " << to_string(update);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
top_thread_message_ids.push_back(message_id);
|
||||||
|
}
|
||||||
|
td_->forum_topic_manager_->on_update_pinned_forum_topics(DialogId(ChannelId(update->channel_id_)),
|
||||||
|
std::move(top_thread_message_ids));
|
||||||
|
promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, Promise<Unit> &&promise) {
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, Promise<Unit> &&promise) {
|
||||||
int new_pts = update->pts_;
|
int new_pts = update->pts_;
|
||||||
int pts_count = update->pts_count_;
|
int pts_count = update->pts_count_;
|
||||||
@ -3799,12 +3820,4 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTranscribedAudi
|
|||||||
|
|
||||||
// unsupported updates
|
// unsupported updates
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopic> update, Promise<Unit> &&promise) {
|
|
||||||
promise.set_value(Unit());
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopics> update, Promise<Unit> &&promise) {
|
|
||||||
promise.set_value(Unit());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -480,6 +480,9 @@ class UpdatesManager final : public Actor {
|
|||||||
void on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionInbox> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionInbox> update, Promise<Unit> &&promise);
|
||||||
void on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionOutbox> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionOutbox> update, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopic> update, Promise<Unit> &&promise);
|
||||||
|
void on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopics> update, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, Promise<Unit> &&promise);
|
||||||
void on_update(tl_object_ptr<telegram_api::updatePinnedChannelMessages> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updatePinnedChannelMessages> update, Promise<Unit> &&promise);
|
||||||
|
|
||||||
@ -564,10 +567,6 @@ class UpdatesManager final : public Actor {
|
|||||||
void on_update(tl_object_ptr<telegram_api::updateTranscribedAudio> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updateTranscribedAudio> update, Promise<Unit> &&promise);
|
||||||
|
|
||||||
// unsupported updates
|
// unsupported updates
|
||||||
|
|
||||||
void on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopic> update, Promise<Unit> &&promise);
|
|
||||||
|
|
||||||
void on_update(tl_object_ptr<telegram_api::updateChannelPinnedTopics> update, Promise<Unit> &&promise);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
Loading…
Reference in New Issue
Block a user