Add join room/create room/create direct chat && small bug fixes.
This commit is contained in:
parent
22ad70cc49
commit
5c606f1d5d
|
@ -16,7 +16,7 @@ Page {
|
||||||
parent: null
|
parent: null
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingAppearancePage {
|
SettingAppearanceForm {
|
||||||
id: appearanceForm
|
id: appearanceForm
|
||||||
parent: null
|
parent: null
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ AvatarContainer {
|
||||||
Image {
|
Image {
|
||||||
id: messageImage
|
id: messageImage
|
||||||
z: -4
|
z: -4
|
||||||
sourceSize.width: width
|
sourceSize.width: 128
|
||||||
sourceSize.height: height
|
|
||||||
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
|
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
|
|
@ -32,7 +32,6 @@ Item {
|
||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
fillMode: Image.PreserveAspectCrop
|
fillMode: Image.PreserveAspectCrop
|
||||||
sourceSize.width: item.width
|
sourceSize.width: item.width
|
||||||
sourceSize.height: item.width
|
|
||||||
|
|
||||||
layer.effect: OpacityMask {
|
layer.effect: OpacityMask {
|
||||||
maskSource: Item {
|
maskSource: Item {
|
||||||
|
@ -74,8 +73,8 @@ Item {
|
||||||
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
||||||
}
|
}
|
||||||
var colour = '#';
|
var colour = '#';
|
||||||
for (var i = 0; i < 3; i++) {
|
for (var j = 0; j < 3; j++) {
|
||||||
var value = (hash >> (i * 8)) & 0xFF;
|
var value = (hash >> (j * 8)) & 0xFF;
|
||||||
colour += ('00' + value.toString(16)).substr(-2);
|
colour += ('00' + value.toString(16)).substr(-2);
|
||||||
}
|
}
|
||||||
return colour;
|
return colour;
|
||||||
|
|
|
@ -42,7 +42,7 @@ AvatarContainer {
|
||||||
id: timeText
|
id: timeText
|
||||||
visible: Math.abs(time - aboveTime) > 600000 || index == 0
|
visible: Math.abs(time - aboveTime) > 600000 || index == 0
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
text: Qt.formatDateTime(time, "d MMM hh:mm")
|
text: Qt.formatTime(time, "hh:mm")
|
||||||
color: isNotice || sentByMe ? "grey" : "white"
|
color: isNotice || sentByMe ? "grey" : "white"
|
||||||
font.pointSize: 8
|
font.pointSize: 8
|
||||||
|
|
||||||
|
|
|
@ -5,36 +5,24 @@ import QtQuick.Controls.Material 2.2
|
||||||
Item {
|
Item {
|
||||||
id: messageDelegate
|
id: messageDelegate
|
||||||
|
|
||||||
readonly property bool sentByMe: author === currentRoom.localUser
|
|
||||||
readonly property bool darkTheme: Material.theme == Material.Dark
|
readonly property bool darkTheme: Material.theme == Material.Dark
|
||||||
readonly property color background: darkTheme ? "#242424" : "lightgrey"
|
readonly property color background: darkTheme ? "#242424" : "lightgrey"
|
||||||
|
|
||||||
|
readonly property bool sentByMe: author === currentRoom.localUser
|
||||||
|
readonly property bool isState: eventType === "state" || eventType === "emote"
|
||||||
|
readonly property bool isMessage: eventType === "message" || eventType === "notice"
|
||||||
|
readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image"
|
||||||
|
|
||||||
z: -5
|
z: -5
|
||||||
width: delegateLoader.width
|
width: delegateLoader.width
|
||||||
height: delegateLoader.height
|
height: delegateLoader.height
|
||||||
|
|
||||||
anchors.right: !(eventType === "state" || eventType === "emote") && sentByMe ? parent.right : undefined
|
anchors.right: !isState && sentByMe ? parent.right : undefined
|
||||||
anchors.horizontalCenter: (eventType === "state" || eventType === "emote") ? parent.horizontalCenter : undefined
|
anchors.horizontalCenter: isState ? parent.horizontalCenter : undefined
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: delegateLoader
|
id: delegateLoader
|
||||||
|
|
||||||
source: {
|
source: isMessage ? "MessageBubble.qml" : isState ? "StateBubble.qml" : isFile ? eventType === "image" ? "ImageBubble.qml" : "FileBubble.qml" : ""
|
||||||
switch (eventType) {
|
|
||||||
case "notice":
|
|
||||||
case "message":
|
|
||||||
return "MessageBubble.qml"
|
|
||||||
case "image":
|
|
||||||
return "ImageBubble.qml"
|
|
||||||
case "emote":
|
|
||||||
case "state":
|
|
||||||
return "StateBubble.qml"
|
|
||||||
case "video":
|
|
||||||
case "audio":
|
|
||||||
case "file":
|
|
||||||
return "FileBubble.qml"
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,7 @@ Item {
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: "Leave Room"
|
text: "Leave Room"
|
||||||
onTriggered: listModel.connection.forgetRoom(roomListMenu.room.id)
|
onTriggered: matriqueController.forgetRoom(roomListMenu.room.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
94
qml/main.qml
94
qml/main.qml
|
@ -17,7 +17,7 @@ ApplicationWindow {
|
||||||
visible: true
|
visible: true
|
||||||
width: 960
|
width: 960
|
||||||
height: 640
|
height: 640
|
||||||
minimumWidth: 640
|
minimumWidth: 800
|
||||||
minimumHeight: 480
|
minimumHeight: 480
|
||||||
title: qsTr("Matrique")
|
title: qsTr("Matrique")
|
||||||
|
|
||||||
|
@ -166,6 +166,94 @@ ApplicationWindow {
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SideNavButton {
|
||||||
|
contentItem: MaterialIcon { icon: "\ue145"; color: "white" }
|
||||||
|
onClicked: addRoomMenu.popup()
|
||||||
|
|
||||||
|
Menu {
|
||||||
|
id: addRoomMenu
|
||||||
|
MenuItem {
|
||||||
|
text:"New Room"
|
||||||
|
onTriggered: addRoomDialog.open()
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: addRoomDialog
|
||||||
|
parent: ApplicationWindow.overlay
|
||||||
|
|
||||||
|
x: (window.width - width) / 2
|
||||||
|
y: (window.height - height) / 2
|
||||||
|
width: 360
|
||||||
|
|
||||||
|
title: "New Room"
|
||||||
|
modal: true
|
||||||
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
|
||||||
|
contentItem: Column {
|
||||||
|
TextField {
|
||||||
|
id: addRoomDialogNameTextField
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
|
placeholderText: "Name"
|
||||||
|
}
|
||||||
|
TextField {
|
||||||
|
id: addRoomDialogTopicTextField
|
||||||
|
width: parent.width
|
||||||
|
placeholderText: "Topic"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccepted: matriqueController.createRoom(addRoomDialogNameTextField.text, addRoomDialogTopicTextField.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: "Join Room"
|
||||||
|
onTriggered: joinRoomDialog.open()
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: joinRoomDialog
|
||||||
|
parent: ApplicationWindow.overlay
|
||||||
|
|
||||||
|
x: (window.width - width) / 2
|
||||||
|
y: (window.height - height) / 2
|
||||||
|
width: 360
|
||||||
|
|
||||||
|
title: "Input Room Alias or ID"
|
||||||
|
modal: true
|
||||||
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
|
||||||
|
contentItem: TextField {
|
||||||
|
id: joinRoomDialogTextField
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccepted: matriqueController.joinRoom(joinRoomDialogTextField.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: "Direct Chat"
|
||||||
|
onTriggered: directChatDialog.open()
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: directChatDialog
|
||||||
|
parent: ApplicationWindow.overlay
|
||||||
|
|
||||||
|
x: (window.width - width) / 2
|
||||||
|
y: (window.height - height) / 2
|
||||||
|
width: 360
|
||||||
|
|
||||||
|
title: "Input User ID"
|
||||||
|
modal: true
|
||||||
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
|
||||||
|
contentItem: TextField {
|
||||||
|
id: directChatDialogTextField
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccepted: matriqueController.createDirectChat(directChatDialogTextField.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SideNavButton {
|
SideNavButton {
|
||||||
contentItem: MaterialIcon { icon: "\ue8b8"; color: "white" }
|
contentItem: MaterialIcon { icon: "\ue8b8"; color: "white" }
|
||||||
page: settingPage
|
page: settingPage
|
||||||
|
@ -173,9 +261,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
SideNavButton {
|
SideNavButton {
|
||||||
contentItem: MaterialIcon { icon: "\ue879"; color: "white" }
|
contentItem: MaterialIcon { icon: "\ue879"; color: "white" }
|
||||||
onClicked: {
|
onClicked: Qt.quit()
|
||||||
Qt.quit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
res.qrc
2
res.qrc
|
@ -28,6 +28,6 @@
|
||||||
<file>qml/form/SettingForm.qml</file>
|
<file>qml/form/SettingForm.qml</file>
|
||||||
<file>qml/Setting.qml</file>
|
<file>qml/Setting.qml</file>
|
||||||
<file>qml/form/SettingAccountForm.qml</file>
|
<file>qml/form/SettingAccountForm.qml</file>
|
||||||
<file>qml/form/SettingAppearancePage.qml</file>
|
<file>qml/form/SettingAppearanceForm.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -4,26 +4,25 @@
|
||||||
#include "events/eventcontent.h"
|
#include "events/eventcontent.h"
|
||||||
#include "events/roommessageevent.h"
|
#include "events/roommessageevent.h"
|
||||||
|
|
||||||
|
#include "csapi/create_room.h"
|
||||||
|
#include "csapi/joining.h"
|
||||||
|
#include "csapi/leaving.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
|
|
||||||
Controller::Controller(QObject* parent) : QObject(parent) {
|
Controller::Controller(QObject* parent) : QObject(parent) {
|
||||||
connect(m_connection, &Connection::connected, this,
|
connect(m_connection, &Connection::connected, this, &Controller::connected);
|
||||||
&Controller::connected);
|
|
||||||
connect(m_connection, &Connection::resolveError, this,
|
connect(m_connection, &Connection::resolveError, this,
|
||||||
&Controller::reconnect);
|
&Controller::reconnect);
|
||||||
connect(m_connection, &Connection::syncError, this,
|
connect(m_connection, &Connection::syncError, this, &Controller::reconnect);
|
||||||
&Controller::reconnect);
|
connect(m_connection, &Connection::syncDone, this, &Controller::resync);
|
||||||
connect(m_connection, &Connection::syncDone, this,
|
|
||||||
&Controller::resync);
|
|
||||||
connect(m_connection, &Connection::connected, this,
|
connect(m_connection, &Connection::connected, this,
|
||||||
&Controller::connectionChanged);
|
&Controller::connectionChanged);
|
||||||
|
|
||||||
connect(m_connection, &Connection::connected,
|
connect(m_connection, &Connection::connected, [=] { setBusy(true); });
|
||||||
[=] { setBusy(true); });
|
connect(m_connection, &Connection::syncDone, [=] { setBusy(false); });
|
||||||
connect(m_connection, &Connection::syncDone,
|
|
||||||
[=] { setBusy(false); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller::~Controller() {
|
Controller::~Controller() {
|
||||||
|
@ -52,6 +51,7 @@ void Controller::loginWithCredentials(QString serverAddr, QString user,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::logout() {
|
void Controller::logout() {
|
||||||
|
m_connection->logout();
|
||||||
setUserID("");
|
setUserID("");
|
||||||
setToken("");
|
setToken("");
|
||||||
setIsLogin(false);
|
setIsLogin(false);
|
||||||
|
@ -66,10 +66,7 @@ void Controller::connected() {
|
||||||
setIsLogin(true);
|
setIsLogin(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::resync() {
|
void Controller::resync() { m_connection->sync(30000); }
|
||||||
m_connection->sync(30000);
|
|
||||||
m_connection->saveState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::reconnect() {
|
void Controller::reconnect() {
|
||||||
qDebug() << "Connection lost. Reconnecting...";
|
qDebug() << "Connection lost. Reconnecting...";
|
||||||
|
@ -97,3 +94,29 @@ QString Controller::getMIME(const QUrl& fileUrl) const {
|
||||||
delete db;
|
delete db;
|
||||||
return mime;
|
return mime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Controller::forgetRoom(const QString& roomID) {
|
||||||
|
ForgetRoomJob* forgetRoomJob = m_connection->forgetRoom(roomID);
|
||||||
|
setBusy(true);
|
||||||
|
forgetRoomJob->connect(forgetRoomJob, &ForgetRoomJob::finished,
|
||||||
|
[=] { setBusy(false); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::joinRoom(const QString& alias) {
|
||||||
|
JoinRoomJob* joinRoomJob = m_connection->joinRoom(alias);
|
||||||
|
setBusy(true);
|
||||||
|
joinRoomJob->connect(joinRoomJob, &JoinRoomJob::finished,
|
||||||
|
[=] { setBusy(false); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::createRoom(const QString& name, const QString& topic) {
|
||||||
|
CreateRoomJob* createRoomJob = m_connection->createRoom(
|
||||||
|
Connection::PublishRoom, "", name, topic, QStringList());
|
||||||
|
setBusy(true);
|
||||||
|
createRoomJob->connect(createRoomJob, &CreateRoomJob::finished,
|
||||||
|
[=] { setBusy(false); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::createDirectChat(const QString& userID) {
|
||||||
|
m_connection->requestDirectChat(userID);
|
||||||
|
}
|
||||||
|
|
|
@ -95,9 +95,12 @@ class Controller : public QObject {
|
||||||
void errorOccured();
|
void errorOccured();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void postFile(Room* room, const QUrl& localFile,
|
void postFile(Room* room, const QUrl& localFile, const QUrl& mxcUrl);
|
||||||
const QUrl& mxcUrl);
|
|
||||||
QString getMIME(const QUrl& fileUrl) const;
|
QString getMIME(const QUrl& fileUrl) const;
|
||||||
|
void forgetRoom(const QString& roomID);
|
||||||
|
void joinRoom(const QString& alias);
|
||||||
|
void createRoom(const QString& name, const QString& topic);
|
||||||
|
void createDirectChat(const QString& userID);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTROLLER_H
|
#endif // CONTROLLER_H
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
|
|
||||||
|
#include "csapi/joining.h"
|
||||||
#include "csapi/leaving.h"
|
#include "csapi/leaving.h"
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
using namespace QMatrixClient;
|
||||||
|
@ -28,8 +29,6 @@ int main(int argc, char *argv[]) {
|
||||||
// QNetworkProxy::setApplicationProxy(proxy);
|
// QNetworkProxy::setApplicationProxy(proxy);
|
||||||
|
|
||||||
qRegisterMetaType<Room *>("Room*");
|
qRegisterMetaType<Room *>("Room*");
|
||||||
qRegisterMetaType<LeaveRoomJob *>("LeaveRoomJob*");
|
|
||||||
qRegisterMetaType<ForgetRoomJob *>("ForgetRoomJob*");
|
|
||||||
|
|
||||||
qRegisterMetaType<User *>("User*");
|
qRegisterMetaType<User *>("User*");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue