mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
chore: some fixes
translator cache, filter zalgo in author, semi-transparent deleted messages with replies
This commit is contained in:
@@ -460,11 +460,7 @@ void AyuSettings::validate() {
|
||||
validateEnum(_showRepeatMessageInContextMenu, defaults._showRepeatMessageInContextMenu);
|
||||
validateEnum(_showAddFilterInContextMenu, defaults._showAddFilterInContextMenu);
|
||||
|
||||
const auto &provider = _translationProvider.current();
|
||||
if (provider != "telegram" && provider != "google" && provider != "yandex") {
|
||||
_translationProvider = defaults._translationProvider.current();
|
||||
modified = true;
|
||||
}
|
||||
validateEnum(_translationProvider, defaults._translationProvider);
|
||||
|
||||
validateRange(_wideMultiplier, 0.5, 4.0, defaults._wideMultiplier);
|
||||
validateRange(_recentStickersCount, 1, 200, defaults._recentStickersCount);
|
||||
@@ -916,7 +912,7 @@ void AyuSettings::setVoiceConfirmation(bool val) {
|
||||
save();
|
||||
}
|
||||
|
||||
void AyuSettings::setTranslationProvider(const QString &val) {
|
||||
void AyuSettings::setTranslationProvider(TranslationProvider val) {
|
||||
if (_translationProvider.current() == val) return;
|
||||
_translationProvider = val;
|
||||
Ayu::Translator::TranslateManager::currentInstance()->resetCache();
|
||||
|
||||
@@ -38,6 +38,12 @@ enum class ContextMenuVisibility {
|
||||
VisibleWithModifier = 2,
|
||||
};
|
||||
|
||||
enum class TranslationProvider {
|
||||
Telegram = 0,
|
||||
Google = 1,
|
||||
Yandex = 2,
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(PeerIdDisplay, {
|
||||
{PeerIdDisplay::Hidden, 0},
|
||||
{PeerIdDisplay::TelegramApi, 1},
|
||||
@@ -56,6 +62,12 @@ NLOHMANN_JSON_SERIALIZE_ENUM(ContextMenuVisibility, {
|
||||
{ContextMenuVisibility::VisibleWithModifier, 2},
|
||||
})
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(TranslationProvider, {
|
||||
{TranslationProvider::Telegram, "telegram"},
|
||||
{TranslationProvider::Google, "google"},
|
||||
{TranslationProvider::Yandex, "yandex"},
|
||||
})
|
||||
|
||||
class GhostModeAccountSettings {
|
||||
public:
|
||||
GhostModeAccountSettings();
|
||||
@@ -285,7 +297,7 @@ public:
|
||||
[[nodiscard]] bool stickerConfirmation() const { return _stickerConfirmation.current(); }
|
||||
[[nodiscard]] bool gifConfirmation() const { return _gifConfirmation.current(); }
|
||||
[[nodiscard]] bool voiceConfirmation() const { return _voiceConfirmation.current(); }
|
||||
[[nodiscard]] const QString &translationProvider() const { return _translationProvider.current(); }
|
||||
[[nodiscard]] TranslationProvider translationProvider() const { return _translationProvider.current(); }
|
||||
[[nodiscard]] bool adaptiveCoverColor() const { return _adaptiveCoverColor.current(); }
|
||||
[[nodiscard]] bool improveLinkPreviews() const { return _improveLinkPreviews.current(); }
|
||||
[[nodiscard]] bool crashReporting() const { return _crashReporting.current(); }
|
||||
@@ -361,7 +373,7 @@ public:
|
||||
void setStickerConfirmation(bool val);
|
||||
void setGifConfirmation(bool val);
|
||||
void setVoiceConfirmation(bool val);
|
||||
void setTranslationProvider(const QString &val);
|
||||
void setTranslationProvider(TranslationProvider val);
|
||||
void setAdaptiveCoverColor(bool val);
|
||||
void setImproveLinkPreviews(bool val);
|
||||
void setCrashReporting(bool val);
|
||||
@@ -438,7 +450,7 @@ public:
|
||||
[[nodiscard]] rpl::producer<bool> stickerConfirmationChanges() const { return _stickerConfirmation.value(); }
|
||||
[[nodiscard]] rpl::producer<bool> gifConfirmationChanges() const { return _gifConfirmation.value(); }
|
||||
[[nodiscard]] rpl::producer<bool> voiceConfirmationChanges() const { return _voiceConfirmation.value(); }
|
||||
[[nodiscard]] rpl::producer<QString> translationProviderChanges() const { return _translationProvider.value(); }
|
||||
[[nodiscard]] rpl::producer<TranslationProvider> translationProviderChanges() const { return _translationProvider.value(); }
|
||||
[[nodiscard]] rpl::producer<bool> adaptiveCoverColorChanges() const { return _adaptiveCoverColor.value(); }
|
||||
[[nodiscard]] rpl::producer<bool> improveLinkPreviewsChanges() const { return _improveLinkPreviews.value(); }
|
||||
[[nodiscard]] rpl::producer<bool> crashReportingChanges() const { return _crashReporting.value(); }
|
||||
@@ -523,7 +535,7 @@ private:
|
||||
rpl::variable<bool> _stickerConfirmation = false;
|
||||
rpl::variable<bool> _gifConfirmation = false;
|
||||
rpl::variable<bool> _voiceConfirmation = false;
|
||||
rpl::variable<QString> _translationProvider = QString("telegram");
|
||||
rpl::variable<TranslationProvider> _translationProvider = TranslationProvider::Telegram;
|
||||
rpl::variable<bool> _adaptiveCoverColor = true;
|
||||
rpl::variable<bool> _improveLinkPreviews = false;
|
||||
rpl::variable<bool> _crashReporting = true;
|
||||
|
||||
@@ -24,6 +24,21 @@
|
||||
// todo: expose available languages from current translator and use in `ChooseTranslateToBox`
|
||||
|
||||
namespace Ayu::Translator {
|
||||
namespace {
|
||||
|
||||
BaseTranslator &translatorForProvider(TranslationProvider provider) {
|
||||
switch (provider) {
|
||||
case TranslationProvider::Telegram:
|
||||
return TelegramTranslator::instance();
|
||||
case TranslationProvider::Yandex:
|
||||
return YandexTranslator::instance();
|
||||
case TranslationProvider::Google:
|
||||
return GoogleTranslator::instance();
|
||||
}
|
||||
return GoogleTranslator::instance();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TranslateManager::Builder::Builder(
|
||||
TranslateManager &manager,
|
||||
@@ -228,13 +243,7 @@ mtpRequestId TranslateManager::performTranslation(Builder &req) {
|
||||
|
||||
if (const auto it = _pending.find(id); it != _pending.end()) {
|
||||
const auto &settings = AyuSettings::getInstance();
|
||||
if (settings.translationProvider() == "telegram") {
|
||||
it->second.cancel = TelegramTranslator::instance().startTranslation(args);
|
||||
} else if (settings.translationProvider() == "yandex") {
|
||||
it->second.cancel = YandexTranslator::instance().startTranslation(args);
|
||||
} else {
|
||||
it->second.cancel = GoogleTranslator::instance().startTranslation(args);
|
||||
}
|
||||
it->second.cancel = translatorForProvider(settings.translationProvider()).startTranslation(args);
|
||||
}
|
||||
|
||||
return id;
|
||||
|
||||
@@ -41,11 +41,8 @@ void BuildTranslator(SectionBuilder &builder, AyuSectionBuilder &ayu) {
|
||||
QString("Yandex")
|
||||
};
|
||||
|
||||
const auto getIndex = [=](const QString &val) {
|
||||
if (val == "telegram") return 0;
|
||||
if (val == "google") return 1;
|
||||
if (val == "yandex") return 2;
|
||||
return 0;
|
||||
const auto getIndex = [=](TranslationProvider val) {
|
||||
return static_cast<int>(val);
|
||||
};
|
||||
|
||||
auto currentVal = AyuSettings::getInstance().translationProviderChanges()
|
||||
@@ -62,10 +59,8 @@ void BuildTranslator(SectionBuilder &builder, AyuSectionBuilder &ayu) {
|
||||
controller->show(Box(
|
||||
[=](not_null<Ui::GenericBox*> box) {
|
||||
const auto save = [=](int index) {
|
||||
const auto provider = (index == 0)
|
||||
? "telegram"
|
||||
: (index == 1) ? "google" : "yandex";
|
||||
AyuSettings::getInstance().setTranslationProvider(provider);
|
||||
AyuSettings::getInstance().setTranslationProvider(
|
||||
static_cast<TranslationProvider>(index));
|
||||
};
|
||||
SingleChoiceBox(box, {
|
||||
.title = tr::ayu_TranslationProvider(),
|
||||
|
||||
@@ -1225,7 +1225,7 @@ void LanguageBox::setupTop(not_null<Ui::VerticalLayout*> container) {
|
||||
auto premium = Data::AmPremiumValue(&_controller->session()) | rpl::map([=](bool val)
|
||||
{
|
||||
// const auto &settings = AyuSettings::getInstance();
|
||||
// if (settings.translationProvider != "telegram") {
|
||||
// if (settings.translationProvider() != TranslationProvider::Telegram) {
|
||||
// return true;
|
||||
// }
|
||||
// return val;
|
||||
|
||||
@@ -7773,3 +7773,7 @@ void HistoryItem::overrideMedia(std::unique_ptr<Data::Media> media) {
|
||||
|
||||
_media = std::move(media);
|
||||
}
|
||||
|
||||
void HistoryItem::removeTranslationBit() {
|
||||
RemoveComponents(HistoryMessageTranslation::Bit());
|
||||
}
|
||||
|
||||
@@ -611,6 +611,7 @@ public:
|
||||
[[nodiscard]] int unsupportedTTL() const {
|
||||
return _unsupportedTTL;
|
||||
}
|
||||
void removeTranslationBit();
|
||||
|
||||
[[nodiscard]] int boostsApplied() const {
|
||||
return _boostsApplied;
|
||||
|
||||
@@ -834,6 +834,21 @@ HistoryWidget::HistoryWidget(
|
||||
this->update();
|
||||
}, lifetime());
|
||||
|
||||
AyuSettings::getInstance().translationProviderChanges(
|
||||
) | rpl::on_next([=](TranslationProvider) {
|
||||
if (_history) {
|
||||
for (const auto &block : _history->blocks) {
|
||||
for (const auto &view : block->messages) {
|
||||
const auto item = view->data();
|
||||
if (item->Has<HistoryMessageTranslation>()) {
|
||||
item->removeTranslationBit();
|
||||
_history->owner().requestItemTextRefresh(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, lifetime());
|
||||
|
||||
using MessageUpdateFlag = Data::MessageUpdate::Flag;
|
||||
session().changes().messageUpdates(
|
||||
MessageUpdateFlag::Destroyed
|
||||
|
||||
@@ -105,6 +105,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
// AyuGram includes
|
||||
#include "ayu/ayu_settings.h"
|
||||
#include "history/history_item_components.h"
|
||||
|
||||
|
||||
namespace HistoryView {
|
||||
@@ -2205,6 +2206,21 @@ void ComposeControls::init() {
|
||||
orderControls();
|
||||
}, _wrap->lifetime());
|
||||
|
||||
AyuSettings::getInstance().translationProviderChanges(
|
||||
) | rpl::on_next([=](TranslationProvider) {
|
||||
if (_history) {
|
||||
for (const auto &block : _history->blocks) {
|
||||
for (const auto &view : block->messages) {
|
||||
const auto item = view->data();
|
||||
if (item->Has<HistoryMessageTranslation>()) {
|
||||
item->removeTranslationBit();
|
||||
_history->owner().requestItemTextRefresh(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, _wrap->lifetime());
|
||||
|
||||
orderControls();
|
||||
}
|
||||
|
||||
|
||||
@@ -467,7 +467,7 @@ void BottomInfo::layoutDateText() {
|
||||
: _data.scheduleRepeatPeriod
|
||||
? (SchedulePeriodText(_data.scheduleRepeatPeriod) + ' ')
|
||||
: QString();
|
||||
const auto author = _data.author;
|
||||
const auto author = settings.filterZalgo() ? filterZalgo(_data.author) : _data.author;
|
||||
const auto prefix = !author.isEmpty() ? u", "_q : QString();
|
||||
const auto date = edited + ((_data.flags & Data::Flag::ForwardedDate)
|
||||
? Ui::FormatDateTimeSavedFrom(_data.date)
|
||||
@@ -534,7 +534,7 @@ void BottomInfo::layoutDateText() {
|
||||
edited = TextWithEntities{ SchedulePeriodText(_data.scheduleRepeatPeriod) + ' ' };
|
||||
}
|
||||
|
||||
const auto author = _data.author;
|
||||
const auto author = settings.filterZalgo() ? filterZalgo(_data.author) : _data.author;
|
||||
const auto prefix = !author.isEmpty() ? (_data.flags & Data::Flag::Edited ? u" "_q : u", "_q) : QString();
|
||||
|
||||
const auto dateStr = (_data.flags & Data::Flag::ForwardedDate)
|
||||
|
||||
@@ -251,6 +251,7 @@ void FillBackgroundEmoji(
|
||||
bool quote,
|
||||
const Ui::BackgroundEmojiCache &cache,
|
||||
const QImage &firstGiftFrame) {
|
||||
const auto was = p.opacity(); // for semi-transparent deleted messages
|
||||
p.setClipRect(rect);
|
||||
|
||||
const auto &frames = cache.frames;
|
||||
@@ -264,7 +265,7 @@ void FillBackgroundEmoji(
|
||||
if (y >= rect.height()) {
|
||||
return;
|
||||
}
|
||||
p.setOpacity(opacity);
|
||||
p.setOpacity(was * opacity);
|
||||
p.drawImage(
|
||||
right - style::ConvertScale(x + (quote ? 12 : 0)),
|
||||
rect.y() + y,
|
||||
@@ -296,7 +297,7 @@ void FillBackgroundEmoji(
|
||||
}
|
||||
|
||||
p.setClipping(false);
|
||||
p.setOpacity(1.);
|
||||
p.setOpacity(was);
|
||||
}
|
||||
|
||||
Reply::Reply()
|
||||
|
||||
@@ -491,7 +491,7 @@ void TranslateBar::showMenu(base::unique_qptr<Ui::PopupMenu> menu) {
|
||||
&st::menuIconCancel);
|
||||
|
||||
const auto &settings = AyuSettings::getInstance();
|
||||
if (settings.translationProvider() == "telegram") {
|
||||
if (settings.translationProvider() == TranslationProvider::Telegram) {
|
||||
_menu->addSeparator();
|
||||
const auto cocoon = ChatHelpers::GenerateLocalTgsSticker(
|
||||
&_history->session(),
|
||||
|
||||
Reference in New Issue
Block a user