Return all reactions as available in private chats.

This commit is contained in:
levlam 2022-01-19 18:10:16 +03:00
parent 305f2e87e1
commit 4e657b73ab
6 changed files with 59 additions and 10 deletions

View File

@ -5649,6 +5649,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_all_active_reactions(Td *td) {
return td->stickers_manager_->get_all_active_reactions();
}
vector<string> get_active_reactions(Td *td, const vector<string> &available_reactions) {
return td->stickers_manager_->get_active_reactions(available_reactions);
}

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_all_active_reactions(Td *td);
vector<string> get_active_reactions(Td *td, const vector<string> &available_reactions);
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date);

View File

@ -8172,6 +8172,18 @@ void MessagesManager::on_update_dialog_available_reactions(DialogId dialog_id, v
void MessagesManager::set_dialog_available_reactions(Dialog *d, vector<string> &&available_reactions) {
CHECK(!td_->auth_manager_->is_bot());
CHECK(d != nullptr);
switch (d->dialog_id.get_type()) {
case DialogType::Chat:
case DialogType::Channel:
// ok
break;
case DialogType::User:
case DialogType::SecretChat:
default:
UNREACHABLE();
break;
}
if (d->available_reactions == available_reactions) {
if (!d->is_available_reactions_inited) {
d->is_available_reactions_inited = true;
@ -8194,6 +8206,22 @@ void MessagesManager::set_dialog_available_reactions(Dialog *d, vector<string> &
}
}
vector<string> MessagesManager::get_dialog_active_reactions(const Dialog *d) const {
CHECK(d != nullptr);
switch (d->dialog_id.get_type()) {
case DialogType::User:
return get_all_active_reactions(td_);
case DialogType::Chat:
case DialogType::Channel:
return get_active_reactions(td_, d->available_reactions);
case DialogType::SecretChat:
return {};
default:
UNREACHABLE();
return {};
}
}
bool MessagesManager::update_dialog_silent_send_message(Dialog *d, bool silent_send_message) {
if (td_->auth_manager_->is_bot()) {
// just in case
@ -20580,11 +20608,10 @@ 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),
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);
get_chat_notification_settings_object(&d->notification_settings), get_dialog_active_reactions(d),
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);
}
tl_object_ptr<td_api::chat> MessagesManager::get_chat_object(DialogId dialog_id) const {
@ -29751,9 +29778,9 @@ void MessagesManager::send_update_chat_available_reactions(const Dialog *d) {
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)));
send_closure(
G()->td(), &Td::send_update,
td_api::make_object<td_api::updateChatAvailableReactions>(d->dialog_id.get(), get_dialog_active_reactions(d)));
}
void MessagesManager::send_update_secret_chats_with_user_theme(const Dialog *d) const {
@ -35088,6 +35115,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
d->has_bots = dialog_id.get_user_id() != ContactsManager::get_replies_bot_user_id() &&
td_->contacts_manager_->is_user_bot(dialog_id.get_user_id());
d->is_has_bots_inited = true;
d->is_available_reactions_inited = true;
break;
case DialogType::Chat:
d->is_is_blocked_inited = true;

View File

@ -2580,6 +2580,8 @@ class MessagesManager final : public Actor {
void set_dialog_available_reactions(Dialog *d, vector<string> &&available_reactions);
vector<string> get_dialog_active_reactions(const Dialog *d) const;
bool is_dialog_action_unneeded(DialogId dialog_id) const;
void on_send_dialog_action_timeout(DialogId dialog_id);

View File

@ -3168,6 +3168,7 @@ void StickersManager::on_get_available_reactions(
CHECK(constructor_id == telegram_api::messages_availableReactions::ID);
auto available_reactions = move_tl_object_as<telegram_api::messages_availableReactions>(available_reactions_ptr);
vector<Reaction> new_reactions;
vector<string> new_active_reactions;
for (auto &available_reaction : available_reactions->reactions_) {
Reaction reaction;
reaction.is_active_ = !available_reaction->inactive_;
@ -3193,9 +3194,14 @@ void StickersManager::on_get_available_reactions(
LOG(ERROR) << "Receive invalid reaction " << reaction.reaction_;
continue;
}
if (reaction.is_active_) {
new_active_reactions.push_back(reaction.reaction_);
}
new_reactions.push_back(std::move(reaction));
}
reactions_.reactions_ = std::move(new_reactions);
reactions_.active_reactions_ = std::move(new_active_reactions);
reactions_.hash_ = available_reactions->hash_;
send_closure(G()->td(), &Td::send_update, get_update_reactions_object());
}
@ -4842,7 +4848,11 @@ 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) {
vector<string> StickersManager::get_all_active_reactions() const {
return reactions_.active_reactions_;
}
vector<string> StickersManager::get_active_reactions(const vector<string> &available_reactions) const {
return available_reactions;
}

View File

@ -89,7 +89,9 @@ 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);
vector<string> get_all_active_reactions() const;
vector<string> get_active_reactions(const vector<string> &available_reactions) const;
void create_sticker(FileId file_id, string minithumbnail, PhotoSize thumbnail, Dimensions dimensions,
tl_object_ptr<telegram_api::documentAttributeSticker> sticker, StickerFormat sticker_format,
@ -457,6 +459,7 @@ class StickersManager final : public Actor {
int32 hash_ = 0;
bool are_being_reloaded_ = false;
vector<Reaction> reactions_;
vector<string> active_reactions_;
};
class StickerListLogEvent;