mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-08-02 10:53:02 +02:00
fix: AyuForward crashes & improvements
This commit is contained in:
parent
157039946f
commit
4940d85b29
3 changed files with 58 additions and 17 deletions
|
@ -213,12 +213,11 @@ void sendMedia(
|
|||
}
|
||||
|
||||
bool isAyuForwardNeeded(const std::vector<not_null<HistoryItem*>> &items) {
|
||||
for (const auto &item : items) {
|
||||
if (isAyuForwardNeeded(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
const auto needAyuForward = [&](const auto &item)
|
||||
{
|
||||
return isAyuForwardNeeded(item);
|
||||
};
|
||||
return std::ranges::any_of(items, needAyuForward);
|
||||
}
|
||||
|
||||
bool isAyuForwardNeeded(not_null<HistoryItem*> item) {
|
||||
|
@ -243,7 +242,10 @@ void intelligentForward(
|
|||
const Api::SendAction &action,
|
||||
const Data::ResolvedForwardDraft &draft) {
|
||||
const auto history = action.history;
|
||||
history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {});
|
||||
crl::on_main([&]
|
||||
{
|
||||
history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {});
|
||||
});
|
||||
|
||||
const auto items = draft.items;
|
||||
const auto peer = history->peer;
|
||||
|
@ -302,7 +304,7 @@ void forwardMessages(
|
|||
not_null<Main::Session*> session,
|
||||
const Api::SendAction &action,
|
||||
bool forwardState,
|
||||
Data::ResolvedForwardDraft draft) {
|
||||
const Data::ResolvedForwardDraft &draft) {
|
||||
const auto items = draft.items;
|
||||
const auto history = action.history;
|
||||
const auto peer = history->peer;
|
||||
|
@ -392,6 +394,23 @@ void forwardMessages(
|
|||
}
|
||||
}
|
||||
|
||||
// remove not finished files
|
||||
for (int j = preparedMedia.files.size() - 1; j >= 0; j--) {
|
||||
auto &file = preparedMedia.files[j];
|
||||
|
||||
QFile f(file.path);
|
||||
if (groupMedia[j]->photo() && f.size() < groupMedia[j]->photo()->imageByteSize(Data::PhotoSize::Large)
|
||||
||
|
||||
groupMedia[j]->document() && f.size() < groupMedia[j]->document()->size
|
||||
) {
|
||||
preparedMedia.files.erase(preparedMedia.files.begin() + j);
|
||||
}
|
||||
}
|
||||
|
||||
if (preparedMedia.files.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto groups = Ui::DivideByGroups(
|
||||
std::move(preparedMedia),
|
||||
way,
|
||||
|
|
|
@ -47,6 +47,6 @@ void forwardMessages(
|
|||
not_null<Main::Session*> session,
|
||||
const Api::SendAction &action,
|
||||
bool forwardState,
|
||||
Data::ResolvedForwardDraft draft);
|
||||
const Data::ResolvedForwardDraft &draft);
|
||||
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ private:
|
|||
namespace AyuSync {
|
||||
|
||||
QString pathForSave(not_null<Main::Session*> session) {
|
||||
const auto path = Core::App().settings().downloadPath();
|
||||
auto path = Core::App().settings().downloadPath();
|
||||
if (path.isEmpty()) {
|
||||
return File::DefaultDownloadPath(session);
|
||||
}
|
||||
|
@ -66,6 +66,10 @@ QString pathForSave(not_null<Main::Session*> session) {
|
|||
}
|
||||
|
||||
QString filePath(not_null<Main::Session*> session, const Data::Media *media) {
|
||||
if (!media) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (const auto document = media->document()) {
|
||||
if (!document->filename().isEmpty()) {
|
||||
return pathForSave(session) + media->document()->filename();
|
||||
|
@ -85,7 +89,7 @@ QString filePath(not_null<Main::Session*> session, const Data::Media *media) {
|
|||
return pathForSave(session) + QString::number(photo->getDC()) + "_" + QString::number(photo->id) + ".jpg";
|
||||
}
|
||||
|
||||
return QString();
|
||||
return {};
|
||||
}
|
||||
|
||||
qint64 fileSize(not_null<HistoryItem*> item) {
|
||||
|
@ -128,9 +132,13 @@ void loadDocumentSync(not_null<Main::Session*> session, DocumentData *data, not_
|
|||
auto latch = std::make_shared<TimedCountDownLatch>(1);
|
||||
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||
|
||||
auto path = filePath(session, item->media());
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
crl::on_main([&]
|
||||
{
|
||||
data->save(Data::FileOriginMessage(item->fullId()), filePath(session, item->media()));
|
||||
data->save(Data::FileOriginMessage(item->fullId()), path);
|
||||
|
||||
rpl::single() | rpl::then(
|
||||
session->downloaderTaskFinished()
|
||||
|
@ -140,12 +148,26 @@ void loadDocumentSync(not_null<Main::Session*> session, DocumentData *data, not_
|
|||
}) | rpl::start_with_next([&]() mutable
|
||||
{
|
||||
latch->countDown();
|
||||
base::take(lifetime)->destroy();
|
||||
},
|
||||
*lifetime);
|
||||
});
|
||||
|
||||
latch->await(std::chrono::minutes(5));
|
||||
|
||||
constexpr auto overall = std::chrono::minutes(15);
|
||||
const auto startTime = std::chrono::steady_clock::now();
|
||||
|
||||
|
||||
while (std::chrono::steady_clock::now() - startTime < overall) {
|
||||
if (latch->await(std::chrono::minutes(5))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!data->loading()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
base::take(lifetime)->destroy();
|
||||
}
|
||||
|
||||
void forwardMessagesSync(not_null<Main::Session*> session,
|
||||
|
@ -220,11 +242,11 @@ void loadPhotoSync(not_null<Main::Session*> session, const std::pair<not_null<Ph
|
|||
{
|
||||
saveToFiles();
|
||||
latch->countDown();
|
||||
base::take(lifetime)->destroy();
|
||||
},
|
||||
*lifetime);
|
||||
});
|
||||
latch->await(std::chrono::minutes(5));
|
||||
base::take(lifetime)->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,12 +277,12 @@ void waitForMsgSync(not_null<Main::Session*> session, const Api::SendAction &act
|
|||
}) | rpl::start_with_next([&]
|
||||
{
|
||||
latch->countDown();
|
||||
base::take(lifetime)->destroy();
|
||||
},
|
||||
*lifetime);
|
||||
});
|
||||
|
||||
latch->await(std::chrono::minutes(2));
|
||||
latch->await(std::chrono::minutes(5));
|
||||
base::take(lifetime)->destroy();
|
||||
}
|
||||
|
||||
void sendDocumentSync(not_null<Main::Session*> session,
|
||||
|
|
Loading…
Add table
Reference in a new issue