mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Block notifications until the image has been downloaded
This commit is contained in:
parent
64dd10a6a0
commit
98b2fee71b
1 changed files with 21 additions and 9 deletions
|
@ -22,9 +22,11 @@ NotificationsManager::cacheImage(const mtx::events::collections::TimelineEvents
|
||||||
QString path{QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" +
|
QString path{QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" +
|
||||||
filename};
|
filename};
|
||||||
|
|
||||||
|
bool downloadComplete = false;
|
||||||
|
|
||||||
http::client()->download(
|
http::client()->download(
|
||||||
url,
|
url,
|
||||||
[&path, url, encryptionInfo](const std::string &data,
|
[&downloadComplete, &path, url, encryptionInfo](const std::string &data,
|
||||||
const std::string &,
|
const std::string &,
|
||||||
const std::string &,
|
const std::string &,
|
||||||
mtx::http::RequestErr err) {
|
mtx::http::RequestErr err) {
|
||||||
|
@ -33,6 +35,9 @@ NotificationsManager::cacheImage(const mtx::events::collections::TimelineEvents
|
||||||
url,
|
url,
|
||||||
err->matrix_error.error,
|
err->matrix_error.error,
|
||||||
static_cast<int>(err->status_code));
|
static_cast<int>(err->status_code));
|
||||||
|
// the image doesn't exist, so delete the path
|
||||||
|
path.clear();
|
||||||
|
downloadComplete = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +49,11 @@ NotificationsManager::cacheImage(const mtx::events::collections::TimelineEvents
|
||||||
|
|
||||||
QFile file{path};
|
QFile file{path};
|
||||||
|
|
||||||
if (!file.open(QIODevice::WriteOnly))
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
|
path.clear();
|
||||||
|
downloadComplete = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// delete any existing file content
|
// delete any existing file content
|
||||||
file.resize(0);
|
file.resize(0);
|
||||||
|
@ -53,9 +61,9 @@ NotificationsManager::cacheImage(const mtx::events::collections::TimelineEvents
|
||||||
// resize the image
|
// resize the image
|
||||||
QImage img{utils::readImage(QByteArray{temp.data()})};
|
QImage img{utils::readImage(QByteArray{temp.data()})};
|
||||||
|
|
||||||
if (img.isNull())
|
if (img.isNull()) {
|
||||||
{
|
|
||||||
path.clear();
|
path.clear();
|
||||||
|
downloadComplete = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,11 +76,15 @@ NotificationsManager::cacheImage(const mtx::events::collections::TimelineEvents
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
downloadComplete = true;
|
||||||
return;
|
return;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
nhlog::ui()->warn("Error while caching file to: {}", e.what());
|
nhlog::ui()->warn("Error while caching file to: {}", e.what());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
while (!downloadComplete)
|
||||||
|
continue;
|
||||||
|
|
||||||
return path.toHtmlEscaped();
|
return path.toHtmlEscaped();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue