diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 7af7f12cc6..a3641fb762 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -1691,34 +1691,12 @@ object_ptr CreatePollBox::setupContent() { const auto showStickerPanel = [=]( not_null, std::shared_ptr media) { - using Selector = ChatHelpers::TabbedSelector; - using Descriptor = ChatHelpers::TabbedSelectorDescriptor; - using Mode = ChatHelpers::TabbedSelector::Mode; - using Panel = ChatHelpers::TabbedPanel; if (!state->stickerPanel) { const auto body = getDelegate()->outerContainer(); - state->stickerPanel = base::make_unique_q( + state->stickerPanel = HistoryView::CreatePollStickerPanel( body, - _controller, - object_ptr( - nullptr, - Descriptor{ - .show = _controller->uiShow(), - .st = st::backgroundEmojiPan, - .level = Window::GifPauseReason::Layer, - .mode = Mode::StickersOnly, - .features = { - .megagroupSet = false, - .stickersSettings = false, - .openStickerSets = false, - }, - })); + _controller); state->stickerPanel->setDropDown(true); - state->stickerPanel->setDesiredHeightValues( - 0., - st::emojiPanMinHeight, - st::emojiPanMinHeight); - state->stickerPanel->hide(); base::install_event_filter( body, [=](not_null event) { @@ -2221,57 +2199,17 @@ object_ptr CreatePollBox::setupContent() { std::shared_ptr media, bool allowDocuments = false, bool allowStickers = true) { - if (media->uploading) { - clearMedia(media); - return; - } - const auto document = media->media.document; - const auto photo = media->media.photo; - const auto remove = [=] { clearMedia(media); }; - if (document && document->sticker()) { - HistoryView::ShowPollStickerPreview( - _controller, - document, - [=] { showStickerPanel(button, media); }, - remove); - return; - } else if (photo) { - HistoryView::ShowPollPhotoPreview( - _controller, - photo, - [=] { choosePhotoOrVideo(media); }, - [=] { - HistoryView::EditPollPhoto( - _controller, - photo, - crl::guard(this, [=](Ui::PreparedList list) { - applyPreparedPhotoList( - media, - std::move(list)); - })); - }, - remove); - return; - } else if (document && document->isVideoFile()) { - HistoryView::ShowPollDocumentPreview( - _controller, - document, - [=] { choosePhotoOrVideo(media); }, - remove); - return; - } else if (document) { - HistoryView::ShowPollDocumentPreview( - _controller, - document, - [=] { chooseDocument(media); }, - remove); - return; - } else if (media->media.geo) { - HistoryView::ShowPollGeoPreview( - _controller, - *media->media.geo, - nullptr, - remove); + if (HistoryView::ShowPollMediaPreview(_controller, media, { + .choosePhotoOrVideo = [=] { choosePhotoOrVideo(media); }, + .chooseDocument = [=] { chooseDocument(media); }, + .chooseSticker = [=] { + showStickerPanel(button, media); + }, + .editPhoto = crl::guard(this, [=](Ui::PreparedList list) { + applyPreparedPhotoList(media, std::move(list)); + }), + .remove = [=] { clearMedia(media); }, + })) { return; } state->mediaMenu = base::make_unique_q( diff --git a/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.cpp b/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.cpp index 95b9381056..025718f5a3 100644 --- a/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.cpp +++ b/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.cpp @@ -30,9 +30,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "layout/layout_document_generic_preview.h" #include "main/main_session.h" +#include "poll/poll_media_upload.h" #include "mainwidget.h" #include "storage/localimageloader.h" #include "storage/storage_media_prepare.h" +#include "chat_helpers/tabbed_panel.h" +#include "chat_helpers/tabbed_selector.h" #include "ui/chat/attach/attach_prepare.h" #include "ui/painter.h" #include "ui/rect.h" @@ -600,4 +603,89 @@ void EditPollPhoto( Ui::LayerOption::KeepOther); } +bool ShowPollMediaPreview( + not_null controller, + const std::shared_ptr &media, + PollMediaActions actions) { + if (media->uploading) { + actions.remove(); + return true; + } + const auto document = media->media.document; + const auto photo = media->media.photo; + if (document && document->sticker()) { + ShowPollStickerPreview( + controller, + document, + std::move(actions.chooseSticker), + std::move(actions.remove)); + return true; + } else if (photo) { + ShowPollPhotoPreview( + controller, + photo, + std::move(actions.choosePhotoOrVideo), + [controller, photo, editPhoto = std::move(actions.editPhoto)] { + EditPollPhoto( + controller, + photo, + std::move(editPhoto)); + }, + std::move(actions.remove)); + return true; + } else if (document && document->isVideoFile()) { + ShowPollDocumentPreview( + controller, + document, + std::move(actions.choosePhotoOrVideo), + std::move(actions.remove)); + return true; + } else if (document) { + ShowPollDocumentPreview( + controller, + document, + std::move(actions.chooseDocument), + std::move(actions.remove)); + return true; + } else if (media->media.geo) { + ShowPollGeoPreview( + controller, + *media->media.geo, + nullptr, + std::move(actions.remove)); + return true; + } + return false; +} + +base::unique_qptr CreatePollStickerPanel( + not_null parent, + not_null controller) { + using Selector = ChatHelpers::TabbedSelector; + using Descriptor = ChatHelpers::TabbedSelectorDescriptor; + + auto panel = base::make_unique_q( + parent, + controller, + object_ptr( + nullptr, + Descriptor{ + .show = controller->uiShow(), + .st = st::backgroundEmojiPan, + .level = Window::GifPauseReason::Layer, + .mode = Selector::Mode::StickersOnly, + .features = { + .megagroupSet = false, + .stickersSettings = false, + .openStickerSets = false, + }, + })); + panel->setDesiredHeightValues( + 0., + st::emojiPanMinHeight, + st::emojiPanMinHeight); + panel->hide(); + return panel; +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.h b/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.h index 73ab5cc54c..8b5765c789 100644 --- a/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.h +++ b/Telegram/SourceFiles/history/view/media/menu/history_view_poll_menu.h @@ -7,14 +7,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/unique_qptr.h" + namespace Data { class LocationPoint; } // namespace Data +namespace PollMediaUpload { +struct PollMediaState; +} // namespace PollMediaUpload + struct PollData; class DocumentData; class PhotoData; +namespace ChatHelpers { +class TabbedPanel; +} // namespace ChatHelpers + namespace Ui { class DropdownMenu; struct PreparedList; @@ -26,6 +36,14 @@ class SessionController; namespace HistoryView { +struct PollMediaActions { + Fn choosePhotoOrVideo; + Fn chooseDocument; + Fn chooseSticker; + Fn editPhoto; + Fn remove; +}; + void FillPollAnswerMenu( not_null menu, not_null poll, @@ -64,4 +82,14 @@ void EditPollPhoto( not_null photo, Fn done); +[[nodiscard]] bool ShowPollMediaPreview( + not_null controller, + const std::shared_ptr &media, + PollMediaActions actions); + +[[nodiscard]] base::unique_qptr +CreatePollStickerPanel( + not_null parent, + not_null controller); + } // namespace HistoryView