From d1d7139f4bef9dc7bc2da97116bf7b0d83a22267 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sat, 4 Aug 2018 20:40:23 +0800 Subject: [PATCH] Update libqmatrixclient && add redact support(Incomplete) && cancel maximumFlickVelocity && disable ListView bouncing. --- include/libqmatrixclient | 2 +- qml/component/MessageDelegate.qml | 13 +++++++++++++ qml/form/RoomForm.qml | 15 ++++++++------- qml/form/RoomListForm.qml | 3 ++- src/controller.cpp | 8 +------- src/controller.h | 1 - src/main.cpp | 2 ++ src/roomlistmodel.cpp | 26 +++++++++++++------------- 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/include/libqmatrixclient b/include/libqmatrixclient index 7298e99..9875149 160000 --- a/include/libqmatrixclient +++ b/include/libqmatrixclient @@ -1 +1 @@ -Subproject commit 7298e99125522c4d010ec83052cd10ce085e09b4 +Subproject commit 98751495f1990dccf285e3b4739f86de7b7f68fd diff --git a/qml/component/MessageDelegate.qml b/qml/component/MessageDelegate.qml index c8baba7..e77210a 100644 --- a/qml/component/MessageDelegate.qml +++ b/qml/component/MessageDelegate.qml @@ -22,6 +22,19 @@ Item { anchors.right: !isState && sentByMe ? parent.right : undefined anchors.horizontalCenter: isState ? parent.horizontalCenter : undefined + MouseArea { + anchors.fill: parent + onPressAndHold: messageContextMenu.popup() + + Menu { + id: messageContextMenu + MenuItem { + text: "Redact" + onTriggered: currentRoom.redactEvent(eventId) + } + } + } + Loader { id: delegateLoader diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index bd54d24..4d4d2f0 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -86,9 +86,10 @@ Item { displayMarginBeginning: 40 displayMarginEnd: 40 verticalLayoutDirection: ListView.BottomToTop - maximumFlickVelocity: 1024 spacing: 8 + boundsBehavior: Flickable.DragOverBounds + model: MessageEventModel{ id: messageEventModel room: currentRoom @@ -230,12 +231,12 @@ Item { if (text.indexOf(PREFIX_ME) === 0) { text = text.substr(PREFIX_ME.length) - matriqueController.postMessage(currentRoom, "m.emote", text) + currentRoom.postMessage(text, RoomMessageEvent.Emote) return } if (text.indexOf(PREFIX_NOTICE) === 0) { text = text.substr(PREFIX_NOTICE.length) - matriqueController.postMessage(currentRoom, "m.notice", text) + currentRoom.postMessage(text, RoomMessageEvent.Notice) return } if (text.indexOf(PREFIX_RAINBOW) === 0) { @@ -246,24 +247,24 @@ Item { for (var i = 0; i < text.length; i++) { parsedText = parsedText + "" + text.charAt(i) + "" } - currentRoom.postHtmlMessage(text, parsedText) + currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.Text) return } if (text.indexOf(PREFIX_HTML) === 0) { text = text.substr(PREFIX_HTML.length) var re = new RegExp("<.*?>") var plainText = text.replace(re, "") - currentRoom.postHtmlMessage(plainText, text, "m.text") + currentRoom.postHtmlMessage(plainText, text, RoomMessageEvent.Text) return } if (text.indexOf(PREFIX_MARKDOWN) === 0) { text = text.substr(PREFIX_MARKDOWN.length) var parsedText = Markdown.markdown_parser(text) - currentRoom.postHtmlMessage(text, parsedText) + currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.Text) return } - matriqueController.postMessage(currentRoom, "m.text", text) + currentRoom.postPlainText(text) } } diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml index 5c551b8..bb4b76f 100644 --- a/qml/form/RoomListForm.qml +++ b/qml/form/RoomListForm.qml @@ -125,10 +125,11 @@ Item { opacity: 0.2 } highlightMoveDuration: 250 - maximumFlickVelocity: 2048 currentIndex: -1 + boundsBehavior: Flickable.DragOverBounds + ScrollBar.vertical: ScrollBar { id: scrollBar } delegate: ItemDelegate { diff --git a/src/controller.cpp b/src/controller.cpp index 613d632..87aab58 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -73,12 +73,6 @@ void Controller::reconnect() { m_connection->connectWithToken(userID, token, ""); } -void Controller::postMessage(Room* room, const QString& type, - const QString& text) { - room->postMessage("m.room.message", - QJsonObject{{"msgtype", type}, {"body", text}}); -} - void Controller::postFile(Room* room, const QUrl& localFile, const QUrl& mxcUrl) { const QString mime = getMIME(localFile); @@ -91,7 +85,7 @@ void Controller::postFile(Room* room, const QUrl& localFile, {"body", fileName}, {"filename", fileName}, {"url", mxcUrl.url()}}}; - room->postMessage("m.room.message", json); + room->postJson("m.room.message", json); } QString Controller::getMIME(const QUrl& fileUrl) const { diff --git a/src/controller.h b/src/controller.h index fbdfae1..563c010 100644 --- a/src/controller.h +++ b/src/controller.h @@ -95,7 +95,6 @@ class Controller : public QObject { void errorOccured(); public slots: - void postMessage(Room* room, const QString& type, const QString& text); void postFile(Room* room, const QUrl& localFile, const QUrl& mxcUrl); QString getMIME(const QUrl& fileUrl) const; void forgetRoom(const QString& roomID); diff --git a/src/main.cpp b/src/main.cpp index 0021fb8..7207e10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,10 +23,12 @@ int main(int argc, char *argv[]) { qRegisterMetaType("Room*"); qRegisterMetaType("User*"); + qRegisterMetaType("MessageEventType"); qmlRegisterType("Matrique", 0, 1, "Controller"); qmlRegisterType("Matrique", 0, 1, "RoomListModel"); qmlRegisterType("Matrique", 0, 1, "MessageEventModel"); + qmlRegisterUncreatableType("Matrique", 0, 1, "RoomMessageEvent", "ENUM"); QQmlApplicationEngine engine; diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index 86e707a..b6eeb30 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -60,19 +60,19 @@ void RoomListModel::connectRoomSignals(Room* room) { connect(room, &Room::avatarChanged, this, [=] { refresh(room, {AvatarRole}); }); - connect(room, &Room::unreadMessagesChanged, this, [=](Room* r) { - if (r->hasUnreadMessages()) emit newMessage(r); - }); - // connect( - // room, &QMatrixClient::Room::aboutToAddNewMessages, this, - // [=](QMatrixClient::RoomEventsRange eventsRange) { - // for (QMatrixClient::RoomEvents events : eventsRange.const_iterator) { - // for (QMatrixClient::RoomEvent event : events) { - // qDebug() << event.fullJson(); - // } - // } - // emit newMessage(room); - // }); + connect(room, &Room::unreadMessagesChanged, this, [=](Room* r) { + if (r->hasUnreadMessages()) emit newMessage(r); + }); +// connect( +// room, &QMatrixClient::Room::aboutToAddNewMessages, this, +// [=](QMatrixClient::RoomEventsRange eventsRange) { +// for (QMatrixClient::RoomEvents events : eventsRange.const_iterator) { +// for (QMatrixClient::RoomEvent event : events) { +// qDebug() << event.fullJson(); +// } +// } +// emit newMessage(room); +// }); } void RoomListModel::updateRoom(Room* room, Room* prev) {