Added ability to see attached stickers on documents.

Fixed #8927.
This commit is contained in:
23rd 2020-10-30 04:07:04 +03:00
parent 391ec8ac28
commit 665e322fce
7 changed files with 76 additions and 10 deletions

View File

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/confirm_box.h"
#include "boxes/sticker_set_box.h"
#include "boxes/stickers_box.h"
#include "data/data_document.h"
#include "data/data_photo.h"
#include "lang/lang_keys.h"
#include "window/window_session_controller.h"
@ -21,15 +22,14 @@ AttachedStickers::AttachedStickers(not_null<ApiWrap*> api)
: _api(&api->instance()) {
}
void AttachedStickers::requestAttachedStickerSets(
void AttachedStickers::request(
not_null<Window::SessionController*> controller,
not_null<PhotoData*> photo) {
MTPmessages_GetAttachedStickers &&mtpRequest) {
const auto weak = base::make_weak(controller.get());
_api.request(_requestId).cancel();
_requestId = _api.request(
MTPmessages_GetAttachedStickers(
MTP_inputStickeredMediaPhoto(photo->mtpInput())
)).done([=](const MTPVector<MTPStickerSetCovered> &result) {
std::move(mtpRequest)
).done([=](const MTPVector<MTPStickerSetCovered> &result) {
_requestId = 0;
const auto strongController = weak.get();
if (!strongController) {
@ -61,4 +61,22 @@ void AttachedStickers::requestAttachedStickerSets(
}).send();
}
void AttachedStickers::requestAttachedStickerSets(
not_null<Window::SessionController*> controller,
not_null<PhotoData*> photo) {
request(
controller,
MTPmessages_GetAttachedStickers(
MTP_inputStickeredMediaPhoto(photo->mtpInput())));
}
void AttachedStickers::requestAttachedStickerSets(
not_null<Window::SessionController*> controller,
not_null<DocumentData*> document) {
request(
controller,
MTPmessages_GetAttachedStickers(
MTP_inputStickeredMediaDocument(document->mtpInput())));
}
} // namespace Api

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/sender.h"
class ApiWrap;
class DocumentData;
class PhotoData;
namespace Window {
@ -26,7 +27,15 @@ public:
not_null<Window::SessionController*> controller,
not_null<PhotoData*> photo);
void requestAttachedStickerSets(
not_null<Window::SessionController*> controller,
not_null<DocumentData*> document);
private:
void request(
not_null<Window::SessionController*> controller,
MTPmessages_GetAttachedStickers &&mtpRequest);
MTP::Sender _api;
mtpRequestId _requestId = 0;

View File

@ -499,7 +499,9 @@ Main::Session &DocumentData::session() const {
void DocumentData::setattributes(
const QVector<MTPDocumentAttribute> &attributes) {
_flags &= ~(Flag::ImageType | kStreamingSupportedMask);
_flags &= ~(Flag::ImageType
| Flag::HasAttachedStickers
| kStreamingSupportedMask);
_flags |= kStreamingSupportedUnknown;
validateLottieSticker();
@ -577,6 +579,7 @@ void DocumentData::setattributes(
_filename = std::move(_filename).replace(ch, "_");
}
}, [&](const MTPDdocumentAttributeHasStickers &data) {
_flags |= Flag::HasAttachedStickers;
});
}
if (type == StickerDocument
@ -1539,6 +1542,10 @@ bool DocumentData::isImage() const {
return (_flags & Flag::ImageType);
}
bool DocumentData::hasAttachedStickers() const {
return (_flags & Flag::HasAttachedStickers);
}
bool DocumentData::supportsStreaming() const {
return (_flags & kStreamingSupportedMask) == kStreamingSupportedMaybeYes;
}

View File

@ -221,6 +221,8 @@ public:
[[nodiscard]] bool hasMimeType(QLatin1String mime) const;
void setMimeString(const QString &mime);
[[nodiscard]] bool hasAttachedStickers() const;
[[nodiscard]] MediaKey mediaKey() const;
[[nodiscard]] Storage::Cache::Key cacheKey() const;
[[nodiscard]] uint8 cacheTag() const;
@ -259,6 +261,7 @@ private:
ImageType = 0x08,
DownloadCancelled = 0x10,
LoadedInMediaCache = 0x20,
HasAttachedStickers = 0x40,
};
using Flags = base::flags<Flag>;
friend constexpr bool is_flag_type(Flag) { return true; };

View File

@ -1635,6 +1635,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
saveDocumentToFile(itemId, document);
}));
if (document->hasAttachedStickers()) {
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
session->api().attachedStickers().requestAttachedStickerSets(
controller,
document);
});
}
};
const auto link = ClickHandler::getActive();
auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(link.get());

View File

@ -773,8 +773,15 @@ void OverlayWidget::updateActions() {
if ((_document && documentContentShown()) || (_photo && _photoMedia->loaded())) {
_actions.push_back({ tr::lng_mediaview_copy(tr::now), SLOT(onCopy()) });
}
if (_photo && _photo->hasAttachedStickers()) {
_actions.push_back({ tr::lng_context_attached_stickers(tr::now), SLOT(onAttachedStickers()) });
if ((_photo && _photo->hasAttachedStickers())
|| (_document && _document->hasAttachedStickers())) {
auto member = _photo
? SLOT(onPhotoAttachedStickers())
: SLOT(onDocumentAttachedStickers());
_actions.push_back({
tr::lng_context_attached_stickers(tr::now),
std::move(member)
});
}
if (_canForwardItem) {
_actions.push_back({ tr::lng_mediaview_forward(tr::now), SLOT(onForward()) });
@ -1545,7 +1552,7 @@ void OverlayWidget::onCopy() {
}
}
void OverlayWidget::onAttachedStickers() {
void OverlayWidget::onPhotoAttachedStickers() {
if (!_session || !_photo) {
return;
}
@ -1559,6 +1566,20 @@ void OverlayWidget::onAttachedStickers() {
close();
}
void OverlayWidget::onDocumentAttachedStickers() {
if (!_session || !_document) {
return;
}
const auto &active = _session->windows();
if (active.empty()) {
return;
}
_session->api().attachedStickers().requestAttachedStickerSets(
active.front(),
_document);
close();
}
auto OverlayWidget::sharedMediaType() const
-> std::optional<SharedMediaType> {
using Type = SharedMediaType;

View File

@ -125,7 +125,8 @@ private slots:
void onCopy();
void onMenuDestroy(QObject *obj);
void receiveMouse();
void onAttachedStickers();
void onPhotoAttachedStickers();
void onDocumentAttachedStickers();
void onDropdown();