mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Support new styles list from appConfig.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -16,12 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"cloud_lng_age_verify_about_gb#one" = "To access such content, you must confirm that you are at least **{count}** year old as required by UK law.";
|
||||
"cloud_lng_age_verify_about_gb#other" = "To access such content, you must confirm that you are at least **{count}** years old as required by UK law.";
|
||||
|
||||
"cloud_lng_ai_compose_style_biblical" = "Biblical";
|
||||
"cloud_lng_ai_compose_style_formal" = "Formal";
|
||||
"cloud_lng_ai_compose_style_posh" = "Posh";
|
||||
"cloud_lng_ai_compose_style_savage" = "Savage";
|
||||
"cloud_lng_ai_compose_style_short" = "Short";
|
||||
|
||||
"cloud_lng_passport_in_ar" = "Arabic";
|
||||
"cloud_lng_passport_in_az" = "Azerbaijani";
|
||||
"cloud_lng_passport_in_bg" = "Bulgarian";
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
<file alias="voice_ttl_start.tgs">../../animations/voice_ttl_start.tgs</file>
|
||||
<file alias="chat/voice_to_video.tgs">../../animations/chat/voice_to_video.tgs</file>
|
||||
<file alias="chat/video_to_voice.tgs">../../animations/chat/video_to_voice.tgs</file>
|
||||
<file alias="chat/sparkles_emoji.tgs">../../animations/chat/sparkles_emoji.tgs</file>
|
||||
<file alias="chat/white_flag_emoji.tgs">../../animations/chat/white_flag_emoji.tgs</file>
|
||||
<file alias="palette.tgs">../../animations/palette.tgs</file>
|
||||
<file alias="sleep.tgs">../../animations/sleep.tgs</file>
|
||||
<file alias="greeting.tgs">../../animations/greeting.tgs</file>
|
||||
|
||||
@@ -11,11 +11,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "apiwrap.h"
|
||||
#include "boxes/premium_preview_box.h"
|
||||
#include "chat_helpers/compose/compose_show.h"
|
||||
#include "chat_helpers/stickers_emoji_pack.h"
|
||||
#include "chat_helpers/stickers_lottie.h"
|
||||
#include "core/ui_integration.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
#include "data/data_session.h"
|
||||
#include "lang/lang_instance.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/session/session_show.h"
|
||||
#include "main/main_app_config.h"
|
||||
@@ -38,7 +38,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/emoji_config.h"
|
||||
#include "styles/style_basic.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_chat_helpers.h"
|
||||
@@ -72,20 +71,6 @@ enum class CardState {
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] QString ToneTitle(const QString &key) {
|
||||
if (key.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
const auto value = Lang::GetNonDefaultValue(
|
||||
QByteArray("cloud_lng_ai_compose_style_") + key.toUtf8());
|
||||
if (!value.isEmpty()) {
|
||||
return value;
|
||||
}
|
||||
auto result = key;
|
||||
result[0] = result[0].toTitleCase();
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] TextWithEntities HighlightDiff(TextWithEntities text) {
|
||||
return Ui::Text::Colorized(
|
||||
Ui::Text::Wrapped(std::move(text), EntityType::Underline), 1);
|
||||
@@ -217,40 +202,21 @@ enum class CardState {
|
||||
opacity);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<Ui::LabeledEmojiTab> ResolveStyleDescriptor(
|
||||
not_null<Main::Session*> session,
|
||||
QString id,
|
||||
QString label,
|
||||
const QString &emoji) {
|
||||
const auto found = Ui::Emoji::Find(emoji);
|
||||
if (!found) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto result = Ui::LabeledEmojiTab{
|
||||
.id = std::move(id),
|
||||
.label = std::move(label),
|
||||
.emoji = found,
|
||||
[[nodiscard]] Ui::LabeledEmojiTab ResolveStyleDescriptor(
|
||||
const Main::AppConfig::AiComposeStyle &style) {
|
||||
return {
|
||||
.id = style.type,
|
||||
.label = style.title,
|
||||
.customEmojiData = Data::SerializeCustomEmojiId(style.emojiId),
|
||||
};
|
||||
const auto sticker = session->emojiStickersPack().stickerForEmoji(found);
|
||||
if (sticker.document) {
|
||||
result.customEmojiData = Data::SerializeCustomEmojiId(sticker.document);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<Ui::LabeledEmojiTab> ResolveStyleDescriptors(
|
||||
not_null<Main::Session*> session,
|
||||
const std::vector<Main::AppConfig::AiComposeStyle> &styles) {
|
||||
auto result = std::vector<Ui::LabeledEmojiTab>();
|
||||
result.reserve(styles.size());
|
||||
for (const auto &style : styles) {
|
||||
if (const auto descriptor = ResolveStyleDescriptor(
|
||||
session,
|
||||
style.key,
|
||||
ToneTitle(style.key),
|
||||
style.emoji)) {
|
||||
result.push_back(*descriptor);
|
||||
}
|
||||
result.push_back(ResolveStyleDescriptor(style));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -258,41 +224,27 @@ enum class CardState {
|
||||
[[nodiscard]] std::vector<Ui::LabeledEmojiTab> ResolveTranslateStyleDescriptors(
|
||||
not_null<Main::Session*> session,
|
||||
const std::vector<Ui::LabeledEmojiTab> &styles) {
|
||||
const auto neutral = ChatHelpers::GenerateLocalTgsSticker(
|
||||
session,
|
||||
u"chat/white_flag_emoji"_q);
|
||||
auto result = std::vector<Ui::LabeledEmojiTab>();
|
||||
result.reserve(styles.size() + 1);
|
||||
const auto neutralEmoji = QString::fromUtf8(
|
||||
"\xF0\x9F\x8F\xB3\xEF\xB8\x8F");
|
||||
auto neutral = Ui::LabeledEmojiTab{
|
||||
result.push_back({
|
||||
.id = QString(),
|
||||
.label = tr::lng_ai_compose_style_neutral(tr::now),
|
||||
.emoji = Ui::Emoji::Find(neutralEmoji),
|
||||
};
|
||||
if (neutral.emoji) {
|
||||
const auto sticker = session->emojiStickersPack().stickerForEmoji(
|
||||
neutral.emoji);
|
||||
if (sticker.document) {
|
||||
neutral.customEmojiData = Data::SerializeCustomEmojiId(
|
||||
sticker.document);
|
||||
}
|
||||
}
|
||||
result.push_back(std::move(neutral));
|
||||
.customEmojiData = Data::SerializeCustomEmojiId(neutral->id),
|
||||
});
|
||||
result.insert(end(result), begin(styles), end(styles));
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<TextWithEntities> ResolveLoadingTitleSparkle(
|
||||
[[nodiscard]] TextWithEntities LoadingTitleSparkle(
|
||||
not_null<Main::Session*> session) {
|
||||
const auto sparkleEmoji = QString::fromUtf8("\xE2\x9C\xA8");
|
||||
const auto found = Ui::Emoji::Find(sparkleEmoji);
|
||||
if (!found) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto sticker = session->emojiStickersPack().stickerForEmoji(found);
|
||||
if (!sticker.document) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto sparkles = ChatHelpers::GenerateLocalTgsSticker(
|
||||
session,
|
||||
u"chat/sparkles_emoji"_q);
|
||||
return tr::marked(u" "_q)
|
||||
.append(Data::SingleCustomEmoji(sticker.document));
|
||||
.append(Data::SingleCustomEmoji(sparkles->id));
|
||||
}
|
||||
|
||||
class ComposeAiModeButton final : public Ui::RippleButton {
|
||||
@@ -915,7 +867,6 @@ ComposeAiContent::ComposeAiContent(
|
||||
, _detectedFrom(Platform::Language::Recognize(_original.text))
|
||||
, _to(DefaultAiTranslateTo(_detectedFrom))
|
||||
, _stylesData(ResolveStyleDescriptors(
|
||||
_session,
|
||||
_session->appConfig().aiComposeStyles()))
|
||||
, _translateStylesData(ResolveTranslateStyleDescriptors(_session, _stylesData))
|
||||
, _preview(Ui::CreateChild<ComposeAiPreviewCard>(this, _session, _original)) {
|
||||
@@ -1327,7 +1278,7 @@ void ComposeAiBox(not_null<Ui::GenericBox*> box, ComposeAiBoxArgs &&args) {
|
||||
content->setModeTabs(tabs);
|
||||
content->setStyleTabs(stylesWrap);
|
||||
|
||||
if (const auto sparkle = ResolveLoadingTitleSparkle(session)) {
|
||||
const auto sparkle = LoadingTitleSparkle(session);
|
||||
const auto loading = box->lifetime().make_state<
|
||||
rpl::variable<bool>>();
|
||||
|
||||
@@ -1339,11 +1290,8 @@ void ComposeAiBox(not_null<Ui::GenericBox*> box, ComposeAiBoxArgs &&args) {
|
||||
loading->value(),
|
||||
tr::lng_ai_compose_title(tr::marked)
|
||||
) | rpl::map([=](bool loading, TextWithEntities title) {
|
||||
return loading ? title.append(*sparkle) : title;
|
||||
return loading ? title.append(sparkle) : title;
|
||||
}), Core::TextContext({ .session = session }));
|
||||
} else {
|
||||
box->setTitle(tr::lng_ai_compose_title());
|
||||
}
|
||||
|
||||
auto premiumFlooded = std::make_shared<bool>(false);
|
||||
auto sendButton = std::make_shared<QPointer<Ui::SendButton>>();
|
||||
|
||||
@@ -6268,7 +6268,9 @@ bool HistoryWidget::fieldOrDisabledShown() const {
|
||||
}
|
||||
|
||||
bool HistoryWidget::hasEnoughLinesForAi() const {
|
||||
if (!_history || _voiceRecordBar->isActive()) {
|
||||
if (!_history
|
||||
|| _voiceRecordBar->isActive()
|
||||
|| session().appConfig().aiComposeStyles().empty()) {
|
||||
return false;
|
||||
}
|
||||
const auto &style = _field->st().style;
|
||||
|
||||
@@ -3677,7 +3677,9 @@ bool ComposeControls::canSendAiComposeDirect() const {
|
||||
}
|
||||
|
||||
bool ComposeControls::hasEnoughLinesForAi() const {
|
||||
if (!_history || _recording.current()) {
|
||||
if (!_history
|
||||
|| _recording.current()
|
||||
|| session().appConfig().aiComposeStyles().empty()) {
|
||||
return false;
|
||||
}
|
||||
const auto &style = _field->st().style;
|
||||
|
||||
@@ -21,20 +21,6 @@ namespace {
|
||||
|
||||
constexpr auto kRefreshTimeout = 3600 * crl::time(1000);
|
||||
|
||||
[[nodiscard]] auto DefaultAiComposeStyles()
|
||||
-> std::vector<AppConfig::AiComposeStyle> {
|
||||
const auto emoji = [](const char *value) {
|
||||
return QString::fromUtf8(value);
|
||||
};
|
||||
return {
|
||||
{ emoji("\xF0\x9F\xA4\x9D"), u"formal"_q },
|
||||
{ emoji("\xF0\x9F\x8E\xAF"), u"short"_q },
|
||||
{ emoji("\xF0\x9F\x8D\x96"), u"savage"_q },
|
||||
{ emoji("\xF0\x9F\x95\xAF"), u"biblical"_q },
|
||||
{ emoji("\xF0\x9F\x8D\xB7"), u"posh"_q },
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AppConfig::AppConfig(not_null<Account*> account) : _account(account) {
|
||||
@@ -355,7 +341,7 @@ void AppConfig::refresh(bool force) {
|
||||
}
|
||||
updateIgnoredRestrictionReasons(std::move(was));
|
||||
|
||||
_aiComposeStyles = {};
|
||||
_aiComposeStyles.reset();
|
||||
_groupCallColorings = {};
|
||||
|
||||
DEBUG_LOG(("getAppConfig result handled."));
|
||||
@@ -567,8 +553,8 @@ bool AppConfig::newRequirePremiumFree() const {
|
||||
}
|
||||
|
||||
std::vector<AppConfig::AiComposeStyle> AppConfig::aiComposeStyles() const {
|
||||
if (!_aiComposeStyles.empty()) {
|
||||
return _aiComposeStyles;
|
||||
if (_aiComposeStyles) {
|
||||
return *_aiComposeStyles;
|
||||
}
|
||||
_aiComposeStyles = getValue(u"ai_compose_styles"_q, [&](const auto &value) {
|
||||
return value.match([&](const MTPDjsonArray &data) {
|
||||
@@ -576,27 +562,27 @@ std::vector<AppConfig::AiComposeStyle> AppConfig::aiComposeStyles() const {
|
||||
result.reserve(data.vvalue().v.size());
|
||||
for (const auto &entry : data.vvalue().v) {
|
||||
if (entry.type() != mtpc_jsonArray) {
|
||||
return DefaultAiComposeStyles();
|
||||
return std::vector<AiComposeStyle>();
|
||||
}
|
||||
const auto &list = entry.c_jsonArray().vvalue().v;
|
||||
if (list.size() < 2
|
||||
if (list.size() < 3
|
||||
|| (list[0].type() != mtpc_jsonString)
|
||||
|| (list[1].type() != mtpc_jsonString)) {
|
||||
return DefaultAiComposeStyles();
|
||||
|| (list[1].type() != mtpc_jsonString)
|
||||
|| (list[2].type() != mtpc_jsonString)) {
|
||||
return std::vector<AiComposeStyle>();
|
||||
}
|
||||
result.push_back({
|
||||
qs(list[0].c_jsonString().vvalue()),
|
||||
qs(list[1].c_jsonString().vvalue()),
|
||||
.type = qs(list[0].c_jsonString().vvalue()),
|
||||
.emojiId = qs(list[1].c_jsonString().vvalue()).toULongLong(),
|
||||
.title = qs(list[2].c_jsonString().vvalue()),
|
||||
});
|
||||
}
|
||||
return result.empty()
|
||||
? DefaultAiComposeStyles()
|
||||
: result;
|
||||
return result;
|
||||
}, [&](const auto &) {
|
||||
return DefaultAiComposeStyles();
|
||||
return std::vector<AiComposeStyle>();
|
||||
});
|
||||
});
|
||||
return _aiComposeStyles;
|
||||
return *_aiComposeStyles;
|
||||
}
|
||||
|
||||
auto AppConfig::groupCallColorings() const -> std::vector<StarsColoring> {
|
||||
|
||||
@@ -139,8 +139,9 @@ public:
|
||||
[[nodiscard]] std::vector<int64> stakeDiceNanoTonSuggested() const;
|
||||
|
||||
struct AiComposeStyle {
|
||||
QString emoji;
|
||||
QString key;
|
||||
QString type;
|
||||
DocumentId emojiId = 0;
|
||||
QString title;
|
||||
};
|
||||
[[nodiscard]] std::vector<AiComposeStyle> aiComposeStyles() const;
|
||||
|
||||
@@ -199,7 +200,7 @@ private:
|
||||
|
||||
std::vector<QString> _startRefPrefixes;
|
||||
|
||||
mutable std::vector<AiComposeStyle> _aiComposeStyles;
|
||||
mutable std::optional<std::vector<AiComposeStyle>> _aiComposeStyles;
|
||||
mutable std::vector<StarsColoring> _groupCallColorings;
|
||||
|
||||
crl::time _lastFrozenRefresh = 0;
|
||||
|
||||
Reference in New Issue
Block a user