From 4a9967c5c13b9eff6ce725ff7dffda6dc42bf5d7 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Fri, 3 Aug 2018 20:58:12 +0800 Subject: [PATCH] Update libqmatrixclient && Fix "full path is posted instead of filename when uploading files". --- include/libqmatrixclient | 2 +- qml/component/MessageDelegate.qml | 4 ++- src/controller.cpp | 2 +- src/messageeventmodel.cpp | 60 +++++++++++++++---------------- src/messageeventmodel.h | 5 +-- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/include/libqmatrixclient b/include/libqmatrixclient index 527a12e..7298e99 160000 --- a/include/libqmatrixclient +++ b/include/libqmatrixclient @@ -1 +1 @@ -Subproject commit 527a12eb5b6009f679b7e18eceda782f3f5747b7 +Subproject commit 7298e99125522c4d010ec83052cd10ce085e09b4 diff --git a/qml/component/MessageDelegate.qml b/qml/component/MessageDelegate.qml index 5b58f8a..c8baba7 100644 --- a/qml/component/MessageDelegate.qml +++ b/qml/component/MessageDelegate.qml @@ -13,6 +13,8 @@ Item { readonly property bool isMessage: eventType === "message" || eventType === "notice" readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image" + visible: eventType != "redaction" + z: -5 width: delegateLoader.width height: delegateLoader.height @@ -23,6 +25,6 @@ Item { Loader { id: delegateLoader - source: isMessage ? "MessageBubble.qml" : isState ? "StateBubble.qml" : isFile ? eventType === "image" ? "ImageBubble.qml" : "FileBubble.qml" : "" + source: eventType != "redaction" ? isMessage ? "MessageBubble.qml" : isState ? "StateBubble.qml" : isFile ? eventType === "image" ? "ImageBubble.qml" : "FileBubble.qml" : "" : "" } } diff --git a/src/controller.cpp b/src/controller.cpp index de49bcf..613d632 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -82,7 +82,7 @@ void Controller::postMessage(Room* room, const QString& type, void Controller::postFile(Room* room, const QUrl& localFile, const QUrl& mxcUrl) { const QString mime = getMIME(localFile); - const QString fileName = localFile.toLocalFile(); + const QString fileName = localFile.fileName(); QString msgType = "m.file"; if (mime.startsWith("image")) msgType = "m.image"; if (mime.startsWith("video")) msgType = "m.video"; diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index a1b9149..8316cd0 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -4,17 +4,35 @@ #include #include // for qmlRegisterType() -#include "events/redactionevent.h" -#include "events/roomavatarevent.h" -#include "events/roommemberevent.h" -#include "events/simplestateevents.h" +#include +#include +#include +#include +#include +#include +#include -#include "connection.h" -#include "settings.h" -#include "user.h" +QHash MessageEventModel::roleNames() const { + QHash roles = QAbstractItemModel::roleNames(); + roles[EventTypeRole] = "eventType"; + roles[EventIdRole] = "eventId"; + roles[TimeRole] = "time"; + roles[AboveTimeRole] = "aboveTime"; + roles[SectionRole] = "section"; + roles[AboveSectionRole] = "aboveSection"; + roles[AuthorRole] = "author"; + roles[AboveAuthorRole] = "aboveAuthor"; + roles[ContentRole] = "content"; + roles[ContentTypeRole] = "contentType"; + roles[ReadMarkerRole] = "readMarker"; + roles[SpecialMarksRole] = "marks"; + roles[LongOperationRole] = "progressInfo"; + roles[EventResolvedTypeRole] = "eventResolvedType"; + return roles; +} MessageEventModel::MessageEventModel(QObject* parent) - : QAbstractListModel(parent) { + : QAbstractListModel(parent), m_currentRoom(nullptr) { qmlRegisterType(); qRegisterMetaType(); } @@ -122,7 +140,7 @@ inline bool hasValidTimestamp(const QMatrixClient::TimelineItem& ti) { } QDateTime MessageEventModel::makeMessageTimestamp( - QMatrixClient::Room::rev_iter_t baseIt) const { + const QMatrixClient::Room::rev_iter_t& baseIt) const { const auto& timeline = m_currentRoom->messageEvents(); auto ts = baseIt->event()->timestamp(); if (ts.isValid()) return ts; @@ -143,7 +161,7 @@ QDateTime MessageEventModel::makeMessageTimestamp( } QString MessageEventModel::makeDateString( - QMatrixClient::Room::rev_iter_t baseIt) const { + const QMatrixClient::Room::rev_iter_t& baseIt) const { auto date = makeMessageTimestamp(baseIt).toLocalTime().date(); if (QMatrixClient::SettingsGroup("UI") .value("banner_human_friendly_date", true) @@ -344,8 +362,6 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const { }; } - // HighlightRole is missing. This will be fixed soon. - if (role == ReadMarkerRole) return evt.id() == lastReadEventId; if (role == SpecialMarksRole) { @@ -393,23 +409,3 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const { return QVariant(); } - -QHash MessageEventModel::roleNames() const { - QHash roles = QAbstractItemModel::roleNames(); - roles[EventTypeRole] = "eventType"; - roles[EventIdRole] = "eventId"; - roles[TimeRole] = "time"; - roles[AboveTimeRole] = "aboveTime"; - roles[SectionRole] = "section"; - roles[AboveSectionRole] = "aboveSection"; - roles[AuthorRole] = "author"; - roles[AboveAuthorRole] = "aboveAuthor"; - roles[ContentRole] = "content"; - roles[ContentTypeRole] = "contentType"; - roles[HighlightRole] = "highlight"; - roles[ReadMarkerRole] = "readMarker"; - roles[SpecialMarksRole] = "marks"; - roles[LongOperationRole] = "progressInfo"; - roles[EventResolvedTypeRole] = "eventResolvedType"; - return roles; -} diff --git a/src/messageeventmodel.h b/src/messageeventmodel.h index 8351723..1e83fb4 100644 --- a/src/messageeventmodel.h +++ b/src/messageeventmodel.h @@ -49,8 +49,9 @@ class MessageEventModel : public QAbstractListModel { bool mergingEcho = 0; int nextNewerRow = -1; - QDateTime makeMessageTimestamp(QMatrixClient::Room::rev_iter_t baseIt) const; - QString makeDateString(QMatrixClient::Room::rev_iter_t baseIt) const; + QDateTime makeMessageTimestamp( + const QMatrixClient::Room::rev_iter_t& baseIt) const; + QString makeDateString(const QMatrixClient::Room::rev_iter_t& baseIt) const; void refreshEventRoles(const int row, const QVector& roles); void refreshEventRoles(const QString& eventId, const QVector& roles);