diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 351fe5256..17797e785 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1468,6 +1468,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_copy_text" = "Copy Text"; "lng_context_open_gif" = "Open GIF"; "lng_context_save_gif" = "Save GIF"; +"lng_context_delete_gif" = "Delete GIF"; "lng_context_attached_stickers" = "Attached Stickers"; "lng_context_to_msg" = "Go To Message"; "lng_context_reply_msg" = "Reply"; diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 10544a6ab..aacd3ddf0 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "chat_helpers/gifs_list_widget.h" -#include "api/api_common.h" +#include "apiwrap.h" // ApiWrap::toggleSavedGif #include "base/const_string.h" #include "data/data_photo.h" #include "data/data_document.h" @@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "history/view/history_view_schedule_box.h" #include "app.h" +#include "storage/storage_account.h" // Account::writeSavedGifs #include "styles/style_chat_helpers.h" #include @@ -46,6 +47,21 @@ constexpr auto kSearchBotUsername = "gif"_cs; } // namespace +void DeleteSavedGif(not_null document) { + auto &data = document->owner(); + document->session().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(); + } + data.stickers().notifySavedGifsUpdated(); +} + class GifsListWidget::Footer : public TabbedSelector::InnerFooter { public: Footer(not_null parent); @@ -373,6 +389,24 @@ void GifsListWidget::fillContextMenu( [&] { return type; }, silent, schedule); + + [&] { + const auto row = _selected / MatrixRowShift; + const auto column = _selected % MatrixRowShift; + if (row >= _rows.size() || column >= _rows[row].items.size()) { + return; + } + 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); + }); + } + }(); } void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index 8772cf2a0..9b16ff71c 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -38,6 +38,8 @@ enum class SendMenuType; namespace ChatHelpers { +void DeleteSavedGif(not_null document); + class GifsListWidget : public TabbedSelector::Inner , public InlineBots::Layout::Context diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 62ebe98d9..29fcce2e5 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -2046,6 +2046,14 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const { return myrtlrect(removeButtonRect(section)).topLeft() + st::stickerPanRemoveSet.rippleAreaPosition; } +void StickersListWidget::showStickerSetBox(not_null document) { + if (document->sticker() + && document->sticker()->set.type() != mtpc_inputStickerSetEmpty) { + _displayingSet = true; + checkHideWithBox(StickerSetBox::Show(controller(), document)); + } +} + void StickersListWidget::fillContextMenu( not_null menu, SendMenuType type) { @@ -2079,6 +2087,22 @@ void StickersListWidget::fillContextMenu( [&] { return type; }, silent, schedule); + + const auto toggleFavedSticker = [=] { + document->session().api().toggleFavedSticker( + document, + Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0), + !document->owner().stickers().isFaved(document)); + }; + menu->addAction( + (document->owner().stickers().isFaved(document) + ? tr::lng_faved_stickers_remove + : tr::lng_faved_stickers_add)(tr::now), + toggleFavedSticker); + + menu->addAction(tr::lng_context_pack_info(tr::now), [=] { + showStickerSetBox(document); + }); } } @@ -2118,13 +2142,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { } const auto document = set.stickers[sticker->index].document; if (e->modifiers() & Qt::ControlModifier) { - if (document->sticker() - && document->sticker()->set.type() != mtpc_inputStickerSetEmpty) { - _displayingSet = true; - checkHideWithBox(StickerSetBox::Show( - controller(), - document)); - } + showStickerSetBox(document); } else { _chosen.fire_copy({ .document = document }); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index e2c46a6a6..a0e6bf21e 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -303,6 +303,8 @@ private: void setColumnCount(int count); void refreshFooterIcons(); + void showStickerSetBox(not_null document); + void cancelSetsSearch(); void showSearchResults(); void searchResultsDone(const MTPmessages_FoundStickerSets &result); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index f485b0285..9b871b3b1 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -14,6 +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/stickers_lottie.h" #include "inline_bots/inline_bot_result.h" #include "lottie/lottie_single_player.h" @@ -22,10 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_instance.h" #include "history/history_location_manager.h" #include "history/view/history_view_cursor_state.h" -#include "storage/storage_account.h" #include "ui/image/image.h" #include "main/main_session.h" -#include "apiwrap.h" #include "lang/lang_keys.h" #include "app.h" #include "styles/style_overview.h" @@ -126,17 +125,7 @@ void Gif::setPosition(int32 position) { } void DeleteSavedGifClickHandler::onClickImpl() const { - _data->session().api().toggleSavedGif( - _data, - Data::FileOriginSavedGifs(), - false); - - const auto index = _data->owner().stickers().savedGifs().indexOf(_data); - if (index >= 0) { - _data->owner().stickers().savedGifsRef().remove(index); - _data->session().local().writeSavedGifs(); - } - _data->owner().stickers().notifySavedGifsUpdated(); + ChatHelpers::DeleteSavedGif(_data); } int Gif::resizeGetHeight(int width) {