mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Moved request for attached stickers to separate file.
This commit is contained in:
parent
98afc99a8f
commit
1459e6f38e
9 changed files with 122 additions and 48 deletions
|
@ -157,6 +157,8 @@ nice_target_sources(Telegram ${src_loc}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${style_files}
|
${style_files}
|
||||||
|
|
||||||
|
api/api_attached_stickers.cpp
|
||||||
|
api/api_attached_stickers.h
|
||||||
api/api_authorizations.cpp
|
api/api_authorizations.cpp
|
||||||
api/api_authorizations.h
|
api/api_authorizations.h
|
||||||
api/api_bot.cpp
|
api/api_bot.cpp
|
||||||
|
|
64
Telegram/SourceFiles/api/api_attached_stickers.cpp
Normal file
64
Telegram/SourceFiles/api/api_attached_stickers.cpp
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
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"
|
||||||
|
#include "boxes/confirm_box.h"
|
||||||
|
#include "boxes/sticker_set_box.h"
|
||||||
|
#include "boxes/stickers_box.h"
|
||||||
|
#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()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void AttachedStickers::requestAttachedStickerSets(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<PhotoData*> photo) {
|
||||||
|
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) {
|
||||||
|
_requestId = 0;
|
||||||
|
const auto strongController = weak.get();
|
||||||
|
if (!strongController) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result.v.isEmpty()) {
|
||||||
|
Ui::show(Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
||||||
|
return;
|
||||||
|
} else if (result.v.size() > 1) {
|
||||||
|
Ui::show(Box<StickersBox>(strongController, result));
|
||||||
|
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)
|
||||||
|
? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash())
|
||||||
|
: MTP_inputStickerSetShortName(setData->vshort_name());
|
||||||
|
Ui::show(
|
||||||
|
Box<StickerSetBox>(strongController, setId),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
_requestId = 0;
|
||||||
|
Ui::show(Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Api
|
35
Telegram/SourceFiles/api/api_attached_stickers.h
Normal file
35
Telegram/SourceFiles/api/api_attached_stickers.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mtproto/sender.h"
|
||||||
|
|
||||||
|
class ApiWrap;
|
||||||
|
class PhotoData;
|
||||||
|
|
||||||
|
namespace Window {
|
||||||
|
class SessionController;
|
||||||
|
} // namespace Window
|
||||||
|
|
||||||
|
namespace Api {
|
||||||
|
|
||||||
|
class AttachedStickers final {
|
||||||
|
public:
|
||||||
|
explicit AttachedStickers(not_null<ApiWrap*> api);
|
||||||
|
|
||||||
|
void requestAttachedStickerSets(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<PhotoData*> photo);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MTP::Sender _api;
|
||||||
|
mtpRequestId _requestId = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Api
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
|
||||||
#include "api/api_authorizations.h"
|
#include "api/api_authorizations.h"
|
||||||
|
#include "api/api_attached_stickers.h"
|
||||||
#include "api/api_hash.h"
|
#include "api/api_hash.h"
|
||||||
#include "api/api_media.h"
|
#include "api/api_media.h"
|
||||||
#include "api/api_sending.h"
|
#include "api/api_sending.h"
|
||||||
|
@ -188,6 +189,7 @@ ApiWrap::ApiWrap(not_null<Main::Session*> session)
|
||||||
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
||||||
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); })
|
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); })
|
||||||
, _authorizations(std::make_unique<Api::Authorizations>(this))
|
, _authorizations(std::make_unique<Api::Authorizations>(this))
|
||||||
|
, _attachedStickers(std::make_unique<Api::AttachedStickers>(this))
|
||||||
, _selfDestruct(std::make_unique<Api::SelfDestruct>(this))
|
, _selfDestruct(std::make_unique<Api::SelfDestruct>(this))
|
||||||
, _sensitiveContent(std::make_unique<Api::SensitiveContent>(this))
|
, _sensitiveContent(std::make_unique<Api::SensitiveContent>(this))
|
||||||
, _globalPrivacy(std::make_unique<Api::GlobalPrivacy>(this)) {
|
, _globalPrivacy(std::make_unique<Api::GlobalPrivacy>(this)) {
|
||||||
|
@ -5227,6 +5229,10 @@ Api::Authorizations &ApiWrap::authorizations() {
|
||||||
return *_authorizations;
|
return *_authorizations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Api::AttachedStickers &ApiWrap::attachedStickers() {
|
||||||
|
return *_attachedStickers;
|
||||||
|
}
|
||||||
|
|
||||||
Api::SelfDestruct &ApiWrap::selfDestruct() {
|
Api::SelfDestruct &ApiWrap::selfDestruct() {
|
||||||
return *_selfDestruct;
|
return *_selfDestruct;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace Api {
|
||||||
|
|
||||||
class Updates;
|
class Updates;
|
||||||
class Authorizations;
|
class Authorizations;
|
||||||
|
class AttachedStickers;
|
||||||
class SelfDestruct;
|
class SelfDestruct;
|
||||||
class SensitiveContent;
|
class SensitiveContent;
|
||||||
class GlobalPrivacy;
|
class GlobalPrivacy;
|
||||||
|
@ -455,6 +456,7 @@ public:
|
||||||
rpl::producer<BlockedPeersSlice> blockedPeersSlice();
|
rpl::producer<BlockedPeersSlice> blockedPeersSlice();
|
||||||
|
|
||||||
[[nodiscard]] Api::Authorizations &authorizations();
|
[[nodiscard]] Api::Authorizations &authorizations();
|
||||||
|
[[nodiscard]] Api::AttachedStickers &attachedStickers();
|
||||||
[[nodiscard]] Api::SelfDestruct &selfDestruct();
|
[[nodiscard]] Api::SelfDestruct &selfDestruct();
|
||||||
[[nodiscard]] Api::SensitiveContent &sensitiveContent();
|
[[nodiscard]] Api::SensitiveContent &sensitiveContent();
|
||||||
[[nodiscard]] Api::GlobalPrivacy &globalPrivacy();
|
[[nodiscard]] Api::GlobalPrivacy &globalPrivacy();
|
||||||
|
@ -818,6 +820,7 @@ private:
|
||||||
rpl::event_stream<BlockedPeersSlice> _blockedPeersChanges;
|
rpl::event_stream<BlockedPeersSlice> _blockedPeersChanges;
|
||||||
|
|
||||||
const std::unique_ptr<Api::Authorizations> _authorizations;
|
const std::unique_ptr<Api::Authorizations> _authorizations;
|
||||||
|
const std::unique_ptr<Api::AttachedStickers> _attachedStickers;
|
||||||
const std::unique_ptr<Api::SelfDestruct> _selfDestruct;
|
const std::unique_ptr<Api::SelfDestruct> _selfDestruct;
|
||||||
const std::unique_ptr<Api::SensitiveContent> _sensitiveContent;
|
const std::unique_ptr<Api::SensitiveContent> _sensitiveContent;
|
||||||
const std::unique_ptr<Api::GlobalPrivacy> _globalPrivacy;
|
const std::unique_ptr<Api::GlobalPrivacy> _globalPrivacy;
|
||||||
|
|
|
@ -45,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session_settings.h"
|
#include "main/main_session_settings.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_attached_stickers.h"
|
||||||
#include "api/api_toggling_media.h"
|
#include "api/api_toggling_media.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -1590,7 +1591,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
});
|
});
|
||||||
if (photo->hasSticker) {
|
if (photo->hasSticker) {
|
||||||
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
|
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
|
||||||
controller->requestAttachedStickerSets(photo);
|
session->api().attachedStickers().requestAttachedStickerSets(
|
||||||
|
controller,
|
||||||
|
photo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "media/view/media_view_overlay_widget.h"
|
#include "media/view/media_view_overlay_widget.h"
|
||||||
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_attached_stickers.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
@ -1545,15 +1546,16 @@ void OverlayWidget::onCopy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::onAttachedStickers() {
|
void OverlayWidget::onAttachedStickers() {
|
||||||
const auto session = _session;
|
if (!_session || !_photo) {
|
||||||
if (!session || !_photo) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto &active = _session->windows();
|
const auto &active = _session->windows();
|
||||||
if (active.empty()) {
|
if (active.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
active.front()->requestAttachedStickerSets(_photo);
|
_session->api().attachedStickers().requestAttachedStickerSets(
|
||||||
|
active.front(),
|
||||||
|
_photo);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_chat_filters.h"
|
#include "data/data_chat_filters.h"
|
||||||
#include "data/data_photo.h" // requestAttachedStickerSets.
|
|
||||||
#include "passport/passport_form_controller.h"
|
#include "passport/passport_form_controller.h"
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
#include "core/shortcuts.h"
|
#include "core/shortcuts.h"
|
||||||
|
@ -40,10 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/delayed_activation.h"
|
#include "ui/delayed_activation.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include "boxes/calendar_box.h"
|
#include "boxes/calendar_box.h"
|
||||||
#include "boxes/sticker_set_box.h" // requestAttachedStickerSets.
|
#include "boxes/confirm_box.h"
|
||||||
#include "boxes/confirm_box.h" // requestAttachedStickerSets.
|
|
||||||
#include "boxes/stickers_box.h" // requestAttachedStickerSets.
|
|
||||||
#include "lang/lang_keys.h" // requestAttachedStickerSets.
|
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -545,36 +541,6 @@ rpl::producer<> SessionController::filtersMenuChanged() const {
|
||||||
return _filtersMenuChanged.events();
|
return _filtersMenuChanged.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionController::requestAttachedStickerSets(
|
|
||||||
not_null<PhotoData*> photo) {
|
|
||||||
session().api().request(_attachedStickerSetsRequestId).cancel();
|
|
||||||
_attachedStickerSetsRequestId = session().api().request(
|
|
||||||
MTPmessages_GetAttachedStickers(
|
|
||||||
MTP_inputStickeredMediaPhoto(photo->mtpInput())
|
|
||||||
)).done([=](const MTPVector<MTPStickerSetCovered> &result) {
|
|
||||||
if (result.v.isEmpty()) {
|
|
||||||
Ui::show(Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
|
||||||
return;
|
|
||||||
} else if (result.v.size() > 1) {
|
|
||||||
Ui::show(Box<StickersBox>(this, result));
|
|
||||||
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)
|
|
||||||
? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash())
|
|
||||||
: MTP_inputStickerSetShortName(setData->vshort_name());
|
|
||||||
Ui::show(Box<StickerSetBox>(this, setId), Ui::LayerOption::KeepOther);
|
|
||||||
}).fail([=](const RPCError &error) {
|
|
||||||
Ui::show(Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
|
||||||
}).send();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionController::checkOpenedFilter() {
|
void SessionController::checkOpenedFilter() {
|
||||||
if (const auto filterId = activeChatsFilterCurrent()) {
|
if (const auto filterId = activeChatsFilterCurrent()) {
|
||||||
const auto &list = session().data().chatsFilters().list();
|
const auto &list = session().data().chatsFilters().list();
|
||||||
|
@ -1132,8 +1098,6 @@ void SessionController::setActiveChatsFilter(FilterId id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionController::~SessionController() {
|
SessionController::~SessionController() = default;
|
||||||
session().api().request(_attachedStickerSetsRequestId).cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
|
@ -230,6 +230,7 @@ public:
|
||||||
SessionController(
|
SessionController(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
not_null<Controller*> window);
|
not_null<Controller*> window);
|
||||||
|
~SessionController();
|
||||||
|
|
||||||
[[nodiscard]] Controller &window() const {
|
[[nodiscard]] Controller &window() const {
|
||||||
return *_window;
|
return *_window;
|
||||||
|
@ -348,14 +349,10 @@ public:
|
||||||
void toggleFiltersMenu(bool enabled);
|
void toggleFiltersMenu(bool enabled);
|
||||||
[[nodiscard]] rpl::producer<> filtersMenuChanged() const;
|
[[nodiscard]] rpl::producer<> filtersMenuChanged() const;
|
||||||
|
|
||||||
void requestAttachedStickerSets(not_null<PhotoData*> photo);
|
|
||||||
|
|
||||||
rpl::lifetime &lifetime() {
|
rpl::lifetime &lifetime() {
|
||||||
return _lifetime;
|
return _lifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
~SessionController();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void initSupportMode();
|
void initSupportMode();
|
||||||
|
@ -408,8 +405,6 @@ private:
|
||||||
|
|
||||||
rpl::event_stream<> _filtersMenuChanged;
|
rpl::event_stream<> _filtersMenuChanged;
|
||||||
|
|
||||||
mtpRequestId _attachedStickerSetsRequestId = 0;
|
|
||||||
|
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue