From 731cef3c77c9cf3ad0c160701d1be56cb02fa297 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Mon, 16 Jul 2018 22:05:34 +0800 Subject: [PATCH] Init file sending. --- include/libqmatrixclient | 2 +- qml/component/AudioBubble.qml | 19 +++++++++++++++++++ qml/form/RoomForm.qml | 1 + res.qrc | 1 + src/controller.cpp | 12 ++++++++---- src/controller.h | 3 ++- src/messageeventmodel.cpp | 3 ++- 7 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 qml/component/AudioBubble.qml diff --git a/include/libqmatrixclient b/include/libqmatrixclient index 496e106..56480bc 160000 --- a/include/libqmatrixclient +++ b/include/libqmatrixclient @@ -1 +1 @@ -Subproject commit 496e106083f3740d44716b96ed1b098d61df19eb +Subproject commit 56480bc96b28356c44547cc3d9ea1afbda9f04f9 diff --git a/qml/component/AudioBubble.qml b/qml/component/AudioBubble.qml new file mode 100644 index 0000000..c72728d --- /dev/null +++ b/qml/component/AudioBubble.qml @@ -0,0 +1,19 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtMultimedia 5.8 + +AvatarContainer { + Button { + id: downloadButton + + text: content.body + highlighted: !sentByMe + flat: true + + onClicked: downloadable.downloadAndOpen() + + Audio { + audioRole: Audio.VoiceCommunicationRole + } + } +} diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index 5d7f301..bcf718d 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -154,6 +154,7 @@ Item { currentRoom.uploadFile(fileDialog.fileUrl, fileDialog.fileUrl) currentRoom.fileTransferCompleted.connect(function(id, localFile, mxcUrl) { console.log("File transferred: " + id + ":" + mxcUrl) + matriqueController.postFile(currentRoom, localFile, mxcUrl) }) } } diff --git a/res.qrc b/res.qrc index ce52fb9..1f2d682 100644 --- a/res.qrc +++ b/res.qrc @@ -24,5 +24,6 @@ qml/component/FileBubble.qml qml/component/AvatarContainer.qml qml/form/RoomListForm.qml + qml/component/AudioBubble.qml diff --git a/src/controller.cpp b/src/controller.cpp index abb57db..ce11df4 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -79,8 +79,12 @@ void Controller::reconnect() { m_connection->connectWithToken(userID, token, ""); } -void Controller::postFile(QMatrixClient::Room* room, - const QUrl& localFilename) { -// auto job = m_connection->uploadFile(localFilename.toLocalFile()); -// room->fileTransferInfo(localFilename.fileName()) +void Controller::postFile(QMatrixClient::Room* room, const QUrl& localFile, + const QUrl& mxcUrl) { + QJsonObject json{{"body", localFile.fileName()}, + {"filename", localFile.fileName()}, + {"url", mxcUrl.url()}}; + room->postMessage(QMatrixClient::RoomMessageEvent{ + localFile.fileName(), "m.file", + new QMatrixClient::EventContent::FileContent(json)}); } diff --git a/src/controller.h b/src/controller.h index fb44720..ef388a2 100644 --- a/src/controller.h +++ b/src/controller.h @@ -97,7 +97,8 @@ class Controller : public QObject { void errorOccured(); public slots: - void postFile(QMatrixClient::Room* room, const QUrl& localFilename); + void postFile(QMatrixClient::Room* room, const QUrl& localFile, + const QUrl& mxcUrl); }; #endif // CONTROLLER_H diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index e4e2edf..55dd1bd 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -273,8 +273,9 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const { return "notice"; case MessageEventType::Image: return "image"; - case MessageEventType::File: case MessageEventType::Audio: +// return "audio"; + case MessageEventType::File: case MessageEventType::Video: return "file"; default: