diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index e45b8d21e9..e7d1f80beb 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -533,6 +533,9 @@ void SendFilesBox::pushBlock(int from, int till) { block.takeWidget(), QMargins(0, _inner->count() ? st::sendMediaRowSkip : 0, 0, 0)); + const auto preventDelete = + widget->lifetime().make_state>(); + block.itemDeleteRequest( ) | rpl::filter([=] { return !_removingIndex; @@ -543,12 +546,19 @@ void SendFilesBox::pushBlock(int from, int till) { if (index < 0 || index >= _list.files.size()) { return; } + // Prevent item delete if it is the only one. + if (_list.files.size() == 1) { + preventDelete->fire_copy(0); + return; + } _list.files.erase(_list.files.begin() + index); refreshAllAfterChanges(from); }); }, widget->lifetime()); - block.itemReplaceRequest( + rpl::merge( + block.itemReplaceRequest(), + preventDelete->events() ) | rpl::start_with_next([=](int index) { const auto replace = [=](Ui::PreparedList list) { if (list.files.empty()) {