mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Show only one placeholder for premium reactions.
This commit is contained in:
parent
26d7abe2c9
commit
22613fc204
9 changed files with 70 additions and 27 deletions
|
@ -1017,7 +1017,7 @@ void Controller::fillManageSection() {
|
||||||
EditAllowedReactionsBox,
|
EditAllowedReactionsBox,
|
||||||
!_peer->isBroadcast(),
|
!_peer->isBroadcast(),
|
||||||
session->data().reactions().list(
|
session->data().reactions().list(
|
||||||
Data::Reactions::Type::ActiveNonPremium),
|
Data::Reactions::Type::Active),
|
||||||
*Data::PeerAllowedReactions(_peer),
|
*Data::PeerAllowedReactions(_peer),
|
||||||
done));
|
done));
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_document_media.h"
|
#include "data/data_document_media.h"
|
||||||
#include "lottie/lottie_icon.h"
|
#include "lottie/lottie_icon.h"
|
||||||
|
#include "storage/localimageloader.h"
|
||||||
|
#include "ui/image/image_location_factory.h"
|
||||||
#include "base/timer_rpl.h"
|
#include "base/timer_rpl.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
@ -73,7 +75,6 @@ void Reactions::refresh() {
|
||||||
|
|
||||||
const std::vector<Reaction> &Reactions::list(Type type) const {
|
const std::vector<Reaction> &Reactions::list(Type type) const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::ActiveNonPremium: return _activeNonPremium;
|
|
||||||
case Type::Active: return _active;
|
case Type::Active: return _active;
|
||||||
case Type::All: return _available;
|
case Type::All: return _available;
|
||||||
}
|
}
|
||||||
|
@ -302,7 +303,6 @@ void Reactions::updateFromData(const MTPDmessages_availableReactions &data) {
|
||||||
_iconsCache.emplace(document, document->createMediaView());
|
_iconsCache.emplace(document, document->createMediaView());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_activeNonPremium.clear();
|
|
||||||
_active.clear();
|
_active.clear();
|
||||||
_available.clear();
|
_available.clear();
|
||||||
_active.reserve(list.size());
|
_active.reserve(list.size());
|
||||||
|
@ -317,9 +317,6 @@ void Reactions::updateFromData(const MTPDmessages_availableReactions &data) {
|
||||||
toCache(parsed->selectAnimation);
|
toCache(parsed->selectAnimation);
|
||||||
toCache(parsed->centerIcon);
|
toCache(parsed->centerIcon);
|
||||||
toCache(parsed->aroundAnimation);
|
toCache(parsed->aroundAnimation);
|
||||||
if (!parsed->premium) {
|
|
||||||
_activeNonPremium.push_back(*parsed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,6 +336,7 @@ std::optional<Reaction> Reactions::parse(const MTPAvailableReaction &entry) {
|
||||||
}
|
}
|
||||||
const auto selectAnimation = _owner->processDocument(
|
const auto selectAnimation = _owner->processDocument(
|
||||||
data.vselect_animation());
|
data.vselect_animation());
|
||||||
|
static auto test = 0; AssertIsDebug();
|
||||||
return known
|
return known
|
||||||
? std::make_optional(Reaction{
|
? std::make_optional(Reaction{
|
||||||
.emoji = emoji,
|
.emoji = emoji,
|
||||||
|
@ -359,7 +357,7 @@ std::optional<Reaction> Reactions::parse(const MTPAvailableReaction &entry) {
|
||||||
*data.varound_animation()).get()
|
*data.varound_animation()).get()
|
||||||
: nullptr),
|
: nullptr),
|
||||||
.active = !data.is_inactive(),
|
.active = !data.is_inactive(),
|
||||||
.premium = data.is_premium(),
|
.premium = (data.is_premium() || ((++test) % 2)),
|
||||||
})
|
})
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,7 +40,6 @@ public:
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
ActiveNonPremium,
|
|
||||||
Active,
|
Active,
|
||||||
All,
|
All,
|
||||||
};
|
};
|
||||||
|
@ -103,7 +102,6 @@ private:
|
||||||
|
|
||||||
const not_null<Session*> _owner;
|
const not_null<Session*> _owner;
|
||||||
|
|
||||||
std::vector<Reaction> _activeNonPremium;
|
|
||||||
std::vector<Reaction> _active;
|
std::vector<Reaction> _active;
|
||||||
std::vector<Reaction> _available;
|
std::vector<Reaction> _available;
|
||||||
QString _favorite;
|
QString _favorite;
|
||||||
|
|
|
@ -323,6 +323,15 @@ rpl::producer<bool> CanManageGroupCallValue(not_null<PeerData*> peer) {
|
||||||
return rpl::single(false);
|
return rpl::single(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<bool> AmPremiumValue(not_null<Main::Session*> session) {
|
||||||
|
return session->user()->flagsValue(
|
||||||
|
) | rpl::filter([=](UserData::Flags::Change change) {
|
||||||
|
return (change.diff & UserDataFlag::Premium);
|
||||||
|
}) | rpl::map([=] {
|
||||||
|
return session->user()->isPremium();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now) {
|
TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now) {
|
||||||
if (user->isServiceUser() || user->isBot()) {
|
if (user->isServiceUser() || user->isBot()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -104,12 +104,18 @@ inline auto PeerFullFlagValue(
|
||||||
[[nodiscard]] rpl::producer<bool> CanWriteValue(ChatData *chat);
|
[[nodiscard]] rpl::producer<bool> CanWriteValue(ChatData *chat);
|
||||||
[[nodiscard]] rpl::producer<bool> CanWriteValue(ChannelData *channel);
|
[[nodiscard]] rpl::producer<bool> CanWriteValue(ChannelData *channel);
|
||||||
[[nodiscard]] rpl::producer<bool> CanWriteValue(not_null<PeerData*> peer);
|
[[nodiscard]] rpl::producer<bool> CanWriteValue(not_null<PeerData*> peer);
|
||||||
[[nodiscard]] rpl::producer<bool> CanPinMessagesValue(not_null<PeerData*> peer);
|
[[nodiscard]] rpl::producer<bool> CanPinMessagesValue(
|
||||||
[[nodiscard]] rpl::producer<bool> CanManageGroupCallValue(not_null<PeerData*> peer);
|
not_null<PeerData*> peer);
|
||||||
|
[[nodiscard]] rpl::producer<bool> CanManageGroupCallValue(
|
||||||
|
not_null<PeerData*> peer);
|
||||||
|
[[nodiscard]] rpl::producer<bool> AmPremiumValue(
|
||||||
|
not_null<Main::Session*> session);
|
||||||
|
|
||||||
[[nodiscard]] TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now);
|
[[nodiscard]] TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now);
|
||||||
[[nodiscard]] crl::time OnlineChangeTimeout(TimeId online, TimeId now);
|
[[nodiscard]] crl::time OnlineChangeTimeout(TimeId online, TimeId now);
|
||||||
[[nodiscard]] crl::time OnlineChangeTimeout(not_null<UserData*> user, TimeId now);
|
[[nodiscard]] crl::time OnlineChangeTimeout(
|
||||||
|
not_null<UserData*> user,
|
||||||
|
TimeId now);
|
||||||
[[nodiscard]] QString OnlineText(TimeId online, TimeId now);
|
[[nodiscard]] QString OnlineText(TimeId online, TimeId now);
|
||||||
[[nodiscard]] QString OnlineText(not_null<UserData*> user, TimeId now);
|
[[nodiscard]] QString OnlineText(not_null<UserData*> user, TimeId now);
|
||||||
[[nodiscard]] QString OnlineTextFull(not_null<UserData*> user, TimeId now);
|
[[nodiscard]] QString OnlineTextFull(not_null<UserData*> user, TimeId now);
|
||||||
|
|
|
@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_document_media.h"
|
#include "data/data_document_media.h"
|
||||||
|
#include "data/data_peer_values.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
#include "lottie/lottie_icon.h"
|
#include "lottie/lottie_icon.h"
|
||||||
|
@ -467,6 +468,7 @@ void Manager::applyListFilters() {
|
||||||
&& (_buttonAlreadyNotMineCount >= limit);
|
&& (_buttonAlreadyNotMineCount >= limit);
|
||||||
auto icons = std::vector<not_null<ReactionIcons*>>();
|
auto icons = std::vector<not_null<ReactionIcons*>>();
|
||||||
icons.reserve(_list.size());
|
icons.reserve(_list.size());
|
||||||
|
auto showPremiumLock = (ReactionIcons*)nullptr;
|
||||||
auto favoriteIndex = -1;
|
auto favoriteIndex = -1;
|
||||||
for (auto &icon : _list) {
|
for (auto &icon : _list) {
|
||||||
const auto &emoji = icon.emoji;
|
const auto &emoji = icon.emoji;
|
||||||
|
@ -474,14 +476,25 @@ void Manager::applyListFilters() {
|
||||||
? _buttonAlreadyList.contains(emoji)
|
? _buttonAlreadyList.contains(emoji)
|
||||||
: (!_filter || _filter->contains(emoji));
|
: (!_filter || _filter->contains(emoji));
|
||||||
if (add) {
|
if (add) {
|
||||||
if (emoji == _favorite) {
|
if (icon.premium
|
||||||
favoriteIndex = int(icons.size());
|
&& !_allowSendingPremium
|
||||||
|
&& !_buttonAlreadyList.contains(emoji)) {
|
||||||
|
showPremiumLock = &icon;
|
||||||
|
} else {
|
||||||
|
icon.premiumLock = false;
|
||||||
|
if (emoji == _favorite) {
|
||||||
|
favoriteIndex = int(icons.size());
|
||||||
|
}
|
||||||
|
icons.push_back(&icon);
|
||||||
}
|
}
|
||||||
icons.push_back(&icon);
|
|
||||||
} else {
|
} else {
|
||||||
clearStateForHidden(icon);
|
clearStateForHidden(icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (showPremiumLock) {
|
||||||
|
showPremiumLock->premiumLock = true;
|
||||||
|
icons.push_back(showPremiumLock);
|
||||||
|
}
|
||||||
if (favoriteIndex > 0) {
|
if (favoriteIndex > 0) {
|
||||||
const auto first = begin(icons);
|
const auto first = begin(icons);
|
||||||
std::rotate(first, first + favoriteIndex, first + favoriteIndex + 1);
|
std::rotate(first, first + favoriteIndex, first + favoriteIndex + 1);
|
||||||
|
@ -492,7 +505,7 @@ void Manager::applyListFilters() {
|
||||||
const auto selected = _selectedIcon;
|
const auto selected = _selectedIcon;
|
||||||
setSelectedIcon(-1);
|
setSelectedIcon(-1);
|
||||||
_icons = std::move(icons);
|
_icons = std::move(icons);
|
||||||
setSelectedIcon(selected < _icons.size() ? selected : -1);
|
setSelectedIcon((selected < _icons.size()) ? selected : -1);
|
||||||
resolveMainReactionIcon();
|
resolveMainReactionIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +538,7 @@ void Manager::updateButton(ButtonParameters parameters) {
|
||||||
}
|
}
|
||||||
_buttonContext = parameters.context;
|
_buttonContext = parameters.context;
|
||||||
parameters.reactionsCount = _icons.size();
|
parameters.reactionsCount = _icons.size();
|
||||||
if (!_buttonContext || _icons.empty()) {
|
if (!_buttonContext || !parameters.reactionsCount) {
|
||||||
return;
|
return;
|
||||||
} else if (_button) {
|
} else if (_button) {
|
||||||
_button->applyParameters(parameters);
|
_button->applyParameters(parameters);
|
||||||
|
@ -564,7 +577,8 @@ void Manager::applyList(
|
||||||
return std::tie(
|
return std::tie(
|
||||||
obj.emoji,
|
obj.emoji,
|
||||||
obj.appearAnimation,
|
obj.appearAnimation,
|
||||||
obj.selectAnimation);
|
obj.selectAnimation,
|
||||||
|
obj.premium);
|
||||||
};
|
};
|
||||||
const auto favoriteChanged = (_favorite != favorite);
|
const auto favoriteChanged = (_favorite != favorite);
|
||||||
if (favoriteChanged) {
|
if (favoriteChanged) {
|
||||||
|
@ -585,10 +599,11 @@ void Manager::applyList(
|
||||||
.emoji = reaction.emoji,
|
.emoji = reaction.emoji,
|
||||||
.appearAnimation = reaction.appearAnimation,
|
.appearAnimation = reaction.appearAnimation,
|
||||||
.selectAnimation = reaction.selectAnimation,
|
.selectAnimation = reaction.selectAnimation,
|
||||||
|
.premium = reaction.premium,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
applyListFilters();
|
applyListFilters();
|
||||||
setSelectedIcon(selected < _icons.size() ? selected : -1);
|
setSelectedIcon((selected < _icons.size()) ? selected : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::updateAllowedSublist(AllowedSublist filter) {
|
void Manager::updateAllowedSublist(AllowedSublist filter) {
|
||||||
|
@ -599,6 +614,14 @@ void Manager::updateAllowedSublist(AllowedSublist filter) {
|
||||||
applyListFilters();
|
applyListFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::updateAllowSendingPremium(bool allow) {
|
||||||
|
if (_allowSendingPremium == allow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_allowSendingPremium = allow;
|
||||||
|
applyListFilters();
|
||||||
|
}
|
||||||
|
|
||||||
const Manager::AllowedSublist &Manager::allowedSublist() const {
|
const Manager::AllowedSublist &Manager::allowedSublist() const {
|
||||||
return _filter;
|
return _filter;
|
||||||
}
|
}
|
||||||
|
@ -1348,6 +1371,8 @@ void Manager::paintAllEmoji(
|
||||||
if (current) {
|
if (current) {
|
||||||
clearStateForHidden(*icon);
|
clearStateForHidden(*icon);
|
||||||
}
|
}
|
||||||
|
} else if (icon->premiumLock) {
|
||||||
|
p.fillRect(target, QColor(0, 128, 0, 128));
|
||||||
} else {
|
} else {
|
||||||
const auto appear = icon->appear.get();
|
const auto appear = icon->appear.get();
|
||||||
if (current
|
if (current
|
||||||
|
@ -1622,6 +1647,12 @@ void SetupManagerList(
|
||||||
reactions->setFavorite(emoji);
|
reactions->setFavorite(emoji);
|
||||||
manager->updateButton({});
|
manager->updateButton({});
|
||||||
}, manager->lifetime());
|
}, manager->lifetime());
|
||||||
|
|
||||||
|
Data::AmPremiumValue(
|
||||||
|
session
|
||||||
|
) | rpl::start_with_next([=](bool premium) {
|
||||||
|
manager->updateAllowSendingPremium(premium);
|
||||||
|
}, manager->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
IconFactory CachedIconFactory::createMethod() {
|
IconFactory CachedIconFactory::createMethod() {
|
||||||
|
|
|
@ -149,6 +149,7 @@ public:
|
||||||
const std::vector<Data::Reaction> &list,
|
const std::vector<Data::Reaction> &list,
|
||||||
const QString &favorite);
|
const QString &favorite);
|
||||||
void updateAllowedSublist(AllowedSublist filter);
|
void updateAllowedSublist(AllowedSublist filter);
|
||||||
|
void updateAllowSendingPremium(bool allow);
|
||||||
[[nodiscard]] const AllowedSublist &allowedSublist() const;
|
[[nodiscard]] const AllowedSublist &allowedSublist() const;
|
||||||
void updateUniqueLimit(not_null<HistoryItem*> item);
|
void updateUniqueLimit(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
|
@ -204,6 +205,8 @@ private:
|
||||||
mutable ClickHandlerPtr link;
|
mutable ClickHandlerPtr link;
|
||||||
mutable Ui::Animations::Simple selectedScale;
|
mutable Ui::Animations::Simple selectedScale;
|
||||||
bool appearAnimated = false;
|
bool appearAnimated = false;
|
||||||
|
bool premium = false;
|
||||||
|
bool premiumLock = false;
|
||||||
mutable bool selected = false;
|
mutable bool selected = false;
|
||||||
mutable bool selectAnimated = false;
|
mutable bool selectAnimated = false;
|
||||||
};
|
};
|
||||||
|
@ -340,8 +343,10 @@ private:
|
||||||
rpl::variable<int> _uniqueLimit = 0;
|
rpl::variable<int> _uniqueLimit = 0;
|
||||||
base::flat_map<not_null<DocumentData*>, ReactionDocument> _loadCache;
|
base::flat_map<not_null<DocumentData*>, ReactionDocument> _loadCache;
|
||||||
std::vector<not_null<ReactionIcons*>> _icons;
|
std::vector<not_null<ReactionIcons*>> _icons;
|
||||||
|
std::optional<ReactionIcons> _premiumIcon;
|
||||||
rpl::lifetime _loadCacheLifetime;
|
rpl::lifetime _loadCacheLifetime;
|
||||||
bool _showingAll = false;
|
bool _showingAll = false;
|
||||||
|
bool _allowSendingPremium = false;
|
||||||
mutable int _selectedIcon = -1;
|
mutable int _selectedIcon = -1;
|
||||||
|
|
||||||
std::optional<ButtonParameters> _scheduledParameters;
|
std::optional<ButtonParameters> _scheduledParameters;
|
||||||
|
|
|
@ -443,8 +443,7 @@ rpl::producer<int> FullReactionsCountValue(
|
||||||
return rpl::single(rpl::empty) | rpl::then(
|
return rpl::single(rpl::empty) | rpl::then(
|
||||||
reactions->updates()
|
reactions->updates()
|
||||||
) | rpl::map([=] {
|
) | rpl::map([=] {
|
||||||
return int(reactions->list(
|
return int(reactions->list(Data::Reactions::Type::Active).size());
|
||||||
Data::Reactions::Type::ActiveNonPremium).size());
|
|
||||||
}) | rpl::distinct_until_changed();
|
}) | rpl::distinct_until_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_chat_filters.h"
|
#include "data/data_chat_filters.h"
|
||||||
#include "data/data_folder.h"
|
#include "data/data_folder.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "data/data_peer_values.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "ui/filter_icons.h"
|
#include "ui/filter_icons.h"
|
||||||
#include "ui/wrap/vertical_layout_reorder.h"
|
#include "ui/wrap/vertical_layout_reorder.h"
|
||||||
|
@ -104,12 +105,8 @@ void FiltersMenu::setup() {
|
||||||
_container->move(0, 0);
|
_container->move(0, 0);
|
||||||
}, _outer.lifetime());
|
}, _outer.lifetime());
|
||||||
|
|
||||||
auto premium = _session->session().user()->flagsValue(
|
auto premium = Data::AmPremiumValue(&_session->session());
|
||||||
) | rpl::filter([=](UserData::Flags::Change change) {
|
|
||||||
return (change.diff & UserDataFlag::Premium);
|
|
||||||
}) | rpl::map([=] {
|
|
||||||
return _session->session().user()->isPremium();
|
|
||||||
});
|
|
||||||
const auto filters = &_session->session().data().chatsFilters();
|
const auto filters = &_session->session().data().chatsFilters();
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
rpl::single(rpl::empty) | rpl::then(filters->changed()),
|
rpl::single(rpl::empty) | rpl::then(filters->changed()),
|
||||||
|
|
Loading…
Add table
Reference in a new issue