2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Allow sending premium emoji to Saved Messages.

This commit is contained in:
John Preston
2022-08-01 16:24:51 +03:00
parent 087074fea4
commit b42f2784ab
18 changed files with 93 additions and 39 deletions

View File

@@ -776,7 +776,7 @@ void EmojiListWidget::paintEvent(QPaintEvent *e) {
drawCollapsedBadge(p, w - _areaPosition, info.count);
continue;
}
if (selected && !info.premiumRequired) {
if (selected) {
auto tl = w;
if (rtl()) {
tl.setX(width() - tl.x() - st::emojiPanArea.width());
@@ -1023,7 +1023,9 @@ void EmojiListWidget::selectEmoji(EmojiPtr emoji) {
}
void EmojiListWidget::selectCustom(not_null<DocumentData*> document) {
if (document->isPremiumEmoji() && !document->session().premium()) {
if (document->isPremiumEmoji()
&& !document->session().premium()
&& !_allowWithoutPremium) {
ShowPremiumPreviewBox(
controller(),
PremiumPreview::AnimatedEmoji,
@@ -1231,6 +1233,15 @@ uint64 EmojiListWidget::currentSet(int yOffset) const {
return sectionSetId(sectionInfoByOffset(yOffset).section);
}
void EmojiListWidget::setAllowWithoutPremium(bool allow) {
if (_allowWithoutPremium == allow) {
return;
}
_allowWithoutPremium = allow;
refreshCustom();
resizeToWidth(width());
}
QString EmojiListWidget::tooltipText() const {
const auto &replacements = Ui::Emoji::internal::GetAllReplacements();
const auto over = std::get_if<OverEmoji>(&_selected);
@@ -1285,7 +1296,9 @@ void EmojiListWidget::refreshCustom() {
auto old = base::take(_custom);
const auto session = &controller()->session();
const auto premiumPossible = session->premiumPossible();
const auto premiumMayBeBought = premiumPossible && !session->premium();
const auto premiumMayBeBought = premiumPossible
&& !session->premium()
&& !_allowWithoutPremium;
const auto owner = &session->data();
const auto &sets = owner->stickers().sets();
const auto push = [&](uint64 setId, bool installed) {

View File

@@ -70,6 +70,7 @@ public:
void showSet(uint64 setId);
[[nodiscard]] uint64 currentSet(int yOffset) const;
void setAllowWithoutPremium(bool allow);
// Ui::AbstractTooltipShower interface.
QString tooltipText() const override;
@@ -274,6 +275,7 @@ private:
QVector<EmojiPtr> _emoji[kEmojiSectionCount];
std::vector<CustomSet> _custom;
base::flat_map<DocumentId, CustomEmojiInstance> _customEmoji;
bool _allowWithoutPremium = false;
int _rowsLeft = 0;
int _columnCount = 1;

View File

@@ -56,21 +56,21 @@ class FieldTagMimeProcessor final {
public:
FieldTagMimeProcessor(
not_null<Main::Session*> _session,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted);
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
QString operator()(QStringView mimeTag);
private:
const not_null<Main::Session*> _session;
const Fn<void(not_null<DocumentData*>)> _unavailableEmojiPasted;
const Fn<bool(not_null<DocumentData*>)> _allowPremiumEmoji;
};
FieldTagMimeProcessor::FieldTagMimeProcessor(
not_null<Main::Session*> session,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted)
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji)
: _session(session)
, _unavailableEmojiPasted(unavailableEmojiPasted) {
, _allowPremiumEmoji(allowPremiumEmoji) {
}
QString FieldTagMimeProcessor::operator()(QStringView mimeTag) {
@@ -93,19 +93,19 @@ QString FieldTagMimeProcessor::operator()(QStringView mimeTag) {
if (!_session->premium()) {
const auto document = _session->data().document(emoji.id);
if (document->isPremiumEmoji()) {
premiumSkipped = document;
i = all.erase(i);
continue;
if (!_allowPremiumEmoji
|| premiumSkipped
|| !_session->premiumPossible()
|| !_allowPremiumEmoji(document)) {
premiumSkipped = document;
i = all.erase(i);
continue;
}
}
}
}
++i;
}
if (premiumSkipped
&& _session->premiumPossible()
&& _unavailableEmojiPasted) {
_unavailableEmojiPasted(premiumSkipped);
}
return TextUtilities::JoinTag(all);
}
@@ -313,10 +313,10 @@ void InitMessageFieldHandlers(
std::shared_ptr<Ui::Show> show,
not_null<Ui::InputField*> field,
Fn<bool()> customEmojiPaused,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji,
const style::InputField *fieldStyle) {
field->setTagMimeProcessor(
FieldTagMimeProcessor(session, unavailableEmojiPasted));
FieldTagMimeProcessor(session, allowPremiumEmoji));
field->setCustomEmojiFactory([=](QStringView data, Fn<void()> update) {
return session->data().customEmojiManager().create(
data,
@@ -337,13 +337,13 @@ void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Window::GifPauseReason pauseReasonLevel,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted) {
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji) {
InitMessageFieldHandlers(
&controller->session(),
std::make_shared<Window::Show>(controller),
field,
[=] { return controller->isGifPausedAtLeastFor(pauseReasonLevel); },
unavailableEmojiPasted);
allowPremiumEmoji);
}
void InitMessageFieldGeometry(not_null<Ui::InputField*> field) {
@@ -358,12 +358,12 @@ void InitMessageFieldGeometry(not_null<Ui::InputField*> field) {
void InitMessageField(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted) {
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji) {
InitMessageFieldHandlers(
controller,
field,
Window::GifPauseReason::Any,
unavailableEmojiPasted);
allowPremiumEmoji);
InitMessageFieldGeometry(field);
field->customTab(true);
}

View File

@@ -49,17 +49,17 @@ void InitMessageFieldHandlers(
std::shared_ptr<Ui::Show> show,
not_null<Ui::InputField*> field,
Fn<bool()> customEmojiPaused,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted = nullptr,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji = nullptr,
const style::InputField *fieldStyle = nullptr);
void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Window::GifPauseReason pauseReasonLevel,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted = nullptr);
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji = nullptr);
void InitMessageField(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Fn<void(not_null<DocumentData*>)> unavailableEmojiPasted);
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
void InitSpellchecker(
std::shared_ptr<Ui::Show> show,

View File

@@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "data/data_changes.h"
#include "data/stickers/data_stickers.h"
#include "data/stickers/data_custom_emoji.h" // AllowEmojiWithoutPremium.
#include "lang/lang_keys.h"
#include "mainwindow.h"
#include "apiwrap.h"
@@ -839,6 +840,8 @@ void TabbedSelector::setCurrentPeer(PeerData *peer) {
if (hasStickersTab()) {
stickers()->showMegagroupSet(peer ? peer->asMegagroup() : nullptr);
}
setAllowEmojiWithoutPremium(
peer && Data::AllowEmojiWithoutPremium(peer));
}
void TabbedSelector::checkRestrictedPeer() {
@@ -924,6 +927,15 @@ void TabbedSelector::setRoundRadius(int radius) {
}
}
void TabbedSelector::setAllowEmojiWithoutPremium(bool allow) {
for (const auto &tab : _tabs) {
if (tab.type() == SelectorTab::Emoji) {
const auto emoji = static_cast<EmojiListWidget*>(tab.widget());
emoji->setAllowWithoutPremium(allow);
}
}
}
void TabbedSelector::createTabsSlider() {
_tabsSlider.create(this, st::emojiTabs);

View File

@@ -98,6 +98,7 @@ public:
rpl::producer<> contextMenuRequested() const;
rpl::producer<Action> choosingStickerUpdated() const;
void setAllowEmojiWithoutPremium(bool allow);
void setRoundRadius(int radius);
void refreshStickers();
void setCurrentPeer(PeerData *peer);