summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-03-08 15:26:52 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-03-08 15:26:52 +0100
commit69a50c15c75fc9159bb607ed04edfed69bb92e59 (patch)
tree121703e1ecdd417fa3ede5555c4a890aecc33bcc
parentFix images without size (diff)
downloadnheko-69a50c15c75fc9159bb607ed04edfed69bb92e59.tar.xz
Reduce times we read upload data
-rw-r--r--src/ChatPage.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 698a4ae2..029444a3 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -307,16 +307,16 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
                  QString mimeClass,
                  const QString &fn,
                  const std::optional<RelatedInfo> &related) {
-                  QMimeDatabase db;
-                  QMimeType mime = db.mimeTypeForData(dev.data());
-
                   if (!dev->open(QIODevice::ReadOnly)) {
                           emit uploadFailed(
                             QString("Error while reading media: %1").arg(dev->errorString()));
                           return;
                   }
 
-                  auto bin     = dev->peek(dev->size());
+                  auto bin = dev->readAll();
+                  QMimeDatabase db;
+                  QMimeType mime = db.mimeTypeForData(bin);
+
                   auto payload = std::string(bin.data(), bin.size());
                   std::optional<mtx::crypto::EncryptedFile> encryptedFile;
                   if (cache::isRoomEncrypted(current_room_.toStdString())) {
@@ -328,10 +328,9 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
                   QSize dimensions;
                   QString blurhash;
                   if (mimeClass == "image") {
-                          dimensions = QImageReader(dev.data()).size();
-
                           QImage img;
                           img.loadFromData(bin);
+                          dimensions = img.size();
                           if (img.height() > 200 && img.width() > 360)
                                   img = img.scaled(360, 200, Qt::KeepAspectRatioByExpanding);
                           std::vector<unsigned char> data;