diff --git a/Telegram/SourceFiles/ayu/features/forward/ayu_forward.cpp b/Telegram/SourceFiles/ayu/features/forward/ayu_forward.cpp index 92f977e308..52fbb0159b 100644 --- a/Telegram/SourceFiles/ayu/features/forward/ayu_forward.cpp +++ b/Telegram/SourceFiles/ayu/features/forward/ayu_forward.cpp @@ -99,8 +99,11 @@ std::pair stateName(const PeerId &id) { void ForwardState::updateBottomBar(const Main::Session &session, const PeerId *peer, const State &st) { state = st; - - session.changes().peerUpdated(session.data().peer(*peer), Data::PeerUpdate::Flag::Rights); + auto peerCopy = *peer; + crl::on_main([&, peerCopy] + { + session.changes().peerUpdated(session.data().peer(peerCopy), Data::PeerUpdate::Flag::Rights); + }); } static Ui::PreparedList prepareMedia(not_null session, @@ -111,6 +114,10 @@ static Ui::PreparedList prepareMedia(not_null session, { groupMedia.emplace_back(media); auto prepared = Ui::PreparedFile(AyuSync::filePath(session, media)); + if (prepared.path.isEmpty()) { + // otherwise will fail assertion in PrepareDetails + return prepared; + } Storage::PrepareDetails(prepared, st::sendMediaPreviewSize, PhotoSideLimit()); return prepared; }; @@ -120,7 +127,9 @@ static Ui::PreparedList prepareMedia(not_null session, const auto groupId = startItem->groupId(); Ui::PreparedList list; - list.files.emplace_back(prepare(media)); + if (auto prepared = prepare(media); !prepared.path.isEmpty()) { + list.files.emplace_back(std::move(prepared)); + } if (!groupId.value) { return list; @@ -132,7 +141,9 @@ static Ui::PreparedList prepareMedia(not_null session, break; } if (const auto nextMedia = nextItem->media()) { - list.files.emplace_back(prepare(nextMedia)); + if (auto prepared = prepare(nextMedia); !prepared.path.isEmpty()) { + list.files.emplace_back(std::move(prepared)); + } i = k; } } @@ -296,7 +307,10 @@ void forwardMessages( const auto history = action.history; const auto peer = history->peer; - history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {}); + crl::on_main([&] + { + history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {}); + }); std::shared_ptr state; diff --git a/Telegram/SourceFiles/ayu/features/forward/ayu_sync.cpp b/Telegram/SourceFiles/ayu/features/forward/ayu_sync.cpp index f8958c248b..d6236e766f 100644 --- a/Telegram/SourceFiles/ayu/features/forward/ayu_sync.cpp +++ b/Telegram/SourceFiles/ayu/features/forward/ayu_sync.cpp @@ -5,8 +5,9 @@ // // Copyright @Radolyn, 2025 #include "ayu_sync.h" -#include "apiwrap.h" #include "api/api_sending.h" +#include "apiwrap.h" +#include "ayu/utils/telegram_helpers.h" #include "core/application.h" #include "core/core_settings.h" #include "core/file_utilities.h" @@ -127,19 +128,22 @@ void loadDocumentSync(not_null session, DocumentData *data, not_ auto latch = std::make_shared(1); auto lifetime = std::make_shared(); - data->save(Data::FileOriginMessage(item->fullId()), filePath(session, item->media())); - - rpl::single() | rpl::then( - session->downloaderTaskFinished() - ) | rpl::filter([&] + crl::on_main([&] { - return data->status == FileDownloadFailed || fileSize(item) == data->size; - }) | rpl::start_with_next([&]() mutable - { - latch->countDown(); - base::take(lifetime)->destroy(); - }, - *lifetime); + data->save(Data::FileOriginMessage(item->fullId()), filePath(session, item->media())); + + rpl::single() | rpl::then( + session->downloaderTaskFinished() + ) | rpl::filter([&] + { + return data->status == FileDownloadFailed || fileSize(item) == data->size; + }) | rpl::start_with_next([&]() mutable + { + latch->countDown(); + base::take(lifetime)->destroy(); + }, + *lifetime); + }); latch->await(std::chrono::minutes(5)); } @@ -207,19 +211,21 @@ void loadPhotoSync(not_null session, const std::pairdownloaderTaskFinished() | rpl::filter([&] + crl::on_main([&] { - return finalCheck(); - }) | rpl::start_with_next([&]() mutable - { - saveToFiles(); - latch->countDown(); - base::take(lifetime)->destroy(); - }, - *lifetime); + session->downloaderTaskFinished() | rpl::filter([&] + { + return finalCheck(); + }) | rpl::start_with_next([&]() mutable + { + saveToFiles(); + latch->countDown(); + base::take(lifetime)->destroy(); + }, + *lifetime); + }); + latch->await(std::chrono::minutes(5)); } - - latch->await(std::chrono::minutes(5)); } void sendMessageSync(not_null session, Api::MessageToSend &message) { @@ -240,17 +246,19 @@ void waitForMsgSync(not_null session, const Api::SendAction &act auto latch = std::make_shared(1); auto lifetime = std::make_shared(); - - session->data().itemIdChanged() - | rpl::filter([&](const Data::Session::IdChange &update) - { - return action.history->peer->id == update.newId.peer; - }) | rpl::start_with_next([&] - { - latch->countDown(); - base::take(lifetime)->destroy(); - }, - *lifetime); + crl::on_main([&] + { + session->data().itemIdChanged() + | rpl::filter([&](const Data::Session::IdChange &update) + { + return action.history->peer->id == update.newId.peer; + }) | rpl::start_with_next([&] + { + latch->countDown(); + base::take(lifetime)->destroy(); + }, + *lifetime); + }); latch->await(std::chrono::minutes(2)); } @@ -260,9 +268,6 @@ void sendDocumentSync(not_null session, SendMediaType type, TextWithTags &&caption, const Api::SendAction &action) { - const auto size = group.list.files.size(); - auto latch = std::make_shared(size); - auto lifetime = std::make_shared(); auto groupId = std::make_shared(); groupId->groupId = base::RandomValue(); @@ -272,27 +277,7 @@ void sendDocumentSync(not_null session, session->api().sendFiles(std::move(lst), type, std::move(caption), groupId, action); }); - - // probably need to handle - // session->uploader().photoFailed() - // and - // session->uploader().documentFailed() - // too - - rpl::merge( - session->uploader().documentReady(), - session->uploader().photoReady() - ) | rpl::filter([&](const Storage::UploadedMedia &docOrPhoto) - { - return docOrPhoto.fullId.peer == action.history->peer->id; - }) | rpl::start_with_next([&] - { - latch->countDown(); - }, - *lifetime); - - latch->await(std::chrono::minutes(5 * size)); - base::take(lifetime)->destroy(); + waitForMsgSync(session, action); } void sendStickerSync(not_null session,