mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-18 22:17:01 +00:00
Respect reactions_default from appconfig.
This commit is contained in:
parent
f3e84de5fb
commit
8a071fe1fe
@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_document.h"
|
||||
@ -47,6 +49,18 @@ Reactions::Reactions(not_null<Session*> owner)
|
||||
_pollItems.remove(item);
|
||||
_repaintItems.remove(item);
|
||||
}, _lifetime);
|
||||
|
||||
const auto appConfig = &_owner->session().account().appConfig();
|
||||
appConfig->value(
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto favorite = appConfig->get<QString>(
|
||||
u"reactions_default"_q,
|
||||
QString::fromUtf8("\xf0\x9f\x91\x8d"));
|
||||
if (_favorite != favorite) {
|
||||
_favorite = favorite;
|
||||
_updated.fire({});
|
||||
}
|
||||
}, _lifetime);
|
||||
}
|
||||
|
||||
Reactions::~Reactions() = default;
|
||||
@ -63,6 +77,10 @@ const std::vector<Reaction> &Reactions::list(Type type) const {
|
||||
Unexpected("Type in Reactions::list.");
|
||||
}
|
||||
|
||||
QString Reactions::favorite() const {
|
||||
return _favorite;
|
||||
}
|
||||
|
||||
rpl::producer<> Reactions::updates() const {
|
||||
return _updated.events();
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
All,
|
||||
};
|
||||
[[nodiscard]] const std::vector<Reaction> &list(Type type) const;
|
||||
[[nodiscard]] QString favorite() const;
|
||||
|
||||
[[nodiscard]] static base::flat_set<QString> ParseAllowed(
|
||||
const MTPVector<MTPstring> *list);
|
||||
@ -95,6 +96,7 @@ private:
|
||||
|
||||
std::vector<Reaction> _active;
|
||||
std::vector<Reaction> _available;
|
||||
QString _favorite;
|
||||
base::flat_map<
|
||||
not_null<DocumentData*>,
|
||||
std::shared_ptr<Data::DocumentMedia>> _iconsCache;
|
||||
|
@ -456,16 +456,25 @@ void Manager::applyListFilters() {
|
||||
&& (_buttonAlreadyNotMineCount >= limit);
|
||||
auto icons = std::vector<not_null<ReactionIcons*>>();
|
||||
icons.reserve(_list.size());
|
||||
auto favoriteIndex = -1;
|
||||
for (auto &icon : _list) {
|
||||
const auto &emoji = icon.emoji;
|
||||
const auto add = applyUniqueLimit
|
||||
? _buttonAlreadyList.contains(icon.emoji)
|
||||
: (!_filter || _filter->contains(icon.emoji));
|
||||
? _buttonAlreadyList.contains(emoji)
|
||||
: (!_filter || _filter->contains(emoji));
|
||||
if (add) {
|
||||
if (emoji == _favorite) {
|
||||
favoriteIndex = int(icons.size());
|
||||
}
|
||||
icons.push_back(&icon);
|
||||
} else {
|
||||
clearStateForHidden(icon);
|
||||
}
|
||||
}
|
||||
if (favoriteIndex > 0) {
|
||||
const auto first = begin(icons);
|
||||
std::rotate(first, first + favoriteIndex, first + favoriteIndex + 1);
|
||||
}
|
||||
if (_icons == icons) {
|
||||
return;
|
||||
}
|
||||
@ -534,14 +543,23 @@ void Manager::showButtonDelayed() {
|
||||
[=]{ updateButton({}); });
|
||||
}
|
||||
|
||||
void Manager::applyList(const std::vector<Data::Reaction> &list) {
|
||||
void Manager::applyList(
|
||||
const std::vector<Data::Reaction> &list,
|
||||
const QString &favorite) {
|
||||
const auto proj = [](const auto &obj) {
|
||||
return std::tie(
|
||||
obj.emoji,
|
||||
obj.appearAnimation,
|
||||
obj.selectAnimation);
|
||||
};
|
||||
const auto favoriteChanged = (_favorite != favorite);
|
||||
if (favoriteChanged) {
|
||||
_favorite = favorite;
|
||||
}
|
||||
if (ranges::equal(_list, list, ranges::equal_to(), proj, proj)) {
|
||||
if (favoriteChanged) {
|
||||
applyListFilters();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const auto selected = _selectedIcon;
|
||||
@ -1533,13 +1551,15 @@ void SetupManagerList(
|
||||
not_null<Manager*> manager,
|
||||
not_null<Main::Session*> session,
|
||||
rpl::producer<std::optional<base::flat_set<QString>>> filter) {
|
||||
const auto reactions = &session->data().reactions();
|
||||
rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(
|
||||
session->data().reactions().updates()
|
||||
reactions->updates()
|
||||
) | rpl::start_with_next([=] {
|
||||
manager->applyList(
|
||||
session->data().reactions().list(Data::Reactions::Type::Active));
|
||||
reactions->list(Data::Reactions::Type::Active),
|
||||
reactions->favorite());
|
||||
}, manager->lifetime());
|
||||
|
||||
std::move(
|
||||
|
@ -141,7 +141,9 @@ public:
|
||||
IconFactory iconFactory);
|
||||
~Manager();
|
||||
|
||||
void applyList(const std::vector<Data::Reaction> &list);
|
||||
void applyList(
|
||||
const std::vector<Data::Reaction> &list,
|
||||
const QString &favorite);
|
||||
void updateAllowedSublist(std::optional<base::flat_set<QString>> filter);
|
||||
void updateUniqueLimit(not_null<HistoryItem*> item);
|
||||
|
||||
@ -296,6 +298,7 @@ private:
|
||||
const IconFactory _iconFactory;
|
||||
rpl::event_stream<Chosen> _chosen;
|
||||
std::vector<ReactionIcons> _list;
|
||||
QString _favorite;
|
||||
std::optional<base::flat_set<QString>> _filter;
|
||||
QSize _outer;
|
||||
QRect _inner;
|
||||
|
@ -78,11 +78,12 @@ std::unique_ptr<MTP::Config> Account::prepareToStart(
|
||||
}
|
||||
|
||||
void Account::start(std::unique_ptr<MTP::Config> config) {
|
||||
_appConfig = std::make_unique<AppConfig>(this);
|
||||
startMtp(config
|
||||
? std::move(config)
|
||||
: std::make_unique<MTP::Config>(
|
||||
Core::App().fallbackProductionConfig()));
|
||||
_appConfig = std::make_unique<AppConfig>(this);
|
||||
_appConfig->start();
|
||||
watchProxyChanges();
|
||||
watchSessionChanges();
|
||||
}
|
||||
|
@ -19,12 +19,6 @@ constexpr auto kRefreshTimeout = 3600 * crl::time(1000);
|
||||
} // namespace
|
||||
|
||||
AppConfig::AppConfig(not_null<Account*> account) : _account(account) {
|
||||
account->mtpMainSessionValue(
|
||||
) | rpl::start_with_next([=](not_null<MTP::Instance*> instance) {
|
||||
_api.emplace(instance);
|
||||
refresh();
|
||||
}, _lifetime);
|
||||
|
||||
account->sessionChanges(
|
||||
) | rpl::filter([=](Session *session) {
|
||||
return (session != nullptr);
|
||||
@ -33,6 +27,14 @@ AppConfig::AppConfig(not_null<Account*> account) : _account(account) {
|
||||
}, _lifetime);
|
||||
}
|
||||
|
||||
void AppConfig::start() {
|
||||
_account->mtpMainSessionValue(
|
||||
) | rpl::start_with_next([=](not_null<MTP::Instance*> instance) {
|
||||
_api.emplace(instance);
|
||||
refresh();
|
||||
}, _lifetime);
|
||||
}
|
||||
|
||||
void AppConfig::refresh() {
|
||||
if (_requestId || !_api) {
|
||||
return;
|
||||
@ -178,6 +180,8 @@ rpl::producer<> AppConfig::suggestionRequested(const QString &key) const {
|
||||
}
|
||||
|
||||
void AppConfig::dismissSuggestion(const QString &key) {
|
||||
Expects(_api.has_value());
|
||||
|
||||
if (!_dismissedSuggestions.emplace(key).second) {
|
||||
return;
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ class AppConfig final {
|
||||
public:
|
||||
explicit AppConfig(not_null<Account*> account);
|
||||
|
||||
void start();
|
||||
|
||||
template <typename Type>
|
||||
[[nodiscard]] Type get(const QString &key, Type fallback) const {
|
||||
if constexpr (std::is_same_v<Type, double>) {
|
||||
|
Loading…
Reference in New Issue
Block a user