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

View File

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

View File

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

View File

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

View File

@ -773,8 +773,15 @@ void OverlayWidget::updateActions() {
if ((_document && documentContentShown()) || (_photo && _photoMedia->loaded())) { if ((_document && documentContentShown()) || (_photo && _photoMedia->loaded())) {
_actions.push_back({ tr::lng_mediaview_copy(tr::now), SLOT(onCopy()) }); _actions.push_back({ tr::lng_mediaview_copy(tr::now), SLOT(onCopy()) });
} }
if (_photo && _photo->hasAttachedStickers()) { if ((_photo && _photo->hasAttachedStickers())
_actions.push_back({ tr::lng_context_attached_stickers(tr::now), SLOT(onAttachedStickers()) }); || (_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) { if (_canForwardItem) {
_actions.push_back({ tr::lng_mediaview_forward(tr::now), SLOT(onForward()) }); _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) { if (!_session || !_photo) {
return; return;
} }
@ -1559,6 +1566,20 @@ void OverlayWidget::onAttachedStickers() {
close(); 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 auto OverlayWidget::sharedMediaType() const
-> std::optional<SharedMediaType> { -> std::optional<SharedMediaType> {
using Type = SharedMediaType; using Type = SharedMediaType;

View File

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