mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
parent
cfaecaab17
commit
6f07ab433e
6 changed files with 67 additions and 46 deletions
|
@ -93,7 +93,8 @@ signals:
|
||||||
const QString &filename,
|
const QString &filename,
|
||||||
const QString &url,
|
const QString &url,
|
||||||
const QString &mime,
|
const QString &mime,
|
||||||
qint64 dsize);
|
qint64 dsize,
|
||||||
|
const QSize &dimensions);
|
||||||
void fileUploaded(const QString &roomid,
|
void fileUploaded(const QString &roomid,
|
||||||
const QString &filename,
|
const QString &filename,
|
||||||
const QString &url,
|
const QString &url,
|
||||||
|
|
|
@ -69,6 +69,7 @@ struct PendingMessage
|
||||||
uint64_t media_size;
|
uint64_t media_size;
|
||||||
QString event_id;
|
QString event_id;
|
||||||
TimelineItem *widget;
|
TimelineItem *widget;
|
||||||
|
QSize dimensions;
|
||||||
bool is_encrypted = false;
|
bool is_encrypted = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -125,7 +126,8 @@ public:
|
||||||
void addUserMessage(const QString &url,
|
void addUserMessage(const QString &url,
|
||||||
const QString &filename,
|
const QString &filename,
|
||||||
const QString &mime,
|
const QString &mime,
|
||||||
uint64_t size);
|
uint64_t size,
|
||||||
|
const QSize &dimensions = QSize());
|
||||||
void updatePendingMessage(const std::string &txn_id, const QString &event_id);
|
void updatePendingMessage(const std::string &txn_id, const QString &event_id);
|
||||||
void scrollDown();
|
void scrollDown();
|
||||||
|
|
||||||
|
@ -321,7 +323,8 @@ void
|
||||||
TimelineView::addUserMessage(const QString &url,
|
TimelineView::addUserMessage(const QString &url,
|
||||||
const QString &filename,
|
const QString &filename,
|
||||||
const QString &mime,
|
const QString &mime,
|
||||||
uint64_t size)
|
uint64_t size,
|
||||||
|
const QSize &dimensions)
|
||||||
{
|
{
|
||||||
auto with_sender = (lastSender_ != local_user_) || isDateDifference(lastMsgTimestamp_);
|
auto with_sender = (lastSender_ != local_user_) || isDateDifference(lastMsgTimestamp_);
|
||||||
auto trimmed = QFileInfo{filename}.fileName(); // Trim file path.
|
auto trimmed = QFileInfo{filename}.fileName(); // Trim file path.
|
||||||
|
@ -346,6 +349,7 @@ TimelineView::addUserMessage(const QString &url,
|
||||||
message.mime = mime;
|
message.mime = mime;
|
||||||
message.media_size = size;
|
message.media_size = size;
|
||||||
message.widget = view_item;
|
message.widget = view_item;
|
||||||
|
message.dimensions = dimensions;
|
||||||
|
|
||||||
handleNewUserMessage(message);
|
handleNewUserMessage(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,8 @@ public slots:
|
||||||
const QString &filename,
|
const QString &filename,
|
||||||
const QString &url,
|
const QString &url,
|
||||||
const QString &mime,
|
const QString &mime,
|
||||||
uint64_t dsize);
|
uint64_t dsize,
|
||||||
|
const QSize &dimensions);
|
||||||
void queueFileMessage(const QString &roomid,
|
void queueFileMessage(const QString &roomid,
|
||||||
const QString &filename,
|
const QString &filename,
|
||||||
const QString &url,
|
const QString &url,
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QImageReader>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
|
@ -283,7 +284,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
|
|
||||||
connect(text_input_, &TextInputWidget::sendJoinRoomRequest, this, &ChatPage::joinRoom);
|
connect(text_input_, &TextInputWidget::sendJoinRoomRequest, this, &ChatPage::joinRoom);
|
||||||
|
|
||||||
connect(text_input_,
|
connect(
|
||||||
|
text_input_,
|
||||||
&TextInputWidget::uploadImage,
|
&TextInputWidget::uploadImage,
|
||||||
this,
|
this,
|
||||||
[this](QSharedPointer<QIODevice> dev, const QString &fn) {
|
[this](QSharedPointer<QIODevice> dev, const QString &fn) {
|
||||||
|
@ -296,8 +298,9 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bin = dev->readAll();
|
auto bin = dev->peek(dev->size());
|
||||||
auto payload = std::string(bin.data(), bin.size());
|
auto payload = std::string(bin.data(), bin.size());
|
||||||
|
auto dimensions = QImageReader(dev.get()).size();
|
||||||
|
|
||||||
http::v2::client()->upload(
|
http::v2::client()->upload(
|
||||||
payload,
|
payload,
|
||||||
|
@ -307,13 +310,14 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
room_id = current_room_,
|
room_id = current_room_,
|
||||||
filename = fn,
|
filename = fn,
|
||||||
mime = mime.name(),
|
mime = mime.name(),
|
||||||
size = payload.size()](const mtx::responses::ContentURI &res,
|
size = payload.size(),
|
||||||
mtx::http::RequestErr err) {
|
dimensions](const mtx::responses::ContentURI &res, mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
emit uploadFailed(
|
emit uploadFailed(
|
||||||
tr("Failed to upload image. Please try again."));
|
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,
|
err->matrix_error.error,
|
||||||
|
to_string(err->matrix_error.errcode),
|
||||||
static_cast<int>(err->status_code));
|
static_cast<int>(err->status_code));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -322,7 +326,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
filename,
|
filename,
|
||||||
QString::fromStdString(res.content_uri),
|
QString::fromStdString(res.content_uri),
|
||||||
mime,
|
mime,
|
||||||
size);
|
size,
|
||||||
|
dimensions);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -461,9 +466,15 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
connect(this,
|
connect(this,
|
||||||
&ChatPage::imageUploaded,
|
&ChatPage::imageUploaded,
|
||||||
this,
|
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();
|
text_input_->hideUploadSpinner();
|
||||||
view_manager_->queueImageMessage(roomid, filename, url, mime, dsize);
|
view_manager_->queueImageMessage(
|
||||||
|
roomid, filename, url, mime, dsize, dimensions);
|
||||||
});
|
});
|
||||||
connect(this,
|
connect(this,
|
||||||
&ChatPage::fileUploaded,
|
&ChatPage::fileUploaded,
|
||||||
|
|
|
@ -1097,6 +1097,8 @@ toRoomMessage<mtx::events::msg::Image>(const PendingMessage &m)
|
||||||
image.info.size = m.media_size;
|
image.info.size = m.media_size;
|
||||||
image.body = m.filename.toStdString();
|
image.body = m.filename.toStdString();
|
||||||
image.url = m.body.toStdString();
|
image.url = m.body.toStdString();
|
||||||
|
image.info.h = m.dimensions.height();
|
||||||
|
image.info.w = m.dimensions.width();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,8 @@ TimelineViewManager::queueImageMessage(const QString &roomid,
|
||||||
const QString &filename,
|
const QString &filename,
|
||||||
const QString &url,
|
const QString &url,
|
||||||
const QString &mime,
|
const QString &mime,
|
||||||
uint64_t size)
|
uint64_t size,
|
||||||
|
const QSize &dimensions)
|
||||||
{
|
{
|
||||||
if (!timelineViewExists(roomid)) {
|
if (!timelineViewExists(roomid)) {
|
||||||
nhlog::ui()->warn("Cannot send m.image message to a non-managed view");
|
nhlog::ui()->warn("Cannot send m.image message to a non-managed view");
|
||||||
|
@ -83,7 +84,8 @@ TimelineViewManager::queueImageMessage(const QString &roomid,
|
||||||
|
|
||||||
auto view = views_[roomid];
|
auto view = views_[roomid];
|
||||||
|
|
||||||
view->addUserMessage<ImageItem, mtx::events::MessageType::Image>(url, filename, mime, size);
|
view->addUserMessage<ImageItem, mtx::events::MessageType::Image>(
|
||||||
|
url, filename, mime, size, dimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue