mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Update API scheme on layer 142: Premium reactions.
This commit is contained in:
parent
2f6f432583
commit
d87c9c72fb
11 changed files with 67 additions and 7 deletions
|
@ -1322,7 +1322,7 @@ messageReactions#4f2b9479 flags:# min:flags.0?true can_see_list:flags.2?true res
|
||||||
|
|
||||||
messages.messageReactionsList#31bd492d flags:# count:int reactions:Vector<MessagePeerReaction> chats:Vector<Chat> users:Vector<User> next_offset:flags.0?string = messages.MessageReactionsList;
|
messages.messageReactionsList#31bd492d flags:# count:int reactions:Vector<MessagePeerReaction> chats:Vector<Chat> users:Vector<User> next_offset:flags.0?string = messages.MessageReactionsList;
|
||||||
|
|
||||||
availableReaction#c077ec01 flags:# inactive:flags.0?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document around_animation:flags.1?Document center_icon:flags.1?Document = AvailableReaction;
|
availableReaction#c077ec01 flags:# inactive:flags.0?true premium:flags.2?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document around_animation:flags.1?Document center_icon:flags.1?Document = AvailableReaction;
|
||||||
|
|
||||||
messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions;
|
messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions;
|
||||||
messages.availableReactions#768e3aad hash:int reactions:Vector<AvailableReaction> = messages.AvailableReactions;
|
messages.availableReactions#768e3aad hash:int reactions:Vector<AvailableReaction> = messages.AvailableReactions;
|
||||||
|
|
|
@ -1016,7 +1016,7 @@ void Controller::fillManageSection() {
|
||||||
EditAllowedReactionsBox,
|
EditAllowedReactionsBox,
|
||||||
!_peer->isBroadcast(),
|
!_peer->isBroadcast(),
|
||||||
session->data().reactions().list(
|
session->data().reactions().list(
|
||||||
Data::Reactions::Type::Active),
|
Data::Reactions::Type::ActiveNonPremium),
|
||||||
*Data::PeerAllowedReactions(_peer),
|
*Data::PeerAllowedReactions(_peer),
|
||||||
done));
|
done));
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/reactions_settings_box.h"
|
#include "boxes/reactions_settings_box.h"
|
||||||
|
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
|
#include "data/data_user.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_message_reactions.h"
|
#include "data/data_message_reactions.h"
|
||||||
|
@ -25,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/chat/chat_theme.h"
|
#include "ui/chat/chat_theme.h"
|
||||||
#include "ui/effects/scroll_content_shadow.h"
|
#include "ui/effects/scroll_content_shadow.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
|
#include "ui/toasts/common_toasts.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
|
@ -424,6 +426,7 @@ void ReactionsSettingsBox(
|
||||||
rpl::single<QString>(base::duplicate(r.title)),
|
rpl::single<QString>(base::duplicate(r.title)),
|
||||||
st::settingsButton);
|
st::settingsButton);
|
||||||
|
|
||||||
|
const auto premium = r.premium;
|
||||||
const auto iconSize = st::settingsReactionSize;
|
const auto iconSize = st::settingsReactionSize;
|
||||||
AddReactionLottieIcon(
|
AddReactionLottieIcon(
|
||||||
button,
|
button,
|
||||||
|
@ -443,6 +446,12 @@ void ReactionsSettingsBox(
|
||||||
&button->lifetime());
|
&button->lifetime());
|
||||||
|
|
||||||
button->setClickedCallback([=, emoji = r.emoji] {
|
button->setClickedCallback([=, emoji = r.emoji] {
|
||||||
|
if (premium && !controller->session().user()->isPremium()) {
|
||||||
|
Ui::ShowMultilineToast({
|
||||||
|
.text = { u"Premium reaction."_q },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
checkButton(button);
|
checkButton(button);
|
||||||
state->selectedEmoji = emoji;
|
state->selectedEmoji = emoji;
|
||||||
});
|
});
|
||||||
|
|
|
@ -73,6 +73,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -301,6 +302,7 @@ 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());
|
||||||
|
@ -315,6 +317,9 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,6 +359,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(),
|
||||||
})
|
})
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,6 +29,7 @@ struct Reaction {
|
||||||
DocumentData *centerIcon = nullptr;
|
DocumentData *centerIcon = nullptr;
|
||||||
DocumentData *aroundAnimation = nullptr;
|
DocumentData *aroundAnimation = nullptr;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
bool premium = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Reactions final {
|
class Reactions final {
|
||||||
|
@ -39,6 +40,7 @@ public:
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
|
ActiveNonPremium,
|
||||||
Active,
|
Active,
|
||||||
All,
|
All,
|
||||||
};
|
};
|
||||||
|
@ -101,6 +103,7 @@ 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;
|
||||||
|
|
|
@ -425,6 +425,7 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
|
||||||
| (data.is_scam() ? Flag::Scam : Flag())
|
| (data.is_scam() ? Flag::Scam : Flag())
|
||||||
| (data.is_fake() ? Flag::Fake : Flag())
|
| (data.is_fake() ? Flag::Fake : Flag())
|
||||||
| (data.is_bot_inline_geo() ? Flag::BotInlineGeo : Flag())
|
| (data.is_bot_inline_geo() ? Flag::BotInlineGeo : Flag())
|
||||||
|
| (data.is_premium() ? Flag::Premium : Flag())
|
||||||
| (data.is_support() ? Flag::Support : Flag())
|
| (data.is_support() ? Flag::Support : Flag())
|
||||||
| (!minimal
|
| (!minimal
|
||||||
? (data.is_contact() ? Flag::Contact : Flag())
|
? (data.is_contact() ? Flag::Contact : Flag())
|
||||||
|
|
|
@ -381,7 +381,11 @@ HistoryInner::HistoryInner(
|
||||||
_reactionsManager->chosen(
|
_reactionsManager->chosen(
|
||||||
) | rpl::start_with_next([=](ChosenReaction reaction) {
|
) | rpl::start_with_next([=](ChosenReaction reaction) {
|
||||||
const auto item = session().data().message(reaction.context);
|
const auto item = session().data().message(reaction.context);
|
||||||
if (!item) {
|
if (!item
|
||||||
|
|| Window::ShowReactPremiumError(
|
||||||
|
_controller,
|
||||||
|
item,
|
||||||
|
reaction.emoji)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
item->toggleReaction(reaction.emoji);
|
item->toggleReaction(reaction.emoji);
|
||||||
|
@ -1876,7 +1880,9 @@ void HistoryInner::toggleFavoriteReaction(not_null<Element*> view) const {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto item = view->data();
|
const auto item = view->data();
|
||||||
if (item->chosenReaction() != favorite) {
|
if (Window::ShowReactPremiumError(_controller, item, favorite)) {
|
||||||
|
return;
|
||||||
|
} else if (item->chosenReaction() != favorite) {
|
||||||
if (const auto top = itemTop(view); top >= 0) {
|
if (const auto top = itemTop(view); top >= 0) {
|
||||||
view->animateReaction({ .emoji = favorite });
|
view->animateReaction({ .emoji = favorite });
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "api/api_who_reacted.h"
|
#include "api/api_who_reacted.h"
|
||||||
#include "layout/layout_selection.h"
|
#include "layout/layout_selection.h"
|
||||||
|
#include "window/section_widget.h"
|
||||||
#include "window/window_adaptive.h"
|
#include "window/window_adaptive.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
|
@ -349,7 +350,11 @@ ListWidget::ListWidget(
|
||||||
_reactionsManager->chosen(
|
_reactionsManager->chosen(
|
||||||
) | rpl::start_with_next([=](ChosenReaction reaction) {
|
) | rpl::start_with_next([=](ChosenReaction reaction) {
|
||||||
const auto item = session().data().message(reaction.context);
|
const auto item = session().data().message(reaction.context);
|
||||||
if (!item) {
|
if (!item
|
||||||
|
|| Window::ShowReactPremiumError(
|
||||||
|
_controller,
|
||||||
|
item,
|
||||||
|
reaction.emoji)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
item->toggleReaction(reaction.emoji);
|
item->toggleReaction(reaction.emoji);
|
||||||
|
@ -2119,7 +2124,9 @@ void ListWidget::toggleFavoriteReaction(not_null<Element*> view) const {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto item = view->data();
|
const auto item = view->data();
|
||||||
if (item->chosenReaction() != favorite) {
|
if (Window::ShowReactPremiumError(_controller, item, favorite)) {
|
||||||
|
return;
|
||||||
|
} else if (item->chosenReaction() != favorite) {
|
||||||
if (const auto top = itemTop(view); top >= 0) {
|
if (const auto top = itemTop(view); top >= 0) {
|
||||||
view->animateReaction({ .emoji = favorite });
|
view->animateReaction({ .emoji = favorite });
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,7 +443,8 @@ 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(Data::Reactions::Type::Active).size());
|
return int(reactions->list(
|
||||||
|
Data::Reactions::Type::ActiveNonPremium).size());
|
||||||
}) | rpl::distinct_until_changed();
|
}) | rpl::distinct_until_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_cloud_themes.h"
|
#include "data/data_cloud_themes.h"
|
||||||
|
#include "data/data_message_reactions.h"
|
||||||
|
#include "history/history_item.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "window/section_memento.h"
|
#include "window/section_memento.h"
|
||||||
#include "window/window_slide_animation.h"
|
#include "window/window_slide_animation.h"
|
||||||
|
@ -338,4 +340,24 @@ bool ShowSendPremiumError(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ShowReactPremiumError(
|
||||||
|
not_null<SessionController*> controller,
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
const QString &emoji) {
|
||||||
|
if (item->chosenReaction() == emoji
|
||||||
|
|| controller->session().user()->isPremium()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto &list = controller->session().data().reactions().list(
|
||||||
|
Data::Reactions::Type::Active);
|
||||||
|
const auto i = ranges::find(list, emoji, &Data::Reaction::emoji);
|
||||||
|
if (i == end(list) || !i->premium) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Ui::ShowMultilineToast({
|
||||||
|
.text = { u"Premium reaction."_q },
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
|
@ -209,4 +209,9 @@ private:
|
||||||
not_null<SessionController*> controller,
|
not_null<SessionController*> controller,
|
||||||
not_null<DocumentData*> document);
|
not_null<DocumentData*> document);
|
||||||
|
|
||||||
|
[[nodiscard]] bool ShowReactPremiumError(
|
||||||
|
not_null<SessionController*> controller,
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
const QString &emoji);
|
||||||
|
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
Loading…
Add table
Reference in a new issue