Update libqmatrixclient && add redact support(Incomplete) && cancel

maximumFlickVelocity && disable ListView bouncing.
This commit is contained in:
Black Hat 2018-08-04 20:40:23 +08:00
parent 84fcdacfd1
commit d1d7139f4b
8 changed files with 40 additions and 30 deletions

@ -1 +1 @@
Subproject commit 7298e99125522c4d010ec83052cd10ce085e09b4
Subproject commit 98751495f1990dccf285e3b4739f86de7b7f68fd

View File

@ -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

View File

@ -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 + "<font color='" + rainbowColor[i % 7] + "'>" + text.charAt(i) + "</font>"
}
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)
}
}

View File

@ -125,10 +125,11 @@ Item {
opacity: 0.2
}
highlightMoveDuration: 250
maximumFlickVelocity: 2048
currentIndex: -1
boundsBehavior: Flickable.DragOverBounds
ScrollBar.vertical: ScrollBar { id: scrollBar }
delegate: ItemDelegate {

View File

@ -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 {

View File

@ -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);

View File

@ -23,10 +23,12 @@ int main(int argc, char *argv[]) {
qRegisterMetaType<Room *>("Room*");
qRegisterMetaType<User *>("User*");
qRegisterMetaType<MessageEventType>("MessageEventType");
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
qmlRegisterType<MessageEventModel>("Matrique", 0, 1, "MessageEventModel");
qmlRegisterUncreatableType<RoomMessageEvent>("Matrique", 0, 1, "RoomMessageEvent", "ENUM");
QQmlApplicationEngine engine;

View File

@ -63,16 +63,16 @@ void RoomListModel::connectRoomSignals(Room* 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);
// });
// 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) {