mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Use correct title in premium sticker toast.
This commit is contained in:
parent
73af96e9c3
commit
2f92830f6a
4 changed files with 82 additions and 7 deletions
|
@ -230,7 +230,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
"lng_limits_increase" = "Increase Limit";
|
||||
|
||||
"lng_sticker_premium_title" = "With Effects";
|
||||
"lng_sticker_premium_text" = "This pack contains premium stickers like this one.";
|
||||
"lng_sticker_premium_view" = "View";
|
||||
"lng_reaction_premium_info" = "Click on the reaction to preview the animation.";
|
||||
|
|
|
@ -12,12 +12,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/buttons.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_session.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "boxes/sticker_set_box.h"
|
||||
#include "lottie/lottie_single_player.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_chat.h"
|
||||
|
||||
namespace HistoryView {
|
||||
|
@ -36,7 +38,9 @@ StickerToast::StickerToast(
|
|||
, _destroy(std::move(destroy)) {
|
||||
}
|
||||
|
||||
StickerToast::~StickerToast() = default;
|
||||
StickerToast::~StickerToast() {
|
||||
cancelRequest();
|
||||
}
|
||||
|
||||
void StickerToast::showFor(not_null<DocumentData*> document) {
|
||||
const auto sticker = document->sticker();
|
||||
|
@ -49,11 +53,76 @@ void StickerToast::showFor(not_null<DocumentData*> document) {
|
|||
return;
|
||||
}
|
||||
strong->hideAnimated();
|
||||
} else if (_setRequestId) {
|
||||
if (_for == document) {
|
||||
return;
|
||||
}
|
||||
cancelRequest();
|
||||
}
|
||||
_for = document;
|
||||
|
||||
const auto title = lookupTitle();
|
||||
if (!title.isEmpty()) {
|
||||
showWithTitle(title);
|
||||
} else {
|
||||
requestSet();
|
||||
}
|
||||
}
|
||||
|
||||
QString StickerToast::lookupTitle() const {
|
||||
Expects(_for != nullptr);
|
||||
|
||||
const auto sticker = _for->sticker();
|
||||
if (!sticker) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto id = sticker->set.id;
|
||||
if (!id) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto &sets = _for->owner().stickers().sets();
|
||||
const auto i = sets.find(id);
|
||||
if (i == end(sets)) {
|
||||
return {};
|
||||
}
|
||||
return i->second->title;
|
||||
}
|
||||
|
||||
void StickerToast::requestSet() {
|
||||
Expects(_for != nullptr);
|
||||
|
||||
if (const auto sticker = _for->sticker()) {
|
||||
const auto api = &_controller->session().api();
|
||||
_setRequestId = api->request(MTPmessages_GetStickerSet(
|
||||
Data::InputStickerSet(sticker->set),
|
||||
MTP_int(0) // hash
|
||||
)).done([=](const MTPmessages_StickerSet &result) {
|
||||
_setRequestId = 0;
|
||||
result.match([&](const MTPDmessages_stickerSet &data) {
|
||||
data.vset().match([&](const MTPDstickerSet &data) {
|
||||
const auto owner = &_controller->session().data();
|
||||
showWithTitle(owner->stickers().getSetTitle(data));
|
||||
});
|
||||
}, [&](const MTPDmessages_stickerSetNotModified &) {
|
||||
LOG(("API Error: Got messages.stickerSetNotModified."));
|
||||
});
|
||||
}).fail([=] {
|
||||
_setRequestId = 0;
|
||||
}).send();
|
||||
}
|
||||
}
|
||||
|
||||
void StickerToast::cancelRequest() {
|
||||
_controller->session().api().request(base::take(_setRequestId)).cancel();
|
||||
}
|
||||
|
||||
void StickerToast::showWithTitle(const QString &title) {
|
||||
Expects(_for != nullptr);
|
||||
|
||||
const auto text = Ui::Text::Bold(
|
||||
tr::lng_sticker_premium_title(tr::now)
|
||||
title
|
||||
).append('\n').append(
|
||||
tr::lng_sticker_premium_text(tr::now)
|
||||
);
|
||||
|
@ -98,8 +167,8 @@ void StickerToast::showFor(not_null<DocumentData*> document) {
|
|||
preview->resize(size, size);
|
||||
preview->show();
|
||||
|
||||
const auto bytes = document->createMediaView()->bytes();
|
||||
const auto filepath = document->filepath();
|
||||
const auto bytes = _for->createMediaView()->bytes();
|
||||
const auto filepath = _for->filepath();
|
||||
const auto player = preview->lifetime().make_state<Lottie::SinglePlayer>(
|
||||
Lottie::ReadContent(bytes, filepath),
|
||||
Lottie::FrameRequest{ QSize(size, size) },
|
||||
|
@ -122,7 +191,7 @@ void StickerToast::showFor(not_null<DocumentData*> document) {
|
|||
|
||||
button->setClickedCallback([=, weak = _weak] {
|
||||
_controller->show(
|
||||
Box<StickerSetBox>(_controller, document->sticker()->set),
|
||||
Box<StickerSetBox>(_controller, _for->sticker()->set),
|
||||
Ui::LayerOption::KeepOther);
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->hideAnimated();
|
||||
|
|
|
@ -34,6 +34,11 @@ public:
|
|||
void showFor(not_null<DocumentData*> document);
|
||||
|
||||
private:
|
||||
void requestSet();
|
||||
void cancelRequest();
|
||||
void showWithTitle(const QString &title);
|
||||
[[nodiscard]] QString lookupTitle() const;
|
||||
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
const not_null<QWidget*> _parent;
|
||||
style::Toast _st;
|
||||
|
@ -41,6 +46,8 @@ private:
|
|||
DocumentData *_for = nullptr;
|
||||
Fn<void()> _destroy;
|
||||
|
||||
mtpRequestId _setRequestId = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 941dc48366268688f05f6260bf38ed717112ef1a
|
||||
Subproject commit 7aedf7703fdf24c11375b7e67c2a6d9e16b0008b
|
Loading…
Add table
Reference in a new issue