Add Chat.view_as_topics.

This commit is contained in:
levlam 2023-11-16 13:59:32 +03:00
parent 1c8205d6de
commit f13dde54a2
4 changed files with 86 additions and 4 deletions

View File

@ -1052,7 +1052,7 @@ basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int53 memb
//@is_slow_mode_enabled True, if the slow mode is enabled in the supergroup
//@is_channel True, if the supergroup is a channel
//@is_broadcast_group True, if the supergroup is a broadcast group, i.e. only administrators can send messages and there is no limit on the number of members
//@is_forum True, if the supergroup must be shown as a forum by default
//@is_forum True, if the supergroup is a forum with topics
//@is_verified True, if the supergroup or channel is verified
//@restriction_reason If non-empty, contains a human-readable description of the reason why access to this supergroup or channel must be restricted
//@is_scam True, if many users reported this supergroup or channel as a scam
@ -1601,6 +1601,7 @@ videoChat group_call_id:int32 has_participants:Bool default_participant_id:Messa
//@has_protected_content True, if chat content can't be saved locally, forwarded, or copied
//@is_translatable True, if translation of all messages in the chat must be suggested to the user
//@is_marked_as_unread True, if the chat is marked as unread
//@view_as_topics True, if the chat is a forum supergroup that must be shown in the "View as topics" mode
//@has_scheduled_messages True, if the chat has scheduled messages
//@can_be_deleted_only_for_self True, if the chat messages can be deleted only for the current user while other users will continue to see the messages
//@can_be_deleted_for_all_users True, if the chat messages can be deleted for all users
@ -1622,7 +1623,7 @@ videoChat group_call_id:int32 has_participants:Bool default_participant_id:Messa
//@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat
//@draft_message A draft of a message in the chat; may be null if none
//@client_data Application-specific data associated with the chat. (For example, the chat scroll position or local chat notification settings can be stored here.) Persistent if the message database is used
chat id:int53 type:ChatType title:string photo:chatPhotoInfo accent_color_id:int32 background_custom_emoji_id:int64 permissions:chatPermissions last_message:message positions:vector<chatPosition> message_sender_id:MessageSender block_list:BlockList has_protected_content:Bool is_translatable:Bool is_marked_as_unread:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 unread_reaction_count:int32 notification_settings:chatNotificationSettings available_reactions:ChatAvailableReactions message_auto_delete_time:int32 background:chatBackground theme_name:string action_bar:ChatActionBar video_chat:videoChat pending_join_requests:chatJoinRequestsInfo reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
chat id:int53 type:ChatType title:string photo:chatPhotoInfo accent_color_id:int32 background_custom_emoji_id:int64 permissions:chatPermissions last_message:message positions:vector<chatPosition> message_sender_id:MessageSender block_list:BlockList has_protected_content:Bool is_translatable:Bool is_marked_as_unread:Bool view_as_topics:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 unread_reaction_count:int32 notification_settings:chatNotificationSettings available_reactions:ChatAvailableReactions message_auto_delete_time:int32 background:chatBackground theme_name:string action_bar:ChatActionBar video_chat:videoChat pending_join_requests:chatJoinRequestsInfo reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
//@description Represents a list of chats @total_count Approximate total number of chats found @chat_ids List of chat identifiers
chats total_count:int32 chat_ids:vector<int53> = Chats;
@ -6142,6 +6143,9 @@ updateChatIsTranslatable chat_id:int53 is_translatable:Bool = Update;
//@description A chat was marked as unread or was read @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread
updateChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Update;
//@description A chat default appearance has changed @chat_id Chat identifier @view_as_topics New value of view_as_topics
updateChatViewAsTopics chat_id:int53 view_as_topics:Bool = Update;
//@description A chat was blocked or unblocked @chat_id Chat identifier @block_list Block list to which the chat is added; may be null if none
updateChatBlockList chat_id:int53 block_list:BlockList = Update;

View File

@ -13147,6 +13147,8 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
td_->messages_manager_->on_update_dialog_message_ttl(DialogId(channel_id), MessageTtl(channel->ttl_period_));
td_->messages_manager_->on_update_dialog_view_as_messages(DialogId(channel_id), channel->view_forum_as_messages_);
td_->messages_manager_->on_update_dialog_is_translatable(DialogId(channel_id), !channel->translations_disabled_);
send_closure_later(td_->story_manager_actor_, &StoryManager::on_get_dialog_stories, DialogId(channel_id),

View File

@ -5338,6 +5338,8 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
STORE_FLAG(has_background);
STORE_FLAG(is_blocked_for_stories);
STORE_FLAG(is_is_blocked_for_stories_inited);
STORE_FLAG(view_as_messages);
STORE_FLAG(is_view_as_messages_inited);
END_STORE_FLAGS();
}
@ -5611,6 +5613,8 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
PARSE_FLAG(has_background);
PARSE_FLAG(is_blocked_for_stories);
PARSE_FLAG(is_is_blocked_for_stories_inited);
PARSE_FLAG(view_as_messages);
PARSE_FLAG(is_view_as_messages_inited);
END_PARSE_FLAGS();
} else {
need_repair_action_bar = false;
@ -5618,6 +5622,8 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
is_background_inited = false;
is_blocked_for_stories = false;
is_is_blocked_for_stories_inited = false;
view_as_messages = false;
is_view_as_messages_inited = false;
}
parse(last_new_message_id, parser);
@ -15660,6 +15666,7 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
auto positions = get_dialog_positions(d);
set_dialog_folder_id(d, FolderId(dialog->folder_id_));
set_dialog_view_as_messages(d, dialog->view_forum_as_messages_);
on_update_dialog_notify_settings(dialog_id, std::move(dialog->notify_settings_), source);
if (!d->notification_settings.is_synchronized && !td_->auth_manager_->is_bot()) {
@ -20772,8 +20779,8 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
get_message_object(d->dialog_id, get_message(d, d->last_message_id), "get_chat_object"),
get_chat_positions_object(d), get_default_message_sender_object(d), block_list_id.get_block_list_object(),
get_dialog_has_protected_content(d->dialog_id), is_translatable, d->is_marked_as_unread,
get_dialog_has_scheduled_messages(d), can_delete.for_self_, can_delete.for_all_users_,
can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message,
get_dialog_view_as_topics(d), get_dialog_has_scheduled_messages(d), can_delete.for_self_,
can_delete.for_all_users_, can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message,
d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(),
d->last_read_outbox_message_id.get(), d->unread_mention_count, d->unread_reaction_count,
get_chat_notification_settings_object(&d->notification_settings), std::move(available_reactions),
@ -31638,6 +31645,55 @@ void MessagesManager::on_update_pinned_dialogs(FolderId folder_id) {
reload_pinned_dialogs(DialogListId(folder_id), Auto());
}
void MessagesManager::on_update_dialog_view_as_messages(DialogId dialog_id, bool view_as_messages) {
if (td_->auth_manager_->is_bot()) {
// just in case
return;
}
if (!dialog_id.is_valid()) {
LOG(ERROR) << "Receive view_as_messages for invalid " << dialog_id;
return;
}
auto d = get_dialog_force(dialog_id, "on_update_dialog_view_as_messages");
if (d == nullptr) {
// nothing to do
return;
}
set_dialog_view_as_messages(d, view_as_messages);
}
void MessagesManager::set_dialog_view_as_messages(Dialog *d, bool view_as_messages) {
if (td_->auth_manager_->is_bot()) {
// just in case
return;
}
CHECK(d != nullptr);
if (d->view_as_messages == view_as_messages) {
if (!d->is_view_as_messages_inited) {
d->is_view_as_messages_inited = true;
on_dialog_updated(d->dialog_id, "set_dialog_view_as_messages");
}
return;
}
auto old_view_as_topics = get_dialog_view_as_topics(d);
d->view_as_messages = view_as_messages;
d->is_view_as_messages_inited = true;
on_dialog_updated(d->dialog_id, "set_dialog_view_as_messages");
LOG(INFO) << "Set " << d->dialog_id << " view_as_messages to " << view_as_messages;
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in set_dialog_view_as_messages";
auto new_view_as_topics = get_dialog_view_as_topics(d);
if (old_view_as_topics != new_view_as_topics) {
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateChatViewAsTopics>(
get_chat_id_object(d->dialog_id, "updateChatViewAsTopics"), new_view_as_topics));
}
// TODO update unread counters in chat lists
}
void MessagesManager::on_update_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread) {
if (td_->auth_manager_->is_bot()) {
// just in case
@ -33073,6 +33129,10 @@ bool MessagesManager::get_dialog_has_protected_content(DialogId dialog_id) const
}
}
bool MessagesManager::get_dialog_view_as_topics(const Dialog *d) const {
return !d->view_as_messages && is_forum_channel(d->dialog_id);
}
bool MessagesManager::get_dialog_has_scheduled_messages(const Dialog *d) const {
if (!have_input_peer(d->dialog_id, AccessRights::Read)) {
return false;
@ -36687,11 +36747,13 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&di
td_->contacts_manager_->is_user_bot(dialog_id.get_user_id());
d->is_has_bots_inited = true;
d->is_available_reactions_inited = true;
d->is_view_as_messages_inited = true;
break;
case DialogType::Chat:
d->is_is_blocked_inited = true;
d->is_is_blocked_for_stories_inited = true;
d->is_background_inited = true;
d->is_view_as_messages_inited = true;
break;
case DialogType::Channel: {
if (td_->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
@ -36729,6 +36791,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&di
d->is_theme_name_inited = true;
d->is_is_blocked_inited = true;
d->is_is_blocked_for_stories_inited = true;
d->is_view_as_messages_inited = true;
if (!d->is_folder_id_inited && !td_->auth_manager_->is_bot()) {
do_set_dialog_folder_id(
d, td_->contacts_manager_->get_secret_chat_initial_folder_id(dialog_id.get_secret_chat_id()));
@ -36923,6 +36986,10 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<DraftMessage> &&draft
!td_->auth_manager_->is_bot()) {
// asynchronously get dialog available reactions from the server
reload_dialog_info_full(dialog_id, "fix_new_dialog init available_reactions");
} else if (being_added_dialog_id_ != dialog_id && !d->is_view_as_messages_inited && is_forum_channel(dialog_id) &&
!td_->auth_manager_->is_bot()) {
// asynchronously get view_as_messages from the server
reload_dialog_info_full(dialog_id, "fix_new_dialog init view_as_messages");
}
if ((!d->know_action_bar || d->need_repair_action_bar) && !td_->auth_manager_->is_bot() &&
dialog_type != DialogType::SecretChat && dialog_id != get_my_dialog_id() &&
@ -38977,6 +39044,7 @@ void MessagesManager::on_get_channel_difference(DialogId dialog_id, int32 reques
}
set_dialog_folder_id(d, FolderId(dialog->folder_id_));
set_dialog_view_as_messages(d, dialog->view_forum_as_messages_);
on_update_dialog_notify_settings(dialog_id, std::move(dialog->notify_settings_),
"updates.channelDifferenceTooLong");

View File

@ -274,6 +274,8 @@ class MessagesManager final : public Actor {
void on_update_pinned_dialogs(FolderId folder_id);
void on_update_dialog_view_as_messages(DialogId dialog_id, bool view_as_messages);
void on_update_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread);
void on_update_dialog_is_translatable(DialogId dialog_id, bool is_translatable);
@ -1387,6 +1389,7 @@ class MessagesManager final : public Actor {
bool is_folder_id_inited = false;
bool need_repair_server_unread_count = false;
bool need_repair_channel_server_unread_count = false;
bool view_as_messages = false;
bool is_marked_as_unread = false;
bool is_blocked = false;
bool is_is_blocked_inited = false;
@ -1404,6 +1407,7 @@ class MessagesManager final : public Actor {
bool is_message_ttl_inited = false;
bool has_expected_active_group_call_id = false;
bool has_bots = false;
bool is_view_as_messages_inited = false;
bool is_has_bots_inited = false;
bool is_background_inited = false;
bool is_theme_name_inited = false;
@ -2579,6 +2583,8 @@ class MessagesManager final : public Actor {
void save_pinned_folder_dialog_ids(const DialogList &list) const;
void set_dialog_view_as_messages(Dialog *d, bool view_as_messages);
void set_dialog_is_marked_as_unread(Dialog *d, bool is_marked_as_unread);
void set_dialog_is_translatable(Dialog *d, bool is_translatable);
@ -2975,6 +2981,8 @@ class MessagesManager final : public Actor {
bool get_dialog_has_protected_content(DialogId dialog_id) const;
bool get_dialog_view_as_topics(const Dialog *d) const;
bool get_dialog_has_scheduled_messages(const Dialog *d) const;
static DialogScheduledMessages *add_dialog_scheduled_messages(Dialog *d);