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(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_stickers_not_found()));
|
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(
|
2022-08-15 08:33:24 +00:00
|
|
|
Box<StickersBox>(strongController, result.v));
|
2020-10-29 23:43:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Single attached sticker pack.
|
2022-07-22 11:39:28 +00:00
|
|
|
const auto data = result.v.front().match([&](const auto &data) {
|
|
|
|
return &data.vset().data();
|
2020-10-29 23:43:35 +00:00
|
|
|
});
|
|
|
|
|
2022-07-22 11:39:28 +00:00
|
|
|
const auto setId = (data->vid().v && data->vaccess_hash().v)
|
2021-07-08 16:42:57 +00:00
|
|
|
? StickerSetIdentifier{
|
2022-07-22 11:39:28 +00:00
|
|
|
.id = data->vid().v,
|
|
|
|
.accessHash = data->vaccess_hash().v }
|
|
|
|
: StickerSetIdentifier{ .shortName = qs(data->vshort_name()) };
|
2021-06-13 07:37:52 +00:00
|
|
|
strongController->show(
|
2022-07-22 11:39:28 +00:00
|
|
|
Box<StickerSetBox>(
|
|
|
|
strongController,
|
|
|
|
setId,
|
|
|
|
(data->is_emojis()
|
|
|
|
? Data::StickersType::Emoji
|
|
|
|
: data->is_masks()
|
|
|
|
? Data::StickersType::Masks
|
|
|
|
: Data::StickersType::Stickers)),
|
2020-10-29 23:43:35 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2021-11-26 20:46:53 +00:00
|
|
|
}).fail([=] {
|
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(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_stickers_not_found()));
|
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
|