Respect the maximum quote length.

This commit is contained in:
John Preston 2024-09-30 14:45:55 +04:00
parent 86c04424f6
commit 57438867b6
6 changed files with 26 additions and 2 deletions

View file

@ -3611,6 +3611,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_reply_header_short" = "Reply";
"lng_reply_quote_selected" = "Quote Selected";
"lng_reply_from_private_chat" = "This reply is from a private chat.";
"lng_reply_quote_long_title" = "Quote too long!";
"lng_reply_quote_long_text" = "The selected text is too long to quote.";
"lng_link_options_header" = "Link Preview Settings";
"lng_link_header_short" = "Link";
"lng_link_move_up" = "Move Up";

View file

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/discrete_sliders.h"
#include "ui/painter.h"
#include "ui/toast/toast.h"
#include "ui/vertical_list.h"
#include "ui/ui_utility.h"
#include "window/themes/window_theme.h"
@ -843,7 +844,14 @@ void DraftOptionsBox(
: tr::lng_reply_quote_selected();
}) | rpl::flatten_latest();
box->addButton(std::move(save), [=] {
finish(resolveReply(), state->webpage);
if (state->quote.current().overflown) {
show->showToast({
.title = tr::lng_reply_quote_long_title(tr::now),
.text = tr::lng_reply_quote_long_text(tr::now),
});
} else {
finish(resolveReply(), state->webpage);
}
});
box->addButton(tr::lng_cancel(), [=] {

View file

@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/core_settings.h"
#include "core/click_handler_types.h"
#include "core/ui_integration.h"
#include "main/main_app_config.h"
#include "main/main_session.h"
#include "chat_helpers/stickers_emoji_pack.h"
#include "window/window_session_controller.h"
@ -1652,6 +1653,12 @@ SelectedQuote Element::FindSelectedQuote(
if (modified.empty() || modified.to > result.text.size()) {
return {};
}
const auto session = &item->history()->session();
const auto limit = session->appConfig().quoteLengthMax();
const auto overflown = (modified.from + limit < modified.to);
if (overflown) {
modified.to = modified.from + limit;
}
result.text = result.text.mid(
modified.from,
modified.to - modified.from);
@ -1678,7 +1685,7 @@ SelectedQuote Element::FindSelectedQuote(
++i;
}
}
return { item, result, modified.from };
return { item, result, modified.from, overflown };
}
TextSelection Element::FindSelectionFromQuote(

View file

@ -294,6 +294,7 @@ struct SelectedQuote {
HistoryItem *item = nullptr;
TextWithEntities text;
int offset = 0;
bool overflown = false;
explicit operator bool() const {
return item && !text.empty();

View file

@ -38,6 +38,10 @@ void AppConfig::start() {
}, _lifetime);
}
int AppConfig::quoteLengthMax() const {
return get<int>(u"quote_length_max"_q, 1024);
}
void AppConfig::refresh(bool force) {
if (_requestId || !_api) {
if (force) {

View file

@ -63,6 +63,8 @@ public:
return _ignoreRestrictionChanges.events();
}
[[nodiscard]] int quoteLengthMax() const;
void refresh(bool force = false);
private: