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.right: !isState && sentByMe ? parent.right : undefined
anchors.horizontalCenter: isState ? parent.horizontalCenter : 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 { Loader {
id: delegateLoader id: delegateLoader

View File

@ -86,9 +86,10 @@ Item {
displayMarginBeginning: 40 displayMarginBeginning: 40
displayMarginEnd: 40 displayMarginEnd: 40
verticalLayoutDirection: ListView.BottomToTop verticalLayoutDirection: ListView.BottomToTop
maximumFlickVelocity: 1024
spacing: 8 spacing: 8
boundsBehavior: Flickable.DragOverBounds
model: MessageEventModel{ model: MessageEventModel{
id: messageEventModel id: messageEventModel
room: currentRoom room: currentRoom
@ -230,12 +231,12 @@ Item {
if (text.indexOf(PREFIX_ME) === 0) { if (text.indexOf(PREFIX_ME) === 0) {
text = text.substr(PREFIX_ME.length) text = text.substr(PREFIX_ME.length)
matriqueController.postMessage(currentRoom, "m.emote", text) currentRoom.postMessage(text, RoomMessageEvent.Emote)
return return
} }
if (text.indexOf(PREFIX_NOTICE) === 0) { if (text.indexOf(PREFIX_NOTICE) === 0) {
text = text.substr(PREFIX_NOTICE.length) text = text.substr(PREFIX_NOTICE.length)
matriqueController.postMessage(currentRoom, "m.notice", text) currentRoom.postMessage(text, RoomMessageEvent.Notice)
return return
} }
if (text.indexOf(PREFIX_RAINBOW) === 0) { if (text.indexOf(PREFIX_RAINBOW) === 0) {
@ -246,24 +247,24 @@ Item {
for (var i = 0; i < text.length; i++) { for (var i = 0; i < text.length; i++) {
parsedText = parsedText + "<font color='" + rainbowColor[i % 7] + "'>" + text.charAt(i) + "</font>" parsedText = parsedText + "<font color='" + rainbowColor[i % 7] + "'>" + text.charAt(i) + "</font>"
} }
currentRoom.postHtmlMessage(text, parsedText) currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.Text)
return return
} }
if (text.indexOf(PREFIX_HTML) === 0) { if (text.indexOf(PREFIX_HTML) === 0) {
text = text.substr(PREFIX_HTML.length) text = text.substr(PREFIX_HTML.length)
var re = new RegExp("<.*?>") var re = new RegExp("<.*?>")
var plainText = text.replace(re, "") var plainText = text.replace(re, "")
currentRoom.postHtmlMessage(plainText, text, "m.text") currentRoom.postHtmlMessage(plainText, text, RoomMessageEvent.Text)
return return
} }
if (text.indexOf(PREFIX_MARKDOWN) === 0) { if (text.indexOf(PREFIX_MARKDOWN) === 0) {
text = text.substr(PREFIX_MARKDOWN.length) text = text.substr(PREFIX_MARKDOWN.length)
var parsedText = Markdown.markdown_parser(text) var parsedText = Markdown.markdown_parser(text)
currentRoom.postHtmlMessage(text, parsedText) currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.Text)
return return
} }
matriqueController.postMessage(currentRoom, "m.text", text) currentRoom.postPlainText(text)
} }
} }

View File

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

View File

@ -73,12 +73,6 @@ void Controller::reconnect() {
m_connection->connectWithToken(userID, token, ""); 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, void Controller::postFile(Room* room, const QUrl& localFile,
const QUrl& mxcUrl) { const QUrl& mxcUrl) {
const QString mime = getMIME(localFile); const QString mime = getMIME(localFile);
@ -91,7 +85,7 @@ void Controller::postFile(Room* room, const QUrl& localFile,
{"body", fileName}, {"body", fileName},
{"filename", fileName}, {"filename", fileName},
{"url", mxcUrl.url()}}}; {"url", mxcUrl.url()}}};
room->postMessage("m.room.message", json); room->postJson("m.room.message", json);
} }
QString Controller::getMIME(const QUrl& fileUrl) const { QString Controller::getMIME(const QUrl& fileUrl) const {

View File

@ -95,7 +95,6 @@ class Controller : public QObject {
void errorOccured(); void errorOccured();
public slots: public slots:
void postMessage(Room* room, const QString& type, const QString& text);
void postFile(Room* room, const QUrl& localFile, const QUrl& mxcUrl); void postFile(Room* room, const QUrl& localFile, const QUrl& mxcUrl);
QString getMIME(const QUrl& fileUrl) const; QString getMIME(const QUrl& fileUrl) const;
void forgetRoom(const QString& roomID); void forgetRoom(const QString& roomID);

View File

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

View File

@ -60,19 +60,19 @@ void RoomListModel::connectRoomSignals(Room* room) {
connect(room, &Room::avatarChanged, this, connect(room, &Room::avatarChanged, this,
[=] { refresh(room, {AvatarRole}); }); [=] { refresh(room, {AvatarRole}); });
connect(room, &Room::unreadMessagesChanged, this, [=](Room* r) { connect(room, &Room::unreadMessagesChanged, this, [=](Room* r) {
if (r->hasUnreadMessages()) emit newMessage(r); if (r->hasUnreadMessages()) emit newMessage(r);
}); });
// connect( // connect(
// room, &QMatrixClient::Room::aboutToAddNewMessages, this, // room, &QMatrixClient::Room::aboutToAddNewMessages, this,
// [=](QMatrixClient::RoomEventsRange eventsRange) { // [=](QMatrixClient::RoomEventsRange eventsRange) {
// for (QMatrixClient::RoomEvents events : eventsRange.const_iterator) { // for (QMatrixClient::RoomEvents events : eventsRange.const_iterator) {
// for (QMatrixClient::RoomEvent event : events) { // for (QMatrixClient::RoomEvent event : events) {
// qDebug() << event.fullJson(); // qDebug() << event.fullJson();
// } // }
// } // }
// emit newMessage(room); // emit newMessage(room);
// }); // });
} }
void RoomListModel::updateRoom(Room* room, Room* prev) { void RoomListModel::updateRoom(Room* room, Room* prev) {