Add chat.available_reactions and updateChatAvailableReactions.

This commit is contained in:
levlam 2022-01-04 16:33:57 +03:00
parent 789b9c0a55
commit 3becacf304
8 changed files with 103 additions and 2 deletions

View File

@ -980,6 +980,7 @@ videoChat group_call_id:int32 has_participants:Bool default_participant_id:Messa
//@last_read_outbox_message_id Identifier of the last read outgoing message
//@unread_mention_count Number of unread messages with a mention/reply in the chat
//@notification_settings Notification settings for this chat
//@available_reactions List of reactions available for this chat
//@message_ttl Current message Time To Live setting (self-destruct timer) for the chat; 0 if not defined. TTL is counted from the time message or its content is viewed in secret chats and from the send date in other chats
//@theme_name If non-empty, name of a theme, set for the chat
//@action_bar Information about actions which must be possible to do through the chat action bar; may be null
@ -988,7 +989,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
//@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 permissions:chatPermissions last_message:message positions:vector<chatPosition> message_sender_id:MessageSender has_protected_content:Bool is_marked_as_unread:Bool is_blocked: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 notification_settings:chatNotificationSettings message_ttl:int32 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 permissions:chatPermissions last_message:message positions:vector<chatPosition> message_sender_id:MessageSender has_protected_content:Bool is_marked_as_unread:Bool is_blocked: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 notification_settings:chatNotificationSettings available_reactions:vector<string> message_ttl:int32 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 count of chats found @chat_ids List of chat identifiers
chats total_count:int32 chat_ids:vector<int53> = Chats;
@ -3736,6 +3737,9 @@ updateChatReadOutbox chat_id:int53 last_read_outbox_message_id:int53 = Update;
//@description The chat action bar was changed @chat_id Chat identifier @action_bar The new value of the action bar; may be null
updateChatActionBar chat_id:int53 action_bar:ChatActionBar = Update;
//@description The chat available reactions were changed @chat_id Chat identifier @available_reactions The new list of reactions available in the chat
updateChatAvailableReactions chat_id:int53 available_reactions:vector<string> = Update;
//@description A chat draft has changed. Be aware that the update may come in the currently opened chat but with old content of the draft. If the user has changed the content of the draft, this update mustn't be applied @chat_id Chat identifier @draft_message The new draft message; may be null @positions The new chat positions in the chat lists
updateChatDraftMessage chat_id:int53 draft_message:draftMessage positions:vector<chatPosition> = Update;

View File

@ -10664,6 +10664,9 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
td_->messages_manager_->on_update_dialog_notify_settings(DialogId(chat_id), std::move(chat->notify_settings_),
"on_get_chat_full");
td_->messages_manager_->on_update_dialog_available_reactions(DialogId(chat_id),
std::move(chat->available_reactions_));
td_->messages_manager_->on_update_dialog_theme_name(DialogId(chat_id), std::move(chat->theme_emoticon_));
td_->messages_manager_->on_update_dialog_pending_join_requests(DialogId(chat_id), chat->requests_pending_,
@ -10710,6 +10713,9 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
td_->messages_manager_->on_update_dialog_notify_settings(DialogId(channel_id), std::move(channel->notify_settings_),
"on_get_channel_full");
td_->messages_manager_->on_update_dialog_available_reactions(DialogId(channel_id),
std::move(channel->available_reactions_));
td_->messages_manager_->on_update_dialog_theme_name(DialogId(channel_id), std::move(channel->theme_emoticon_));
td_->messages_manager_->on_update_dialog_pending_join_requests(DialogId(channel_id), channel->requests_pending_,

View File

@ -5648,6 +5648,10 @@ bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogActi
return !td->stickers_manager_->is_sent_animated_emoji_click(dialog_id, remove_emoji_modifiers(emoji));
}
vector<string> get_active_reactions(Td *td, const vector<string> &available_reactions) {
return td->stickers_manager_->get_active_reactions(available_reactions);
}
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date) {
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, date);
}

View File

@ -248,6 +248,8 @@ void on_sent_message_content(Td *td, const MessageContent *content);
bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogAction &action);
vector<string> get_active_reactions(Td *td, const vector<string> &available_reactions);
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date);
void update_used_hashtags(Td *td, const MessageContent *content);

View File

@ -5308,6 +5308,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
bool has_pending_join_requests = pending_join_request_count != 0;
bool has_action_bar = action_bar != nullptr;
bool has_default_send_message_as_dialog_id = default_send_message_as_dialog_id.is_valid();
bool has_available_reactions = !available_reactions.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_draft_message);
STORE_FLAG(has_last_database_message);
@ -5384,6 +5385,8 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
STORE_FLAG(has_action_bar);
STORE_FLAG(has_default_send_message_as_dialog_id);
STORE_FLAG(need_drop_default_send_message_as_dialog_id);
STORE_FLAG(has_available_reactions);
STORE_FLAG(is_available_reactions_inited);
END_STORE_FLAGS();
}
@ -5487,6 +5490,9 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
if (has_default_send_message_as_dialog_id) {
store(default_send_message_as_dialog_id, storer);
}
if (has_available_reactions) {
store(available_reactions, storer);
}
}
// do not forget to resolve dialog dependencies including dependencies of last_message
@ -5532,6 +5538,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
bool action_bar_can_invite_members = false;
bool has_action_bar = false;
bool has_default_send_message_as_dialog_id = false;
bool has_available_reactions = false;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_draft_message);
PARSE_FLAG(has_last_database_message);
@ -5623,9 +5630,12 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
PARSE_FLAG(has_action_bar);
PARSE_FLAG(has_default_send_message_as_dialog_id);
PARSE_FLAG(need_drop_default_send_message_as_dialog_id);
PARSE_FLAG(has_available_reactions);
PARSE_FLAG(is_available_reactions_inited);
END_PARSE_FLAGS();
} else {
need_repair_action_bar = false;
is_available_reactions_inited = false;
}
parse(last_new_message_id, parser);
@ -5765,6 +5775,9 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
if (has_default_send_message_as_dialog_id) {
parse(default_send_message_as_dialog_id, parser);
}
if (has_available_reactions) {
parse(available_reactions, parser);
}
(void)legacy_know_can_report_spam;
if (know_action_bar && !has_action_bar) {
@ -8061,6 +8074,43 @@ void MessagesManager::on_update_scope_notify_settings(
update_scope_notification_settings(scope, old_notification_settings, notification_settings);
}
void MessagesManager::on_update_dialog_available_reactions(DialogId dialog_id, vector<string> &&available_reactions) {
if (td_->auth_manager_->is_bot()) {
return;
}
Dialog *d = get_dialog_force(dialog_id, "on_update_dialog_available_reactions");
if (d == nullptr) {
return;
}
set_dialog_available_reactions(d, std::move(available_reactions));
}
void MessagesManager::set_dialog_available_reactions(Dialog *d, vector<string> &&available_reactions) {
CHECK(!td_->auth_manager_->is_bot());
if (d->available_reactions == available_reactions) {
if (!d->is_available_reactions_inited) {
d->is_available_reactions_inited = true;
on_dialog_updated(d->dialog_id, "set_dialog_available_reactions");
}
return;
}
VLOG(notifications) << "Update available reactions in " << d->dialog_id << " to " << available_reactions;
bool need_update =
get_active_reactions(td_, d->available_reactions) != get_active_reactions(td_, available_reactions);
d->available_reactions = std::move(available_reactions);
d->is_available_reactions_inited = true;
on_dialog_updated(d->dialog_id, "set_dialog_available_reactions");
if (need_update) {
send_update_chat_available_reactions(d);
}
}
bool MessagesManager::update_dialog_silent_send_message(Dialog *d, bool silent_send_message) {
if (td_->auth_manager_->is_bot()) {
// just in case
@ -14778,6 +14828,9 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
} else if (!d->is_last_pinned_message_id_inited && !td_->auth_manager_->is_bot()) {
// asynchronously get dialog pinned message from the server
get_dialog_pinned_message(dialog_id, Auto());
} else if (!d->is_available_reactions_inited && !td_->auth_manager_->is_bot()) {
// asynchronously get dialog available reactions from the server
get_dialog_info_full(dialog_id, Auto(), "on_get_dialogs init available_reactions");
}
need_update_dialog_pos |= update_dialog_draft_message(
@ -20418,7 +20471,8 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
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,
get_chat_notification_settings_object(&d->notification_settings), d->message_ttl.get_message_ttl_object(),
get_chat_notification_settings_object(&d->notification_settings),
get_active_reactions(td_, d->available_reactions), d->message_ttl.get_message_ttl_object(),
get_dialog_theme_name(d), get_chat_action_bar_object(d), get_video_chat_object(d),
get_chat_join_requests_info_object(d), d->reply_markup_message_id.get(), std::move(draft_message),
d->client_data);
@ -29564,6 +29618,18 @@ void MessagesManager::send_update_chat_action_bar(Dialog *d) {
send_update_secret_chats_with_user_action_bar(d);
}
void MessagesManager::send_update_chat_available_reactions(const Dialog *d) {
if (td_->auth_manager_->is_bot()) {
return;
}
CHECK(d != nullptr);
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_available_reactions";
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateChatAvailableReactions>(
d->dialog_id.get(), get_active_reactions(td_, d->available_reactions)));
}
void MessagesManager::send_update_secret_chats_with_user_theme(const Dialog *d) const {
if (td_->auth_manager_->is_bot()) {
return;
@ -34900,6 +34966,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
d->has_bots = td_->contacts_manager_->is_user_bot(
td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()));
d->is_has_bots_inited = true;
d->is_available_reactions_inited = true;
break;
case DialogType::None:
@ -35038,6 +35105,10 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
have_input_peer(dialog_id, AccessRights::Write)) {
// asynchronously get dialog message TTL from the server
get_dialog_info_full(dialog_id, Auto(), "fix_new_dialog init message_ttl");
} else if (being_added_dialog_id_ != dialog_id && !d->is_available_reactions_inited &&
!td_->auth_manager_->is_bot()) {
// asynchronously get dialog available reactions from the server
get_dialog_info_full(dialog_id, Auto(), "fix_new_dialog init available_reactions");
}
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() &&

View File

@ -825,6 +825,8 @@ class MessagesManager final : public Actor {
void on_update_scope_notify_settings(NotificationSettingsScope scope,
tl_object_ptr<telegram_api::peerNotifySettings> &&peer_notify_settings);
void on_update_dialog_available_reactions(DialogId dialog_id, vector<string> &&available_reactions);
void hide_dialog_action_bar(DialogId dialog_id);
void remove_dialog_action_bar(DialogId dialog_id, Promise<Unit> &&promise);
@ -1206,6 +1208,7 @@ class MessagesManager final : public Actor {
MessageId last_pinned_message_id;
MessageId reply_markup_message_id;
DialogNotificationSettings notification_settings;
vector<string> available_reactions;
MessageTtl message_ttl;
unique_ptr<DraftMessage> draft_message;
unique_ptr<DialogActionBar> action_bar;
@ -1293,6 +1296,7 @@ class MessagesManager final : public Actor {
bool has_bots = false;
bool is_has_bots_inited = false;
bool is_theme_name_inited = false;
bool is_available_reactions_inited = false;
bool increment_view_counter = false;
@ -2395,6 +2399,8 @@ class MessagesManager final : public Actor {
void send_update_chat_action_bar(Dialog *d);
void send_update_chat_available_reactions(const Dialog *d);
void send_update_secret_chats_with_user_theme(const Dialog *d) const;
void send_update_chat_theme(const Dialog *d);
@ -2567,6 +2573,8 @@ class MessagesManager final : public Actor {
bool update_dialog_silent_send_message(Dialog *d, bool silent_send_message);
void set_dialog_available_reactions(Dialog *d, vector<string> &&available_reactions);
bool is_dialog_action_unneeded(DialogId dialog_id) const;
void on_send_dialog_action_timeout(DialogId dialog_id);

View File

@ -4723,6 +4723,10 @@ void StickersManager::send_update_animated_emoji_clicked(FullMessageId full_mess
dialog_id.get(), full_message_id.get_message_id().get(), get_sticker_object(sticker_id, false, true)));
}
vector<string> StickersManager::get_active_reactions(const vector<string> &available_reactions) {
return available_reactions;
}
void StickersManager::view_featured_sticker_sets(const vector<StickerSetId> &sticker_set_ids) {
for (auto sticker_set_id : sticker_set_ids) {
auto set = get_sticker_set(sticker_set_id);

View File

@ -88,6 +88,8 @@ class StickersManager final : public Actor {
Status on_animated_emoji_message_clicked(Slice emoji, FullMessageId full_message_id, string data);
vector<string> get_active_reactions(const vector<string> &available_reactions);
void create_sticker(FileId file_id, string minithumbnail, PhotoSize thumbnail, Dimensions dimensions,
tl_object_ptr<telegram_api::documentAttributeSticker> sticker, bool is_animated,
MultiPromiseActor *load_data_multipromise_ptr);