2020-10-29 23:43:35 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "api/api_attached_stickers.h"
|
|
|
|
|
|
|
|
#include "apiwrap.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2020-10-29 23:43:35 +00:00
|
|
|
#include "boxes/sticker_set_box.h"
|
|
|
|
#include "boxes/stickers_box.h"
|
2020-10-30 01:07:04 +00:00
|
|
|
#include "data/data_document.h"
|
2020-10-29 23:43:35 +00:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
|
|
|
|
AttachedStickers::AttachedStickers(not_null<ApiWrap*> api)
|
|
|
|
: _api(&api->instance()) {
|
|
|
|
}
|
|
|
|
|
2020-10-30 01:07:04 +00:00
|
|
|
void AttachedStickers::request(
|
2020-10-29 23:43:35 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-10-30 01:07:04 +00:00
|
|
|
MTPmessages_GetAttachedStickers &&mtpRequest) {
|
2020-10-29 23:43:35 +00:00
|
|
|
const auto weak = base::make_weak(controller.get());
|
|
|
|
_api.request(_requestId).cancel();
|
|
|
|
_requestId = _api.request(
|
2020-10-30 01:07:04 +00:00
|
|
|
std::move(mtpRequest)
|
|
|
|
).done([=](const MTPVector<MTPStickerSetCovered> &result) {
|
2020-10-29 23:43:35 +00:00
|
|
|
_requestId = 0;
|
|
|
|
const auto strongController = weak.get();
|
|
|
|
if (!strongController) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (result.v.isEmpty()) {
|
2021-06-13 07:37:52 +00:00
|
|
|
strongController->show(
|
2021-10-18 22:28:08 +00:00
|
|
|
Box<Ui::InformBox>(tr::lng_stickers_not_found(tr::now)));
|
2020-10-29 23:43:35 +00:00
|
|
|
return;
|
|
|
|
} else if (result.v.size() > 1) {
|
2021-06-13 07:37:52 +00:00
|
|
|
strongController->show(
|
|
|
|
Box<StickersBox>(strongController, result));
|
2020-10-29 23:43:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Single attached sticker pack.
|
|
|
|
const auto setData = result.v.front().match([&](const auto &data) {
|
|
|
|
return data.vset().match([&](const MTPDstickerSet &data) {
|
|
|
|
return &data;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto setId = (setData->vid().v && setData->vaccess_hash().v)
|
2021-07-08 16:42:57 +00:00
|
|
|
? StickerSetIdentifier{
|
|
|
|
.id = setData->vid().v,
|
|
|
|
.accessHash = setData->vaccess_hash().v }
|
|
|
|
: StickerSetIdentifier{ .shortName = qs(setData->vshort_name()) };
|
2021-06-13 07:37:52 +00:00
|
|
|
strongController->show(
|
2020-10-29 23:43:35 +00:00
|
|
|
Box<StickerSetBox>(strongController, setId),
|
|
|
|
Ui::LayerOption::KeepOther);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-10-29 23:43:35 +00:00
|
|
|
_requestId = 0;
|
2021-06-13 07:37:52 +00:00
|
|
|
if (const auto strongController = weak.get()) {
|
|
|
|
strongController->show(
|
2021-10-18 22:28:08 +00:00
|
|
|
Box<Ui::InformBox>(tr::lng_stickers_not_found(tr::now)));
|
2021-06-13 07:37:52 +00:00
|
|
|
}
|
2020-10-29 23:43:35 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2020-10-30 01:07:04 +00:00
|
|
|
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())));
|
|
|
|
}
|
|
|
|
|
2020-10-29 23:43:35 +00:00
|
|
|
} // namespace Api
|