diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 5525e3a0c7..f89933de5b 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -796,26 +796,24 @@ void EmojiListWidget::fillRecentFrom(const std::vector &list) { } } -void EmojiListWidget::fillContextMenu( - not_null menu, +base::unique_qptr EmojiListWidget::fillContextMenu( SendMenu::Type type) { - if (v::is_null(_selected)) { - return; + if (_mode != Mode::EmojiStatus || v::is_null(_selected)) { + return nullptr; } const auto over = std::get_if(&_selected); if (!over) { - return; + return nullptr; } const auto section = over->section; const auto index = over->index; - // Ignore the default status. - if (!index && (section == int(Section::Recent))) { - return; - } const auto chosen = lookupCustomEmoji(index, section); if (!chosen) { - return; + return nullptr; } + auto menu = base::make_unique_q( + this, + st::defaultPopupMenu); for (const auto &value : { 3600, 3600 * 8, 3600 * 24, 3600 * 24 * 7 }) { const auto text = tr::lng_emoji_status_menu_duration_any( tr::now, @@ -833,6 +831,7 @@ void EmojiListWidget::fillContextMenu( menu->addAction( tr::lng_manage_messages_ttl_after_custom(tr::now), crl::guard(this, [=] { selectCustom(chosen, options); })); + return menu; } void EmojiListWidget::paintEvent(QPaintEvent *e) { @@ -1094,8 +1093,7 @@ bool EmojiListWidget::checkPickerHide() { DocumentData *EmojiListWidget::lookupCustomEmoji( int index, int section) const { - if (section == int(Section::Recent) - && index < _recent.size()) { + if (section == int(Section::Recent) && index < _recent.size()) { const auto document = std::get_if( &_recent[index].id.data); const auto custom = document diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h index bf4c217c28..af17b130cf 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h @@ -126,8 +126,7 @@ public: float64 progress, RectPart origin); - void fillContextMenu( - not_null menu, + base::unique_qptr fillContextMenu( SendMenu::Type type) override; protected: diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 56a83763e7..5754fb5e0c 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -376,13 +376,15 @@ void GifsListWidget::mousePressEvent(QMouseEvent *e) { _previewTimer.callOnce(QApplication::startDragTime()); } -void GifsListWidget::fillContextMenu( - not_null menu, +base::unique_qptr GifsListWidget::fillContextMenu( SendMenu::Type type) { if (_selected < 0 || _pressed >= 0) { - return; + return nullptr; } + auto menu = base::make_unique_q( + this, + st::popupMenuWithIcons); const auto send = [=, selected = _selected](Api::SendOptions options) { selectInlineResult(selected, options, true); }; @@ -405,7 +407,8 @@ void GifsListWidget::fillContextMenu( }; AddGifAction(std::move(callback), _controller, document); } - }; + } + return menu; } 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 284ecfbd73..af0163cf4d 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -82,8 +82,7 @@ public: void cancelled(); rpl::producer<> cancelRequests() const; - void fillContextMenu( - not_null menu, + base::unique_qptr fillContextMenu( SendMenu::Type type) override; ~GifsListWidget(); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 2e0b1cd655..29b0686c18 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1542,65 +1542,71 @@ void StickersListWidget::showStickerSetBox(not_null document) { } } -void StickersListWidget::fillContextMenu( - not_null menu, +base::unique_qptr StickersListWidget::fillContextMenu( SendMenu::Type type) { auto selected = _selected; auto &sets = shownSets(); if (v::is_null(selected) || !v::is_null(_pressed)) { - return; + return nullptr; } - if (auto sticker = std::get_if(&selected)) { - const auto section = sticker->section; - const auto index = sticker->index; - Assert(section >= 0 && section < sets.size()); - auto &set = sets[section]; - Assert(index >= 0 && index < set.stickers.size()); + const auto sticker = std::get_if(&selected); + if (!sticker) { + return nullptr; + } + const auto section = sticker->section; + const auto index = sticker->index; + Assert(section >= 0 && section < sets.size()); + auto &set = sets[section]; + Assert(index >= 0 && index < set.stickers.size()); - const auto document = set.stickers[sticker->index].document; - const auto send = [=](Api::SendOptions options) { - _chosen.fire({ - .document = document, - .options = options, - .messageSendingFrom = options.scheduled - ? Ui::MessageSendingAnimationFrom() - : messageSentAnimationInfo(section, index, document), - }); - }; - SendMenu::FillSendMenu( - menu, - type, - SendMenu::DefaultSilentCallback(send), - SendMenu::DefaultScheduleCallback(this, type, send)); + auto menu = base::make_unique_q( + this, + st::popupMenuWithIcons); - const auto window = _controller; - const auto toggleFavedSticker = [=] { - Api::ToggleFavedSticker( - window, + const auto document = set.stickers[sticker->index].document; + const auto send = [=](Api::SendOptions options) { + _chosen.fire({ + .document = document, + .options = options, + .messageSendingFrom = options.scheduled + ? Ui::MessageSendingAnimationFrom() + : messageSentAnimationInfo(section, index, document), + }); + }; + SendMenu::FillSendMenu( + menu, + type, + SendMenu::DefaultSilentCallback(send), + SendMenu::DefaultScheduleCallback(this, type, send)); + + const auto window = _controller; + const auto toggleFavedSticker = [=] { + Api::ToggleFavedSticker( + window, + document, + Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0)); + }; + const auto isFaved = document->owner().stickers().isFaved(document); + menu->addAction( + (isFaved + ? tr::lng_faved_stickers_remove + : tr::lng_faved_stickers_add)(tr::now), + toggleFavedSticker, + isFaved ? &st::menuIconUnfave : &st::menuIconFave); + + menu->addAction(tr::lng_context_pack_info(tr::now), [=] { + showStickerSetBox(document); + }, &st::menuIconStickers); + + if (const auto id = set.id; id == Data::Stickers::RecentSetId) { + menu->addAction(tr::lng_recent_stickers_remove(tr::now), [=] { + Api::ToggleRecentSticker( document, - Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0)); - }; - const auto isFaved = document->owner().stickers().isFaved(document); - menu->addAction( - (isFaved - ? tr::lng_faved_stickers_remove - : tr::lng_faved_stickers_add)(tr::now), - toggleFavedSticker, - isFaved ? &st::menuIconUnfave : &st::menuIconFave); - - menu->addAction(tr::lng_context_pack_info(tr::now), [=] { - showStickerSetBox(document); - }, &st::menuIconStickers); - - if (const auto id = set.id; id == Data::Stickers::RecentSetId) { - menu->addAction(tr::lng_recent_stickers_remove(tr::now), [=] { - Api::ToggleRecentSticker( - document, - Data::FileOriginStickerSet(id, 0), - false); - }, &st::menuIconDelete); - } + Data::FileOriginStickerSet(id, 0), + false); + }, &st::menuIconDelete); } + return menu; } Ui::MessageSendingAnimationFrom StickersListWidget::messageSentAnimationInfo( diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 8931c2c2b9..46dca8b8c4 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -91,8 +91,7 @@ public: std::shared_ptr getLottieRenderer(); - void fillContextMenu( - not_null menu, + base::unique_qptr fillContextMenu( SendMenu::Type type) override; bool mySetsEmpty() const; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 06b89693a4..8db92311d0 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -1145,12 +1145,8 @@ void TabbedSelector::scrollToY(int y) { } void TabbedSelector::showMenuWithType(SendMenu::Type type) { - _menu = base::make_unique_q( - this, - st::popupMenuWithIcons); - currentTab()->widget()->fillContextMenu(_menu, type); - - if (!_menu->empty()) { + _menu = currentTab()->widget()->fillContextMenu(type); + if (_menu && !_menu->empty()) { _menu->popup(QCursor::pos()); } } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 10f1c7406e..9119918332 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -328,9 +328,9 @@ public: } virtual void beforeHiding() { } - virtual void fillContextMenu( - not_null menu, - SendMenu::Type type) { + [[nodiscard]] virtual base::unique_qptr fillContextMenu( + SendMenu::Type type) { + return nullptr; } rpl::producer scrollToRequests() const;