Add a unique id for locally uploaded images

The event_id will be an empty string because we haven't received yet
This commit is contained in:
Konstantinos Sideris 2018-03-07 20:42:32 +02:00
parent d703377a0a
commit ea22bdce18
2 changed files with 13 additions and 17 deletions

View file

@ -53,9 +53,6 @@ protected:
void mousePressEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private slots:
void imageDownloaded(const QString &event_id, const QPixmap &img);
private:
void openUrl();

View file

@ -21,6 +21,7 @@
#include <QFileInfo>
#include <QPainter>
#include <QPixmap>
#include <QUuid>
#include "Config.h"
#include "Utils.h"
@ -55,9 +56,12 @@ ImageItem::ImageItem(QSharedPointer<MatrixClient> client,
client_.data()->downloadImage(QString::fromStdString(event.event_id), url_);
connect(client_.data(),
SIGNAL(imageDownloaded(const QString &, const QPixmap &)),
&MatrixClient::imageDownloaded,
this,
SLOT(imageDownloaded(const QString &, const QPixmap &)));
[this](const QString &id, const QPixmap &img) {
if (id == QString::fromStdString(event_.event_id))
setImage(img);
});
}
ImageItem::ImageItem(QSharedPointer<MatrixClient> client,
@ -87,21 +91,16 @@ ImageItem::ImageItem(QSharedPointer<MatrixClient> client,
url_ = QString("%1/_matrix/media/r0/download/%2")
.arg(client_.data()->getHomeServer().toString(), media_params);
client_.data()->downloadImage(QString::fromStdString(event_.event_id), url_);
const auto request_id = QUuid::createUuid().toString();
client_.data()->downloadImage(request_id, url_);
connect(client_.data(),
SIGNAL(imageDownloaded(const QString &, const QPixmap &)),
&MatrixClient::imageDownloaded,
this,
SLOT(imageDownloaded(const QString &, const QPixmap &)));
}
void
ImageItem::imageDownloaded(const QString &event_id, const QPixmap &img)
{
if (event_id != QString::fromStdString(event_.event_id))
return;
setImage(img);
[request_id, this](const QString &id, const QPixmap &img) {
if (id == request_id)
setImage(img);
});
}
void