diff --git a/Telegram/SourceFiles/history/media/history_media_sticker.cpp b/Telegram/SourceFiles/history/media/history_media_sticker.cpp index c2a55c6af..cc8a944f2 100644 --- a/Telegram/SourceFiles/history/media/history_media_sticker.cpp +++ b/Telegram/SourceFiles/history/media/history_media_sticker.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image.h" #include "ui/emoji_config.h" #include "main/main_session.h" +#include "main/main_app_config.h" #include "mainwindow.h" // App::wnd()->sessionController. #include "window/window_session_controller.h" // isGifPausedAtLeastFor. #include "data/data_session.h" @@ -28,6 +29,10 @@ namespace { using TextState = HistoryView::TextState; +double GetEmojiStickerZoom(not_null session) { + return session->appConfig().get("emojies_animated_zoom", 0.625); +} + } // namespace HistorySticker::HistorySticker( @@ -73,13 +78,23 @@ QSize HistorySticker::countOptimalSize() { } _pixw = _data->dimensions.width(); _pixh = _data->dimensions.height(); - if (_pixw > st::maxStickerSize) { - _pixh = (st::maxStickerSize * _pixh) / _pixw; - _pixw = st::maxStickerSize; - } - if (_pixh > st::maxStickerSize) { - _pixw = (st::maxStickerSize * _pixw) / _pixh; - _pixh = st::maxStickerSize; + if (isEmojiSticker()) { + constexpr auto kIdealStickerSize = 512; + const auto zoom = GetEmojiStickerZoom(&history()->session()); + const auto convert = [&](int size) { + return int(size * st::maxStickerSize * zoom / kIdealStickerSize); + }; + _pixw = convert(_pixw); + _pixh = convert(_pixh); + } else { + if (_pixw > st::maxStickerSize) { + _pixh = (st::maxStickerSize * _pixh) / _pixw; + _pixw = st::maxStickerSize; + } + if (_pixh > st::maxStickerSize) { + _pixw = (st::maxStickerSize * _pixw) / _pixh; + _pixh = st::maxStickerSize; + } } if (_pixw < 1) _pixw = 1; if (_pixh < 1) _pixh = 1; diff --git a/Telegram/SourceFiles/main/main_app_config.cpp b/Telegram/SourceFiles/main/main_app_config.cpp new file mode 100644 index 000000000..df04b657c --- /dev/null +++ b/Telegram/SourceFiles/main/main_app_config.cpp @@ -0,0 +1,63 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "main/main_app_config.h" + +#include "main/main_session.h" +#include "apiwrap.h" + +namespace Main { +namespace { + +constexpr auto kRefreshTimeout = TimeId(3600); + +} // namespace + +AppConfig::AppConfig(not_null session) : _session(session) { + refresh(); +} + +void AppConfig::refresh() { + if (_requestId) { + return; + } + _requestId = _session->api().request(MTPhelp_GetAppConfig( + )).done([=](const MTPJSONValue &result) { + _requestId = 0; + refreshDelayed(); + if (result.type() == mtpc_jsonObject) { + for (const auto &element : result.c_jsonObject().vvalue().v) { + element.match([&](const MTPDjsonObjectValue &data) { + _data.emplace_or_assign(qs(data.vkey()), data.vvalue()); + }); + } + } + }).fail([=](const RPCError &error) { + _requestId = 0; + refreshDelayed(); + }).send(); +} + +void AppConfig::refreshDelayed() { + App::CallDelayed(kRefreshTimeout, _session, [=] { + refresh(); + }); +} + +double AppConfig::getDouble(const QString &key, double fallback) const { + const auto i = _data.find(key); + if (i == end(_data)) { + return fallback; + } + return i->second.match([&](const MTPDjsonNumber &data) { + return data.vvalue().v; + }, [&](const auto &data) { + return fallback; + }); +} + +} // namespace Main diff --git a/Telegram/SourceFiles/main/main_app_config.h b/Telegram/SourceFiles/main/main_app_config.h new file mode 100644 index 000000000..25afb4e77 --- /dev/null +++ b/Telegram/SourceFiles/main/main_app_config.h @@ -0,0 +1,37 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Main { + +class Session; + +class AppConfig final { +public: + explicit AppConfig(not_null session); + + template + Type get(const QString &key, Type fallback) const { + if constexpr (std::is_same_v) { + return getDouble(key, fallback); + } + } + +private: + void refresh(); + void refreshDelayed(); + + double getDouble(const QString &key, double fallback) const; + + not_null _session; + mtpRequestId _requestId = 0; + base::flat_map _data; + +}; + +} // namespace Main diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 10567f1d1..2cb296a5f 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/changelogs.h" #include "main/main_account.h" +#include "main/main_app_config.h" #include "storage/file_download.h" #include "storage/file_upload.h" #include "storage/localstorage.h" @@ -462,6 +463,7 @@ Session::Session( : _account(account) , _autoLockTimer([=] { checkAutoLock(); }) , _api(std::make_unique(this)) +, _appConfig(std::make_unique(this)) , _calls(std::make_unique()) , _downloader(std::make_unique(_api.get())) , _uploader(std::make_unique(_api.get())) diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index 82e7e9ff5..09ea6203a 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -62,6 +62,7 @@ class Changelogs; namespace Main { class Account; +class AppConfig; class Settings final { public: @@ -335,6 +336,9 @@ public: Stickers::EmojiPack &emojiStickersPack() { return *_emojiStickersPack; } + AppConfig &appConfig() { + return *_appConfig; + } base::Observable &downloaderTaskFinished(); @@ -388,6 +392,7 @@ private: base::Timer _autoLockTimer; const std::unique_ptr _api; + const std::unique_ptr _appConfig; const std::unique_ptr _calls; const std::unique_ptr _downloader; const std::unique_ptr _uploader; diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index bc0329479..ad7373884 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -447,6 +447,8 @@ <(src_loc)/lang/lang_values.h <(src_loc)/main/main_account.cpp <(src_loc)/main/main_account.h +<(src_loc)/main/main_app_config.cpp +<(src_loc)/main/main_app_config.h <(src_loc)/main/main_session.cpp <(src_loc)/main/main_session.h <(src_loc)/media/audio/media_audio.cpp