From b5d3391956c113612fe3e4c643735d7e700819b4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 16 Aug 2023 13:23:06 +0200 Subject: [PATCH] Fix album part edit/delete/replace after reorder. --- Telegram/SourceFiles/boxes/send_files_box.cpp | 6 ++++++ .../ui/chat/attach/attach_album_preview.cpp | 20 ++++--------------- .../ui/chat/attach/attach_album_preview.h | 1 - 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 335582ceb..c639460ba 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -760,6 +760,8 @@ void SendFilesBox::pushBlock(int from, int till) { ) | rpl::filter([=] { return !_removingIndex; }) | rpl::start_with_next([=](int index) { + applyBlockChanges(); + _removingIndex = index; crl::on_main(this, [=] { const auto index = base::take(_removingIndex).value_or(-1); @@ -780,6 +782,8 @@ void SendFilesBox::pushBlock(int from, int till) { const auto show = uiShow(); block.itemReplaceRequest( ) | rpl::start_with_next([=](int index) { + applyBlockChanges(); + const auto replace = [=](Ui::PreparedList list) { if (list.files.empty()) { return; @@ -855,6 +859,8 @@ void SendFilesBox::pushBlock(int from, int till) { const auto openedOnce = widget->lifetime().make_state(false); block.itemModifyRequest( ) | rpl::start_with_next([=, show = _show](int index) { + applyBlockChanges(); + if (!(*openedOnce)) { show->session().settings().incrementPhotoEditorHintShown(); show->session().saveSettings(); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp index d33681b9f..34a76e274 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp @@ -142,8 +142,8 @@ void AlbumPreview::prepareThumbs(gsl::span items) { layout[i], this, [=] { update(); }, - [=] { changeThumbByIndex(thumbIndex(thumbUnderCursor())); }, - [=] { deleteThumbByIndex(thumbIndex(thumbUnderCursor())); })); + [=] { changeThumbByIndex(orderIndex(thumbUnderCursor())); }, + [=] { deleteThumbByIndex(orderIndex(thumbUnderCursor())); })); if (_thumbs.back()->isCompressedSticker()) { _hasMixedFileHeights = true; } @@ -218,8 +218,7 @@ not_null AlbumPreview::findClosestThumb( return result; } -int AlbumPreview::orderIndex( - not_null thumb) const { +int AlbumPreview::orderIndex(not_null thumb) const { const auto i = ranges::find_if(_order, [&](int index) { return (_thumbs[index].get() == thumb); }); @@ -400,17 +399,6 @@ void AlbumPreview::paintFiles(Painter &p, QRect clip) const { } } -int AlbumPreview::thumbIndex(AlbumThumbnail *thumb) { - if (!thumb) { - return -1; - } - const auto thumbIt = ranges::find_if(_thumbs, [&](auto &t) { - return t.get() == thumb; - }); - Expects(thumbIt != _thumbs.end()); - return std::distance(_thumbs.begin(), thumbIt); -} - AlbumThumbnail *AlbumPreview::thumbUnderCursor() { return findThumb(mapFromGlobal(QCursor::pos())); } @@ -439,7 +427,7 @@ void AlbumPreview::modifyThumbByIndex(int index) { void AlbumPreview::thumbButtonsCallback( not_null thumb, AttachButtonType type) { - const auto index = thumbIndex(thumb); + const auto index = orderIndex(thumb); switch (type) { case AttachButtonType::None: return; diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.h b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.h index 7811910da..11eda122f 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.h @@ -64,7 +64,6 @@ private: void updateSize(); void updateFileRows(); - int thumbIndex(AlbumThumbnail *thumb); AlbumThumbnail *thumbUnderCursor(); void deleteThumbByIndex(int index); void changeThumbByIndex(int index);