mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Added ability to Save / Delete GIFs from menu for inline bots.
Fixed #10511.
This commit is contained in:
parent
b373a9ed22
commit
a5abe3d813
4 changed files with 50 additions and 30 deletions
|
@ -46,19 +46,31 @@ constexpr auto kSearchBotUsername = "gif"_cs;
|
|||
|
||||
} // namespace
|
||||
|
||||
void DeleteSavedGif(not_null<DocumentData*> document) {
|
||||
auto &data = document->owner();
|
||||
Api::ToggleSavedGif(
|
||||
document,
|
||||
Data::FileOriginSavedGifs(),
|
||||
false);
|
||||
|
||||
const auto index = data.stickers().savedGifs().indexOf(document);
|
||||
if (index >= 0) {
|
||||
data.stickers().savedGifsRef().remove(index);
|
||||
document->session().local().writeSavedGifs();
|
||||
void AddGifAction(
|
||||
Fn<void(QString, Fn<void()> &&)> callback,
|
||||
not_null<DocumentData*> document) {
|
||||
if (!document->isGifv()) {
|
||||
return;
|
||||
}
|
||||
data.stickers().notifySavedGifsUpdated();
|
||||
auto &data = document->owner();
|
||||
const auto index = data.stickers().savedGifs().indexOf(document);
|
||||
const auto saved = (index >= 0);
|
||||
const auto text = (saved
|
||||
? tr::lng_context_delete_gif
|
||||
: tr::lng_context_save_gif)(tr::now);
|
||||
callback(text, [=] {
|
||||
Api::ToggleSavedGif(
|
||||
document,
|
||||
Data::FileOriginSavedGifs(),
|
||||
!saved);
|
||||
|
||||
auto &data = document->owner();
|
||||
if (saved) {
|
||||
data.stickers().savedGifsRef().remove(index);
|
||||
document->session().local().writeSavedGifs();
|
||||
}
|
||||
data.stickers().notifySavedGifsUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
class GifsListWidget::Footer : public TabbedSelector::InnerFooter {
|
||||
|
@ -381,23 +393,18 @@ void GifsListWidget::fillContextMenu(
|
|||
SendMenu::DefaultSilentCallback(send),
|
||||
SendMenu::DefaultScheduleCallback(this, type, send));
|
||||
|
||||
[&] {
|
||||
const auto row = _selected / MatrixRowShift;
|
||||
const auto column = _selected % MatrixRowShift;
|
||||
if (row >= _rows.size() || column >= _rows[row].items.size()) {
|
||||
return;
|
||||
}
|
||||
if (!(row >= _rows.size() || column >= _rows[row].items.size())) {
|
||||
const auto item = _rows[row].items[column];
|
||||
if (const auto document = item->getDocument()) {
|
||||
auto &data = document->owner();
|
||||
if (data.stickers().savedGifs().indexOf(document) < 0) {
|
||||
return;
|
||||
}
|
||||
menu->addAction(tr::lng_context_delete_gif(tr::now), [=] {
|
||||
ChatHelpers::DeleteSavedGif(document);
|
||||
});
|
||||
const auto document = item->getDocument()
|
||||
? item->getDocument() // Saved GIF.
|
||||
: item->getPreviewDocument(); // Searched GIF.
|
||||
if (document) {
|
||||
auto callback = [&](const QString &text, Fn<void()> &&done) {
|
||||
menu->addAction(text, std::move(done));
|
||||
};
|
||||
AddGifAction(std::move(callback), document);
|
||||
}
|
||||
}();
|
||||
};
|
||||
}
|
||||
|
||||
void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||
|
|
|
@ -40,7 +40,9 @@ enum class Type;
|
|||
|
||||
namespace ChatHelpers {
|
||||
|
||||
void DeleteSavedGif(not_null<DocumentData*> document);
|
||||
void AddGifAction(
|
||||
Fn<void(QString, Fn<void()> &&)> callback,
|
||||
not_null<DocumentData*> document);
|
||||
|
||||
class GifsListWidget
|
||||
: public TabbedSelector::Inner
|
||||
|
|
|
@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_photo_media.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/stickers/data_stickers.h"
|
||||
#include "chat_helpers/gifs_list_widget.h" // ChatHelpers::DeleteSavedGif
|
||||
#include "chat_helpers/gifs_list_widget.h" // ChatHelpers::AddGifAction
|
||||
#include "chat_helpers/stickers_lottie.h"
|
||||
#include "inline_bots/inline_bot_result.h"
|
||||
#include "lottie/lottie_single_player.h"
|
||||
|
@ -127,7 +127,9 @@ void Gif::setPosition(int32 position) {
|
|||
}
|
||||
|
||||
void DeleteSavedGifClickHandler::onClickImpl() const {
|
||||
ChatHelpers::DeleteSavedGif(_data);
|
||||
ChatHelpers::AddGifAction(
|
||||
[](QString, Fn<void()> &&done) { done(); },
|
||||
_data);
|
||||
}
|
||||
|
||||
int Gif::resizeGetHeight(int width) {
|
||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "inline_bots/inline_results_inner.h"
|
||||
|
||||
#include "api/api_common.h"
|
||||
#include "chat_helpers/gifs_list_widget.h" // ChatHelpers::AddGifAction
|
||||
#include "chat_helpers/send_context_menu.h" // SendMenu::FillSendMenu
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_user.h"
|
||||
|
@ -305,6 +306,14 @@ void Inner::contextMenuEvent(QContextMenuEvent *e) {
|
|||
SendMenu::DefaultSilentCallback(send),
|
||||
SendMenu::DefaultScheduleCallback(this, type, send));
|
||||
|
||||
auto item = _rows[row].items[column];
|
||||
if (const auto previewDocument = item->getPreviewDocument()) {
|
||||
auto callback = [&](const QString &text, Fn<void()> &&done) {
|
||||
_menu->addAction(text, std::move(done));
|
||||
};
|
||||
ChatHelpers::AddGifAction(std::move(callback), previewDocument);
|
||||
}
|
||||
|
||||
if (!_menu->empty()) {
|
||||
_menu->popup(QCursor::pos());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue