mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-07 20:43:12 +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) {
|
void ForwardState::updateBottomBar(const Main::Session &session, const PeerId *peer, const State &st) {
|
||||||
state = st;
|
state = st;
|
||||||
|
auto peerCopy = *peer;
|
||||||
session.changes().peerUpdated(session.data().peer(*peer), Data::PeerUpdate::Flag::Rights);
|
crl::on_main([&, peerCopy]
|
||||||
|
{
|
||||||
|
session.changes().peerUpdated(session.data().peer(peerCopy), Data::PeerUpdate::Flag::Rights);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Ui::PreparedList prepareMedia(not_null<Main::Session*> session,
|
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);
|
groupMedia.emplace_back(media);
|
||||||
auto prepared = Ui::PreparedFile(AyuSync::filePath(session, 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());
|
Storage::PrepareDetails(prepared, st::sendMediaPreviewSize, PhotoSideLimit());
|
||||||
return prepared;
|
return prepared;
|
||||||
};
|
};
|
||||||
|
@ -120,7 +127,9 @@ static Ui::PreparedList prepareMedia(not_null<Main::Session*> session,
|
||||||
const auto groupId = startItem->groupId();
|
const auto groupId = startItem->groupId();
|
||||||
|
|
||||||
Ui::PreparedList list;
|
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) {
|
if (!groupId.value) {
|
||||||
return list;
|
return list;
|
||||||
|
@ -132,7 +141,9 @@ static Ui::PreparedList prepareMedia(not_null<Main::Session*> session,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (const auto nextMedia = nextItem->media()) {
|
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;
|
i = k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,7 +307,10 @@ void forwardMessages(
|
||||||
const auto history = action.history;
|
const auto history = action.history;
|
||||||
const auto peer = history->peer;
|
const auto peer = history->peer;
|
||||||
|
|
||||||
|
crl::on_main([&]
|
||||||
|
{
|
||||||
history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {});
|
history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {});
|
||||||
|
});
|
||||||
|
|
||||||
std::shared_ptr<ForwardState> state;
|
std::shared_ptr<ForwardState> state;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
//
|
//
|
||||||
// Copyright @Radolyn, 2025
|
// Copyright @Radolyn, 2025
|
||||||
#include "ayu_sync.h"
|
#include "ayu_sync.h"
|
||||||
#include "apiwrap.h"
|
|
||||||
#include "api/api_sending.h"
|
#include "api/api_sending.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/core_settings.h"
|
#include "core/core_settings.h"
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
|
@ -127,6 +128,8 @@ void loadDocumentSync(not_null<Main::Session*> session, DocumentData *data, not_
|
||||||
auto latch = std::make_shared<TimedCountDownLatch>(1);
|
auto latch = std::make_shared<TimedCountDownLatch>(1);
|
||||||
auto lifetime = std::make_shared<rpl::lifetime>();
|
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||||
|
|
||||||
|
crl::on_main([&]
|
||||||
|
{
|
||||||
data->save(Data::FileOriginMessage(item->fullId()), filePath(session, item->media()));
|
data->save(Data::FileOriginMessage(item->fullId()), filePath(session, item->media()));
|
||||||
|
|
||||||
rpl::single() | rpl::then(
|
rpl::single() | rpl::then(
|
||||||
|
@ -140,6 +143,7 @@ void loadDocumentSync(not_null<Main::Session*> session, DocumentData *data, not_
|
||||||
base::take(lifetime)->destroy();
|
base::take(lifetime)->destroy();
|
||||||
},
|
},
|
||||||
*lifetime);
|
*lifetime);
|
||||||
|
});
|
||||||
|
|
||||||
latch->await(std::chrono::minutes(5));
|
latch->await(std::chrono::minutes(5));
|
||||||
}
|
}
|
||||||
|
@ -207,6 +211,8 @@ void loadPhotoSync(not_null<Main::Session*> session, const std::pair<not_null<Ph
|
||||||
if (finalCheck()) {
|
if (finalCheck()) {
|
||||||
saveToFiles();
|
saveToFiles();
|
||||||
} else {
|
} else {
|
||||||
|
crl::on_main([&]
|
||||||
|
{
|
||||||
session->downloaderTaskFinished() | rpl::filter([&]
|
session->downloaderTaskFinished() | rpl::filter([&]
|
||||||
{
|
{
|
||||||
return finalCheck();
|
return finalCheck();
|
||||||
|
@ -217,9 +223,9 @@ void loadPhotoSync(not_null<Main::Session*> session, const std::pair<not_null<Ph
|
||||||
base::take(lifetime)->destroy();
|
base::take(lifetime)->destroy();
|
||||||
},
|
},
|
||||||
*lifetime);
|
*lifetime);
|
||||||
}
|
});
|
||||||
|
|
||||||
latch->await(std::chrono::minutes(5));
|
latch->await(std::chrono::minutes(5));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessageSync(not_null<Main::Session*> session, Api::MessageToSend &message) {
|
void sendMessageSync(not_null<Main::Session*> session, Api::MessageToSend &message) {
|
||||||
|
@ -240,7 +246,8 @@ void waitForMsgSync(not_null<Main::Session*> session, const Api::SendAction &act
|
||||||
auto latch = std::make_shared<TimedCountDownLatch>(1);
|
auto latch = std::make_shared<TimedCountDownLatch>(1);
|
||||||
auto lifetime = std::make_shared<rpl::lifetime>();
|
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||||
|
|
||||||
|
crl::on_main([&]
|
||||||
|
{
|
||||||
session->data().itemIdChanged()
|
session->data().itemIdChanged()
|
||||||
| rpl::filter([&](const Data::Session::IdChange &update)
|
| rpl::filter([&](const Data::Session::IdChange &update)
|
||||||
{
|
{
|
||||||
|
@ -251,6 +258,7 @@ void waitForMsgSync(not_null<Main::Session*> session, const Api::SendAction &act
|
||||||
base::take(lifetime)->destroy();
|
base::take(lifetime)->destroy();
|
||||||
},
|
},
|
||||||
*lifetime);
|
*lifetime);
|
||||||
|
});
|
||||||
|
|
||||||
latch->await(std::chrono::minutes(2));
|
latch->await(std::chrono::minutes(2));
|
||||||
}
|
}
|
||||||
|
@ -260,9 +268,6 @@ void sendDocumentSync(not_null<Main::Session*> session,
|
||||||
SendMediaType type,
|
SendMediaType type,
|
||||||
TextWithTags &&caption,
|
TextWithTags &&caption,
|
||||||
const Api::SendAction &action) {
|
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>();
|
auto groupId = std::make_shared<SendingAlbum>();
|
||||||
groupId->groupId = base::RandomValue<uint64>();
|
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);
|
session->api().sendFiles(std::move(lst), type, std::move(caption), groupId, action);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
waitForMsgSync(session, 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendStickerSync(not_null<Main::Session*> session,
|
void sendStickerSync(not_null<Main::Session*> session,
|
||||||
|
|
Loading…
Add table
Reference in a new issue