mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-21 13:12:50 +02:00
fix: AyuForward crashes
This commit is contained in:
parent
aef400db0f
commit
06d8d14ad7
2 changed files with 63 additions and 64 deletions
|
@ -99,8 +99,11 @@ std::pair<QString, QString> 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<Main::Session*> session,
|
||||
|
@ -111,6 +114,10 @@ static Ui::PreparedList prepareMedia(not_null<Main::Session*> 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<Main::Session*> 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<Main::Session*> 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<ForwardState> state;
|
||||
|
||||
|
|
|
@ -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<Main::Session*> session, DocumentData *data, not_
|
|||
auto latch = std::make_shared<TimedCountDownLatch>(1);
|
||||
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||
|
||||
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<Main::Session*> session, const std::pair<not_null<Ph
|
|||
if (finalCheck()) {
|
||||
saveToFiles();
|
||||
} else {
|
||||
session->downloaderTaskFinished() | 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<Main::Session*> session, Api::MessageToSend &message) {
|
||||
|
@ -240,17 +246,19 @@ void waitForMsgSync(not_null<Main::Session*> session, const Api::SendAction &act
|
|||
auto latch = std::make_shared<TimedCountDownLatch>(1);
|
||||
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||
|
||||
|
||||
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<Main::Session*> session,
|
|||
SendMediaType type,
|
||||
TextWithTags &&caption,
|
||||
const Api::SendAction &action) {
|
||||
const auto size = group.list.files.size();
|
||||
auto latch = std::make_shared<TimedCountDownLatch>(size);
|
||||
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||
|
||||
auto groupId = std::make_shared<SendingAlbum>();
|
||||
groupId->groupId = base::RandomValue<uint64>();
|
||||
|
@ -272,27 +277,7 @@ void sendDocumentSync(not_null<Main::Session*> 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<Main::Session*> session,
|
||||
|
|
Loading…
Add table
Reference in a new issue