Skip to content

Commit

Permalink
Respect the maximum quote length.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Sep 30, 2024
1 parent 86c0442 commit 5743886
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ For license and copyright information please follow this link:
#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"
Expand Down Expand Up @@ -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(), [=] {
Expand Down
9 changes: 8 additions & 1 deletion Telegram/SourceFiles/history/view/history_view_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ For license and copyright information please follow this link:
#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"
Expand Down Expand Up @@ -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);
Expand All @@ -1678,7 +1685,7 @@ SelectedQuote Element::FindSelectedQuote(
++i;
}
}
return { item, result, modified.from };
return { item, result, modified.from, overflown };
}

TextSelection Element::FindSelectionFromQuote(
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/history/view/history_view_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions Telegram/SourceFiles/main/main_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/main/main_app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class AppConfig final {
return _ignoreRestrictionChanges.events();
}

[[nodiscard]] int quoteLengthMax() const;

void refresh(bool force = false);

private:
Expand Down

0 comments on commit 5743886

Please sign in to comment.