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

@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "editor/photo_editor_layer_widget.h"
#include "history/history_drag_area.h"
#include "history/history_item.h"
#include "history/history.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
@ -242,10 +243,12 @@ void EditCaptionBox::rebuildPreview() {
}
void EditCaptionBox::setupField() {
const auto peer = _historyItem->history()->peer;
InitMessageFieldHandlers(
_controller,
_field.get(),
Window::GifPauseReason::Layer);
Window::GifPauseReason::Layer,
[=](const auto&) { return Data::AllowEmojiWithoutPremium(peer); });
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
_field,
@ -488,6 +491,7 @@ void EditCaptionBox::setupEmojiPanel() {
st::emojiPanMinHeight / 2,
st::emojiPanMinHeight);
_emojiPanel->hide();
_emojiPanel->selector()->setCurrentPeer(_historyItem->history()->peer);
_emojiPanel->selector()->emojiChosen(
) | rpl::start_with_next([=](EmojiPtr emoji) {
Ui::InsertEmojiAtCursor(_field->textCursor(), emoji);

View File

@ -250,15 +250,16 @@ SendFilesBox::SendFilesBox(
not_null<Window::SessionController*> controller,
Ui::PreparedList &&list,
const TextWithTags &caption,
SendLimit limit,
not_null<PeerData*> peer,
Api::SendType sendType,
SendMenu::Type sendMenuType)
: _controller(controller)
, _sendType(sendType)
, _titleHeight(st::boxTitleHeight)
, _list(std::move(list))
, _sendLimit(limit)
, _sendLimit(peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many)
, _sendMenuType(sendMenuType)
, _allowEmojiWithoutPremium(Data::AllowEmojiWithoutPremium(peer))
, _caption(
this,
st::confirmCaptionArea,
@ -676,7 +677,8 @@ void SendFilesBox::setupCaption() {
InitMessageFieldHandlers(
_controller,
_caption.data(),
Window::GifPauseReason::Layer);
Window::GifPauseReason::Layer,
[=](const auto&) { return _allowEmojiWithoutPremium; });
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
_caption,
@ -730,6 +732,8 @@ void SendFilesBox::setupEmojiPanel() {
st::emojiPanMinHeight / 2,
st::emojiPanMinHeight);
_emojiPanel->hide();
_emojiPanel->selector()->setAllowEmojiWithoutPremium(
_allowEmojiWithoutPremium);
_emojiPanel->selector()->emojiChosen(
) | rpl::start_with_next([=](EmojiPtr emoji) {
Ui::InsertEmojiAtCursor(_caption->textCursor(), emoji);

View File

@ -57,7 +57,7 @@ public:
not_null<Window::SessionController*> controller,
Ui::PreparedList &&list,
const TextWithTags &caption,
SendLimit limit,
not_null<PeerData*> peer,
Api::SendType sendType,
SendMenu::Type sendMenuType);
@ -168,6 +168,7 @@ private:
SendLimit _sendLimit = SendLimit::Many;
SendMenu::Type _sendMenuType = SendMenu::Type();
bool _allowEmojiWithoutPremium = false;
Fn<void(
Ui::PreparedList &&list,

View File

@ -422,13 +422,14 @@ void StickerSetBox::updateButtons() {
if (!_controller->session().premium()
&& _controller->session().premiumPossible()
&& _inner->premiumEmojiSet()) {
setStyle(st::premiumPreviewBox);
const auto &st = st::premiumPreviewDoubledLimitsBox;
setStyle(st);
auto button = CreateUnlockButton(
this,
tr::lng_premium_unlock_emoji());
button->resizeToWidth(st::boxWideWidth
- st::premiumPreviewBox.buttonPadding.left()
- st::premiumPreviewBox.buttonPadding.left());
- st.buttonPadding.left()
- st.buttonPadding.left());
button->setClickedCallback([=] {
Settings::ShowPremium(_controller, u"animated_emoji"_q);
});

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);

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h"
#include "data/data_document_media.h"
#include "data/data_file_origin.h"
#include "data/data_peer.h"
#include "lottie/lottie_common.h"
#include "lottie/lottie_emoji.h"
#include "ffmpeg/ffmpeg_emoji.h"
@ -646,6 +647,10 @@ CustomEmojiId ParseCustomEmojiData(QStringView data) {
};
}
bool AllowEmojiWithoutPremium(not_null<PeerData*> peer) {
return peer->isSelf();
}
void InsertCustomEmoji(
not_null<Ui::InputField*> field,
not_null<DocumentData*> document) {

View File

@ -122,6 +122,8 @@ private:
not_null<DocumentData*> document);
[[nodiscard]] CustomEmojiId ParseCustomEmojiData(QStringView data);
[[nodiscard]] bool AllowEmojiWithoutPremium(not_null<PeerData*> peer);
void InsertCustomEmoji(
not_null<Ui::InputField*> field,
not_null<DocumentData*> document);

View File

@ -404,7 +404,6 @@ HistoryMessage::HistoryMessage(
const auto dropForwardInfo = (originalMedia
&& originalMedia->dropForwardedInfo())
|| (original->history()->peer->isSelf()
&& !history->peer->isSelf()
&& !original->Has<HistoryMessageForwarded>()
&& (!originalMedia || !originalMedia->forceForwardedInfo()));
if (!dropForwardInfo) {

View File

@ -396,7 +396,11 @@ HistoryWidget::HistoryWidget(
InitMessageField(controller, _field, [=](
not_null<DocumentData*> document) {
if (_peer && Data::AllowEmojiWithoutPremium(_peer)) {
return true;
}
showPremiumToast(document);
return false;
});
_keyboard->sendCommandRequests(
@ -5001,7 +5005,7 @@ bool HistoryWidget::confirmSendingFiles(
controller(),
std::move(list),
text,
_peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
_peer,
Api::SendType::Normal,
sendMenuType());
_field->setTextWithTags({});

View File

@ -1422,7 +1422,15 @@ void ComposeControls::initField() {
Ui::Connect(_field, &Ui::InputField::resized, [=] { updateHeight(); });
//Ui::Connect(_field, &Ui::InputField::focused, [=] { fieldFocused(); });
Ui::Connect(_field, &Ui::InputField::changed, [=] { fieldChanged(); });
InitMessageField(_window, _field, _unavailableEmojiPasted);
InitMessageField(_window, _field, [=](not_null<DocumentData*> emoji) {
if (_history && Data::AllowEmojiWithoutPremium(_history->peer)) {
return true;
}
if (_unavailableEmojiPasted) {
_unavailableEmojiPasted(emoji);
}
return false;
});
initAutocomplete();
const auto suggestions = Ui::Emoji::SuggestionsController::Init(
_parent,

View File

@ -747,7 +747,7 @@ bool RepliesWidget::confirmSendingFiles(
controller(),
std::move(list),
_composeControls->getTextWithAppliedMarkdown(),
_history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
_history->peer,
Api::SendType::Normal,
SendMenu::Type::SilentOnly); // #TODO replies schedule

View File

@ -195,8 +195,6 @@ private:
void clearSelected();
void setPinnedVisibility(bool shown);
void showPremiumToast(not_null<DocumentData*> document);
[[nodiscard]] Api::SendAction prepareSendAction(
Api::SendOptions options) const;
void send();

View File

@ -405,7 +405,7 @@ bool ScheduledWidget::confirmSendingFiles(
controller(),
std::move(list),
_composeControls->getTextWithAppliedMarkdown(),
_history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
_history->peer,
CanScheduleUntilOnline(_history->peer)
? Api::SendType::ScheduledToUser
: Api::SendType::Scheduled,