Autostart bots with non-empty message history.

This commit is contained in:
levlam 2023-03-11 23:18:24 +03:00
parent 70bee089d4
commit 8847638d28
3 changed files with 18 additions and 2 deletions

View File

@ -283,8 +283,17 @@ class LinkManager::InternalLinkBotStart final : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
bool autostart = autostart_;
if (Scheduler::context() != nullptr && bot_username_ == G()->get_option_string("premium_bot_username")) {
autostart = true;
if (Scheduler::context() != nullptr && !autostart) {
if (bot_username_ == G()->get_option_string("premium_bot_username")) {
autostart = true;
} else {
const Td *td = G()->td().get_actor_unsafe();
auto dialog_id = td->messages_manager_->resolve_dialog_username(bot_username_);
if (dialog_id.is_valid() && dialog_id.get_type() == DialogType::User &&
td->messages_manager_->get_dialog_has_last_message(dialog_id)) {
autostart = true;
}
}
}
return td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username_, start_parameter_, autostart);
}

View File

@ -25952,6 +25952,11 @@ bool MessagesManager::get_dialog_silent_send_message(DialogId dialog_id) const {
return d->notification_settings.silent_send_message;
}
bool MessagesManager::get_dialog_has_last_message(DialogId dialog_id) const {
const auto *d = get_dialog(dialog_id);
return d != nullptr && d->last_message_id.is_valid();
}
DialogId MessagesManager::get_dialog_default_send_message_as_dialog_id(DialogId dialog_id) const {
auto *d = get_dialog(dialog_id);
CHECK(d != nullptr);

View File

@ -433,6 +433,8 @@ class MessagesManager final : public Actor {
bool get_dialog_silent_send_message(DialogId dialog_id) const;
bool get_dialog_has_last_message(DialogId dialog_id) const;
DialogId get_dialog_default_send_message_as_dialog_id(DialogId dialog_id) const;
Result<td_api::object_ptr<td_api::message>> send_message(