Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114774
D143.1732576347.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
13 KB
Referenced Files
None
Subscribers
None
D143.1732576347.diff
View Options
diff --git a/src/contents/ui/SendMessageBox.qml b/src/contents/ui/SendMessageBox.qml
--- a/src/contents/ui/SendMessageBox.qml
+++ b/src/contents/ui/SendMessageBox.qml
@@ -260,6 +260,7 @@
ToolButton {
action: sendMediaFileAction
+ objectName: 'sendMediaFileButton'
display: AbstractButton.IconOnly
}
@@ -344,6 +345,7 @@
}
property var fileDialog: Kazv.FileDialogAdapter {
+ objectName: 'fileDialog'
onAccepted: {
sendMessageBox.uploadFile(fileUrl);
}
@@ -352,8 +354,11 @@
function uploadFile(fileUrl) {
kazvIOManager.startNewUploadJob(
matrixSdk.serverUrl, fileUrl, matrixSdk.token,
- room.roomId, sdkVars.roomList, room.encrypted
+ room.roomId, sdkVars.roomList, room.encrypted,
+ draftRelType, draftRelatedTo
);
+ sendMessageBox.draftRelType = '';
+ sendMessageBox.draftRelatedTo = '';
}
property var stickerPopup: Kirigami.OverlaySheet {
diff --git a/src/kazv-io-job.hpp b/src/kazv-io-job.hpp
--- a/src/kazv-io-job.hpp
+++ b/src/kazv-io-job.hpp
@@ -144,10 +144,14 @@
bool setFile(const QString fileName);
public:
- KazvIOUploadJob(std::optional<Kazv::AES256CTRDesc> aes = std::nullopt, QObject *parent = 0);
+ KazvIOUploadJob(std::optional<Kazv::AES256CTRDesc> aes = std::nullopt,
+ const QString &relType = QStringLiteral(""),
+ const QString &relatedTo = QStringLiteral(""), QObject *parent = 0);
KazvIOUploadJob(const QString fileName, const QUrl serverUrl, MatrixRoomList *roomList,
const QString &roomId, const QString token,
- std::optional<Kazv::AES256CTRDesc> aes = std::nullopt, QObject *parent = 0);
+ std::optional<Kazv::AES256CTRDesc> aes = std::nullopt,
+ const QString &relType = QStringLiteral(""),
+ const QString &relatedTo = QStringLiteral(""), QObject *parent = 0);
~KazvIOUploadJob();
Q_INVOKABLE QString fileName();
diff --git a/src/kazv-io-job.cpp b/src/kazv-io-job.cpp
--- a/src/kazv-io-job.cpp
+++ b/src/kazv-io-job.cpp
@@ -240,20 +240,28 @@
QSharedPointer<MatrixRoom> room;
QString mimeType;
QString mxcUri;
+ QString relType;
+ QString relatedTo;
};
-KazvIOUploadJob::KazvIOUploadJob(std::optional<Kazv::AES256CTRDesc> aes, QObject *parent)
+KazvIOUploadJob::KazvIOUploadJob(std::optional<Kazv::AES256CTRDesc> aes,
+ const QString &relType, const QString &relatedTo, QObject *parent)
: KazvIOBaseJob(aes, parent)
, m_d(new KazvIOUploadJobPrivate)
{
+ m_d->relType = relType;
+ m_d->relatedTo = relatedTo;
}
KazvIOUploadJob::KazvIOUploadJob(const QString fileName, const QUrl serverUrl,
MatrixRoomList *roomList, const QString &roomId, const QString token,
- std::optional<Kazv::AES256CTRDesc> aes, QObject *parent)
+ std::optional<Kazv::AES256CTRDesc> aes,
+ const QString &relType, const QString &relatedTo, QObject *parent)
: KazvIOBaseJob(aes, parent)
, m_d(new KazvIOUploadJobPrivate)
{
+ m_d->relType = relType;
+ m_d->relatedTo = relatedTo;
if (setFile(fileName)) {
auto kazvUploadJob = Kazv::Api::UploadContentJob(serverUrl.toString().toStdString(),
token.toStdString(), Kazv::FileDesc(std::string()));
@@ -323,10 +331,11 @@
QMimeDatabase().mimeTypeForFile(m_d->file.data()->fileName()).name(),
m_d->file->size(), mxcUri,
QString::fromStdString(aes.value().key()), QString::fromStdString(aes.value().iv()),
- m_d->file->hash());
+ m_d->file->hash(), m_d->relType, m_d->relatedTo);
} else {
m_d->room->sendMediaFileMessage(QUrl::fromLocalFile(m_d->file->fileName()).fileName(),
- QMimeDatabase().mimeTypeForData(m_d->file.data()).name(), m_d->file->size(), mxcUri);
+ QMimeDatabase().mimeTypeForData(m_d->file.data()).name(),
+ m_d->file->size(), mxcUri, m_d->relType, m_d->relatedTo);
}
}
diff --git a/src/kazv-io-manager.hpp b/src/kazv-io-manager.hpp
--- a/src/kazv-io-manager.hpp
+++ b/src/kazv-io-manager.hpp
@@ -51,8 +51,10 @@
Q_INVOKABLE KazvIOBaseJob *startNewDownloadJob(const QUrl &serverUrl, const QUrl &localFileName,
const QString &jobId, const QString &hash,
const QString &key = QStringLiteral(""), const QString &iv = QStringLiteral(""));
- Q_INVOKABLE KazvIOBaseJob *startNewUploadJob(const QUrl &serverUrl, const QUrl &localFileName,
- const QString &token, const QString &roomId, MatrixRoomList *roomList, const bool encrypted);
+ Q_INVOKABLE KazvIOBaseJob *startNewUploadJob(
+ const QUrl &serverUrl, const QUrl &localFileName, const QString &token,
+ const QString &roomId, MatrixRoomList *roomList, const bool encrypted,
+ const QString &relType, const QString &relatedTo);
Q_INVOKABLE KazvIOBaseJob *startNewRoomlessUploadJob(const QUrl &serverUrl, const QUrl &localFileName, const QString &token);
Q_INVOKABLE KazvIOBaseJob *getCacheJob(const QString &jobId) const;
Q_INVOKABLE KazvIOBaseJob *getDownloadJob(const QString &jobId);
diff --git a/src/kazv-io-manager.cpp b/src/kazv-io-manager.cpp
--- a/src/kazv-io-manager.cpp
+++ b/src/kazv-io-manager.cpp
@@ -98,18 +98,20 @@
return downloadJob.data();
}
-KazvIOBaseJob *KazvIOManager::startNewUploadJob(const QUrl &serverUrl, const QUrl &localFileUrl,
- const QString &token, const QString &roomId, MatrixRoomList *roomList, const bool encrypted)
+KazvIOBaseJob *KazvIOManager::startNewUploadJob(
+ const QUrl &serverUrl, const QUrl &localFileUrl, const QString &token,
+ const QString &roomId, MatrixRoomList *roomList, const bool encrypted,
+ const QString &relType, const QString &relatedTo)
{
auto uploadJob = QPointer<KazvIOUploadJob>();
if (encrypted) {
auto aes = Kazv::AES256CTRDesc::fromRandom(
m_d->randomGenerator.generateRange<Kazv::RandomData>(Kazv::AES256CTRDesc::randomSize));
uploadJob = new KazvIOUploadJob(localFileUrl.toLocalFile(), serverUrl,
- roomList, roomId, token, aes);
+ roomList, roomId, token, aes, relType, relatedTo);
} else {
uploadJob = new KazvIOUploadJob(localFileUrl.toLocalFile(), serverUrl,
- roomList, roomId, token, std::nullopt);
+ roomList, roomId, token, std::nullopt, relType, relatedTo);
}
if (!m_d->uploadJobs.contains(roomId) || m_d->uploadJobs[roomId].isNull()) {
m_d->uploadJobs[roomId].reset(new UploadJobModel());
@@ -121,7 +123,9 @@
KazvIOBaseJob *KazvIOManager::startNewRoomlessUploadJob(const QUrl &serverUrl, const QUrl &localFileUrl, const QString &token)
{
- return startNewUploadJob(serverUrl, localFileUrl, token, ROOMLESS, 0, false);
+ return startNewUploadJob(
+ serverUrl, localFileUrl, token, ROOMLESS, 0, false,
+ QStringLiteral(""), QStringLiteral(""));
}
KazvIOBaseJob *KazvIOManager::getCacheJob(const QString &jobId) const
diff --git a/src/matrix-room.hpp b/src/matrix-room.hpp
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -86,11 +86,13 @@
Q_INVOKABLE void sendTextMessage(QString text, const QString &relType, QString relatedTo) const;
Q_INVOKABLE void sendMediaFileMessage(QString fileName, QString mimeType,
- qint64 fileSize, QString mxcUri) const;
+ qint64 fileSize, QString mxcUri,
+ const QString &relType, const QString &relatedTo) const;
Q_INVOKABLE void sendEncryptedFileMessage(const QString &fileName, const QString& mimeType,
const qint64 fileSize, const QString& mxcUri,
- const QString &key, const QString &iv, const QByteArray &hash) const;
+ const QString &key, const QString &iv, const QByteArray &hash,
+ const QString &relType, const QString &relatedTo) const;
Q_INVOKABLE void sendReaction(QString text, QString relatedTo) const;
@@ -155,10 +157,12 @@
protected:
nlohmann::json makeMediaFileMessageJson(QString fileName, QString mimeType,
- qint64 fileSize, QString mxcUri) const;
+ qint64 fileSize, QString mxcUri,
+ const QString &relType, const QString &relatedTo) const;
nlohmann::json makeEncryptedFileMessageJson(const QString &fileName, const QString &mimeType,
const qint64 fileSize, const QString &mxcUri,
- const QString &key, const QString &iv, const QByteArray &hash) const;
+ const QString &key, const QString &iv, const QByteArray &hash,
+ const QString &relType, const QString &relatedTo) const;
private Q_SLOTS:
void setTypingImpl();
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -219,18 +219,24 @@
m_room.sendMessage(Event(j));
}
-void MatrixRoom::sendMediaFileMessage(QString fileName, QString mimeType, qint64 fileSize, QString mxcUri) const
+void MatrixRoom::sendMediaFileMessage(
+ QString fileName, QString mimeType, qint64 fileSize, QString mxcUri,
+ const QString &relType, const QString &relatedTo) const
{
- auto j = makeMediaFileMessageJson(fileName, mimeType, fileSize, mxcUri);
+ auto j = makeMediaFileMessageJson(
+ fileName, mimeType, fileSize, mxcUri, relType, relatedTo);
Kazv::Event e{j};
m_room.sendMessage(e);
}
void MatrixRoom::sendEncryptedFileMessage(const QString &fileName, const QString &mimeType,
const qint64 fileSize, const QString &mxcUri,
- const QString &key, const QString &iv, const QByteArray &hash) const
+ const QString &key, const QString &iv, const QByteArray &hash,
+ const QString &relType, const QString &relatedTo) const
{
- auto j = makeEncryptedFileMessageJson(fileName, mimeType, fileSize, mxcUri, key, iv, hash);
+ auto j = makeEncryptedFileMessageJson(
+ fileName, mimeType, fileSize, mxcUri,
+ key, iv, hash, relType, relatedTo);
Kazv::Event e{j};
m_room.sendMessage(e);
}
@@ -279,7 +285,9 @@
return new MatrixPromise(m_room.sendStateEvent(Event(json(eventJson))));
}
-nlohmann::json MatrixRoom::makeMediaFileMessageJson(QString fileName, QString mimeType, qint64 fileSize, QString mxcUri) const
+nlohmann::json MatrixRoom::makeMediaFileMessageJson(
+ QString fileName, QString mimeType, qint64 fileSize, QString mxcUri,
+ const QString &relType, const QString &relatedTo) const
{
static auto available_msgtype = std::array<std::string, 3>{"m.audio", "m.video", "m.image"};
auto try_msgtype = std::find(available_msgtype.begin(), available_msgtype.end(),
@@ -290,7 +298,7 @@
} else {
msgtype = *try_msgtype;
}
- return nlohmann::json {
+ auto msg = nlohmann::json {
{"type", "m.room.message"},
{"content", {
{"msgtype", msgtype},
@@ -302,11 +310,14 @@
}}
}}
};
+ maybeAddRelations(msg, relType, relatedTo);
+ return msg;
}
nlohmann::json MatrixRoom::makeEncryptedFileMessageJson(const QString &fileName, const QString &mimeType,
const qint64 fileSize, const QString &mxcUri,
- const QString &key, const QString &iv, const QByteArray &hash) const
+ const QString &key, const QString &iv, const QByteArray &hash,
+ const QString &relType, const QString &relatedTo) const
{
static auto available_msgtype = std::array<std::string, 3>{"m.audio", "m.video", "m.image"};
auto try_msgtype = std::find(available_msgtype.begin(), available_msgtype.end(),
@@ -317,7 +328,7 @@
} else {
msgtype = *try_msgtype;
}
- return nlohmann::json {
+ auto msg = nlohmann::json {
{"type", "m.room.message"},
{"content", {
{"msgtype", msgtype},
@@ -343,6 +354,8 @@
}}
}}
};
+ maybeAddRelations(msg, relType, relatedTo);
+ return msg;
}
MatrixPromise *MatrixRoom::redactEvent(QString eventId, QString reason) const
diff --git a/src/tests/quick-tests/tst_SendMessageBox.qml b/src/tests/quick-tests/tst_SendMessageBox.qml
--- a/src/tests/quick-tests/tst_SendMessageBox.qml
+++ b/src/tests/quick-tests/tst_SendMessageBox.qml
@@ -44,6 +44,8 @@
},
setTyping: mockHelper.noop(),
sendTextMessage: mockHelper.noop(),
+ roomId: '!some-event-id',
+ encrypted: true,
};
}
@@ -58,9 +60,25 @@
}
}
property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
- property var kazvIOManager: TestHelpers.KazvIOManagerMock {}
- property var sdkVars: ({})
+ property var matrixSdk: TestHelpers.MatrixSdkMock {
+ property var serverUrl: "https://example.com"
+ property var token: "token"
+ }
+ property var kazvIOManager: TestHelpers.KazvIOManagerMock {
+ property var startNewUploadJob: mockHelper.noop([
+ 'serverUrl',
+ 'fileUrl',
+ 'token',
+ 'roomId',
+ 'roomList',
+ 'encrypted',
+ 'draftRelType',
+ 'draftRelatedTo'
+ ])
+ }
+ property var sdkVars: ({
+ roomList: {}
+ })
Kazv.SendMessageBox {
id: sendMessageBox
@@ -221,5 +239,31 @@
keySequence('Ctrl+Return');
verify(room.sendTextMessage.calledTimes() === 0);
}
+
+ function test_replyWithFile() {
+ sendMessageBox.draftRelType = 'm.in_reply_to';
+ sendMessageBox.draftRelatedTo = '!some-event-id';
+ const sendFileButton = findChild(sendMessageBox, 'sendMediaFileButton');
+ const fileDialog = findChild(sendMessageBox, 'fileDialog');
+
+ verify(sendFileButton.enabled);
+ verify(!fileDialog.visible);
+ mouseClick(sendFileButton);
+ verify(fileDialog.visible);
+ fileDialog.accept();
+ verify(!fileDialog.visible);
+
+ compare(kazvIOManager.startNewUploadJob.calledTimes(), 1);
+ verify(Helpers.deepEqual(kazvIOManager.startNewUploadJob.lastArgs(), {
+ serverUrl: matrixSdk.serverUrl,
+ fileUrl: Qt.url(''),
+ token: matrixSdk.token,
+ roomId: room.roomId,
+ roomList: sdkVars.roomList,
+ encrypted: room.encrypted,
+ draftRelType: 'm.in_reply_to',
+ draftRelatedTo: '!some-event-id'
+ }));
+ }
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 3:12 PM (13 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40395
Default Alt Text
D143.1732576347.diff (13 KB)
Attached To
Mode
D143: Enable upload file for reply
Attached
Detach File
Event Timeline
Log In to Comment