|
|
|
@ -16,6 +16,7 @@ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <QApplication> |
|
|
|
|
#include <QImageReader> |
|
|
|
|
#include <QSettings> |
|
|
|
|
#include <QtConcurrent> |
|
|
|
|
|
|
|
|
@ -283,7 +284,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) |
|
|
|
|
|
|
|
|
|
connect(text_input_, &TextInputWidget::sendJoinRoomRequest, this, &ChatPage::joinRoom); |
|
|
|
|
|
|
|
|
|
connect(text_input_, |
|
|
|
|
connect( |
|
|
|
|
text_input_, |
|
|
|
|
&TextInputWidget::uploadImage, |
|
|
|
|
this, |
|
|
|
|
[this](QSharedPointer<QIODevice> dev, const QString &fn) { |
|
|
|
@ -296,8 +298,9 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto bin = dev->readAll(); |
|
|
|
|
auto bin = dev->peek(dev->size()); |
|
|
|
|
auto payload = std::string(bin.data(), bin.size()); |
|
|
|
|
auto dimensions = QImageReader(dev.get()).size(); |
|
|
|
|
|
|
|
|
|
http::v2::client()->upload( |
|
|
|
|
payload, |
|
|
|
@ -307,13 +310,14 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) |
|
|
|
|
room_id = current_room_, |
|
|
|
|
filename = fn, |
|
|
|
|
mime = mime.name(), |
|
|
|
|
size = payload.size()](const mtx::responses::ContentURI &res, |
|
|
|
|
mtx::http::RequestErr err) { |
|
|
|
|
size = payload.size(), |
|
|
|
|
dimensions](const mtx::responses::ContentURI &res, mtx::http::RequestErr err) { |
|
|
|
|
if (err) { |
|
|
|
|
emit uploadFailed( |
|
|
|
|
tr("Failed to upload image. Please try again.")); |
|
|
|
|
nhlog::net()->warn("failed to upload image: {} ({})", |
|
|
|
|
nhlog::net()->warn("failed to upload image: {} {} ({})", |
|
|
|
|
err->matrix_error.error, |
|
|
|
|
to_string(err->matrix_error.errcode), |
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -322,7 +326,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) |
|
|
|
|
filename, |
|
|
|
|
QString::fromStdString(res.content_uri), |
|
|
|
|
mime, |
|
|
|
|
size); |
|
|
|
|
size, |
|
|
|
|
dimensions); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -461,9 +466,15 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) |
|
|
|
|
connect(this, |
|
|
|
|
&ChatPage::imageUploaded, |
|
|
|
|
this, |
|
|
|
|
[this](QString roomid, QString filename, QString url, QString mime, qint64 dsize) { |
|
|
|
|
[this](QString roomid, |
|
|
|
|
QString filename, |
|
|
|
|
QString url, |
|
|
|
|
QString mime, |
|
|
|
|
qint64 dsize, |
|
|
|
|
QSize dimensions) { |
|
|
|
|
text_input_->hideUploadSpinner(); |
|
|
|
|
view_manager_->queueImageMessage(roomid, filename, url, mime, dsize); |
|
|
|
|
view_manager_->queueImageMessage( |
|
|
|
|
roomid, filename, url, mime, dsize, dimensions); |
|
|
|
|
}); |
|
|
|
|
connect(this, |
|
|
|
|
&ChatPage::fileUploaded, |
|
|
|
|