Merge branch 'dev'

This merge updates libqmatrixclient to latest version and fixes bugs caused by the update.
This commit is contained in:
Black Hat 2018-08-03 21:14:24 +08:00
commit ab8dbc4e29
10 changed files with 111 additions and 59 deletions

View File

@ -1,26 +1,60 @@
stages: stages:
- preparation
- build - build
- deploy
preparation-flatpak:
image: debian:latest
stage: preparation
before_script:
- mkdir -p tmp
- apt-get update
- apt-get install -y git
script:
- cd tmp
- git clone "https://$GIT_USERNAME:$GIT_PASSWORD@gitlab.com/b0/matrique-repo"
- cd ../
artifacts:
paths:
- tmp/
build-native: build-native:
image: rabits/qt:5.11-desktop image: rabits/qt:5.11-desktop
stage: build stage: build
cache: {}
before_script: before_script:
- git submodule update --init --recursive - git submodule update --init --recursive
script: script:
- mkdir build && cd build - mkdir -p build && cd build
- qmake ../matrique.pro -spec linux-g++ CONFIG+=qtquickcompiler - qmake ../matrique.pro -spec linux-g++ CONFIG+=qtquickcompiler
- make -j4 - make -j4
build-flatpak:
image: black0/flatpak
stage: build
before_script:
- git submodule update --init --recursive
script:
- gpg2 -v --import <(echo "$GPG_SECRET_KEY")
- cd flatpak
- flatpak-builder --repo=../tmp/matrique-repo/public build-dir org.eu.encom.matrique.json --force-clean --gpg-sign=52986BF4D61350EC249F2E891B0DB3358FC5E4B2
- cd ../
artifacts: artifacts:
paths: paths:
- build/ - tmp/
build-flatpak: deploy-flatpak:
image: fedora:latest only:
stage: build - master
before-script: dnf install flatpak image: debian:latest
stage: deploy
before_script:
- apt-get update
- apt-get install -y git
- git config --global user.name "$GIT_NAME"
- git config --global user.email "$GIT_EMAIL"
script: script:
- flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub - cd tmp/matrique-repo
- flatpak install flathub org.kde.Platform//5.11 - git add -A
- gpg2 -v --import <(echo $GPG_SECRET_KEY) - git commit -m "$CI_COMMIT_MESSAGE"
- git push origin master

@ -1 +1 @@
Subproject commit dc3acd336e30a17d6b5d0cbe6cde2838737c9030 Subproject commit 7298e99125522c4d010ec83052cd10ce085e09b4

View File

@ -28,12 +28,25 @@ AvatarContainer {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
propagateComposedEvents: true propagateComposedEvents: true
ToolTip.visible: containsMouse ToolTip.visible: containsMouse
ToolTip.text: content.body ToolTip.text: content.body
onClicked: mouse.button & Qt.LeftButton ? downloadable.downloadAndOpen() : downloadable.saveFileAs() onClicked: downloadable.downloadAndOpen()
onPressAndHold: messageImageMenu.popup()
}
Menu {
id: messageImageMenu
MenuItem {
text: "View"
onTriggered: downloadable.downloadAndOpen()
}
MenuItem {
text: "Save as..."
onTriggered: downloadable.saveFileAs()
}
} }
} }
} }

View File

@ -13,6 +13,8 @@ Item {
readonly property bool isMessage: eventType === "message" || eventType === "notice" readonly property bool isMessage: eventType === "message" || eventType === "notice"
readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image" readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image"
visible: eventType != "redaction"
z: -5 z: -5
width: delegateLoader.width width: delegateLoader.width
height: delegateLoader.height height: delegateLoader.height
@ -23,6 +25,6 @@ Item {
Loader { Loader {
id: delegateLoader 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" : "" : ""
} }
} }

View File

@ -230,12 +230,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)
currentRoom.postMessage("m.emote", text) matriqueController.postMessage(currentRoom, "m.emote", text)
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)
currentRoom.postMessage("m.notice", text) matriqueController.postMessage(currentRoom, "m.notice", text)
return return
} }
if (text.indexOf(PREFIX_RAINBOW) === 0) { if (text.indexOf(PREFIX_RAINBOW) === 0) {
@ -246,7 +246,7 @@ 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, "m.text") currentRoom.postHtmlMessage(text, parsedText)
return return
} }
if (text.indexOf(PREFIX_HTML) === 0) { if (text.indexOf(PREFIX_HTML) === 0) {
@ -259,11 +259,11 @@ Item {
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, "m.text") currentRoom.postHtmlMessage(text, parsedText)
return return
} }
currentRoom.postMessage("m.text", text) matriqueController.postMessage(currentRoom, "m.text", text)
} }
} }

View File

@ -73,10 +73,16 @@ 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);
const QString fileName = localFile.toLocalFile(); const QString fileName = localFile.fileName();
QString msgType = "m.file"; QString msgType = "m.file";
if (mime.startsWith("image")) msgType = "m.image"; if (mime.startsWith("image")) msgType = "m.image";
if (mime.startsWith("video")) msgType = "m.video"; if (mime.startsWith("video")) msgType = "m.video";

View File

@ -95,6 +95,7 @@ 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

@ -22,7 +22,6 @@ int main(int argc, char *argv[]) {
QApplication app(argc, argv); QApplication app(argc, argv);
qRegisterMetaType<Room *>("Room*"); qRegisterMetaType<Room *>("Room*");
qRegisterMetaType<User *>("User*"); qRegisterMetaType<User *>("User*");
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller"); qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");

View File

@ -4,17 +4,35 @@
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtQml> // for qmlRegisterType() #include <QtQml> // for qmlRegisterType()
#include "events/redactionevent.h" #include <connection.h>
#include "events/roomavatarevent.h" #include <events/redactionevent.h>
#include "events/roommemberevent.h" #include <events/roomavatarevent.h>
#include "events/simplestateevents.h" #include <events/roommemberevent.h>
#include <events/simplestateevents.h>
#include <settings.h>
#include <user.h>
#include "connection.h" QHash<int, QByteArray> MessageEventModel::roleNames() const {
#include "settings.h" QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
#include "user.h" 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) MessageEventModel::MessageEventModel(QObject* parent)
: QAbstractListModel(parent) { : QAbstractListModel(parent), m_currentRoom(nullptr) {
qmlRegisterType<QMatrixClient::FileTransferInfo>(); qmlRegisterType<QMatrixClient::FileTransferInfo>();
qRegisterMetaType<QMatrixClient::FileTransferInfo>(); qRegisterMetaType<QMatrixClient::FileTransferInfo>();
} }
@ -122,7 +140,7 @@ inline bool hasValidTimestamp(const QMatrixClient::TimelineItem& ti) {
} }
QDateTime MessageEventModel::makeMessageTimestamp( QDateTime MessageEventModel::makeMessageTimestamp(
QMatrixClient::Room::rev_iter_t baseIt) const { const QMatrixClient::Room::rev_iter_t& baseIt) const {
const auto& timeline = m_currentRoom->messageEvents(); const auto& timeline = m_currentRoom->messageEvents();
auto ts = baseIt->event()->timestamp(); auto ts = baseIt->event()->timestamp();
if (ts.isValid()) return ts; if (ts.isValid()) return ts;
@ -143,7 +161,7 @@ QDateTime MessageEventModel::makeMessageTimestamp(
} }
QString MessageEventModel::makeDateString( QString MessageEventModel::makeDateString(
QMatrixClient::Room::rev_iter_t baseIt) const { const QMatrixClient::Room::rev_iter_t& baseIt) const {
auto date = makeMessageTimestamp(baseIt).toLocalTime().date(); auto date = makeMessageTimestamp(baseIt).toLocalTime().date();
if (QMatrixClient::SettingsGroup("UI") if (QMatrixClient::SettingsGroup("UI")
.value("banner_human_friendly_date", true) .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 == ReadMarkerRole) return evt.id() == lastReadEventId;
if (role == SpecialMarksRole) { if (role == SpecialMarksRole) {
@ -393,23 +409,3 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const {
return QVariant(); return QVariant();
} }
QHash<int, QByteArray> MessageEventModel::roleNames() const {
QHash<int, QByteArray> 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;
}

View File

@ -49,8 +49,9 @@ class MessageEventModel : public QAbstractListModel {
bool mergingEcho = 0; bool mergingEcho = 0;
int nextNewerRow = -1; int nextNewerRow = -1;
QDateTime makeMessageTimestamp(QMatrixClient::Room::rev_iter_t baseIt) const; QDateTime makeMessageTimestamp(
QString makeDateString(QMatrixClient::Room::rev_iter_t baseIt) const; 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<int>& roles); void refreshEventRoles(const int row, const QVector<int>& roles);
void refreshEventRoles(const QString& eventId, const QVector<int>& roles); void refreshEventRoles(const QString& eventId, const QVector<int>& roles);