mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-22 16:26:52 +00:00
Scale animated emoji by server config.
This commit is contained in:
parent
f7f797dd78
commit
7d2896dd42
@ -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<Main::Session*> session) {
|
||||
return session->appConfig().get<double>("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;
|
||||
|
63
Telegram/SourceFiles/main/main_app_config.cpp
Normal file
63
Telegram/SourceFiles/main/main_app_config.cpp
Normal file
@ -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(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
|
37
Telegram/SourceFiles/main/main_app_config.h
Normal file
37
Telegram/SourceFiles/main/main_app_config.h
Normal file
@ -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*> session);
|
||||
|
||||
template <typename Type>
|
||||
Type get(const QString &key, Type fallback) const {
|
||||
if constexpr (std::is_same_v<Type, double>) {
|
||||
return getDouble(key, fallback);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
void refreshDelayed();
|
||||
|
||||
double getDouble(const QString &key, double fallback) const;
|
||||
|
||||
not_null<Session*> _session;
|
||||
mtpRequestId _requestId = 0;
|
||||
base::flat_map<QString, MTPJSONValue> _data;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Main
|
@ -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<ApiWrap>(this))
|
||||
, _appConfig(std::make_unique<AppConfig>(this))
|
||||
, _calls(std::make_unique<Calls::Instance>())
|
||||
, _downloader(std::make_unique<Storage::Downloader>(_api.get()))
|
||||
, _uploader(std::make_unique<Storage::Uploader>(_api.get()))
|
||||
|
@ -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<void> &downloaderTaskFinished();
|
||||
|
||||
@ -388,6 +392,7 @@ private:
|
||||
base::Timer _autoLockTimer;
|
||||
|
||||
const std::unique_ptr<ApiWrap> _api;
|
||||
const std::unique_ptr<AppConfig> _appConfig;
|
||||
const std::unique_ptr<Calls::Instance> _calls;
|
||||
const std::unique_ptr<Storage::Downloader> _downloader;
|
||||
const std::unique_ptr<Storage::Uploader> _uploader;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user