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 mousePressEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
private slots:
void imageDownloaded(const QString &event_id, const QPixmap &img);
private: private:
void openUrl(); void openUrl();

View File

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