Add join room/create room/create direct chat && small bug fixes.

This commit is contained in:
Black Hat 2018-08-01 20:26:29 +08:00
parent 22ad70cc49
commit 5c606f1d5d
12 changed files with 148 additions and 51 deletions

View File

@ -16,7 +16,7 @@ Page {
parent: null
}
SettingAppearancePage {
SettingAppearanceForm {
id: appearanceForm
parent: null
}

View File

@ -21,8 +21,7 @@ AvatarContainer {
Image {
id: messageImage
z: -4
sourceSize.width: width
sourceSize.height: height
sourceSize.width: 128
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
MouseArea {

View File

@ -32,7 +32,6 @@ Item {
layer.enabled: true
fillMode: Image.PreserveAspectCrop
sourceSize.width: item.width
sourceSize.height: item.width
layer.effect: OpacityMask {
maskSource: Item {
@ -74,8 +73,8 @@ Item {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
for (var j = 0; j < 3; j++) {
var value = (hash >> (j * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;

View File

@ -42,7 +42,7 @@ AvatarContainer {
id: timeText
visible: Math.abs(time - aboveTime) > 600000 || index == 0
Layout.alignment: Qt.AlignRight
text: Qt.formatDateTime(time, "d MMM hh:mm")
text: Qt.formatTime(time, "hh:mm")
color: isNotice || sentByMe ? "grey" : "white"
font.pointSize: 8

View File

@ -5,36 +5,24 @@ import QtQuick.Controls.Material 2.2
Item {
id: messageDelegate
readonly property bool sentByMe: author === currentRoom.localUser
readonly property bool darkTheme: Material.theme == Material.Dark
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
width: delegateLoader.width
height: delegateLoader.height
anchors.right: !(eventType === "state" || eventType === "emote") && sentByMe ? parent.right : undefined
anchors.horizontalCenter: (eventType === "state" || eventType === "emote") ? parent.horizontalCenter : undefined
anchors.right: !isState && sentByMe ? parent.right : undefined
anchors.horizontalCenter: isState ? parent.horizontalCenter : undefined
Loader {
id: delegateLoader
source: {
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 ""
}
source: isMessage ? "MessageBubble.qml" : isState ? "StateBubble.qml" : isFile ? eventType === "image" ? "ImageBubble.qml" : "FileBubble.qml" : ""
}
}

View File

@ -219,7 +219,7 @@ Item {
}
MenuItem {
text: "Leave Room"
onTriggered: listModel.connection.forgetRoom(roomListMenu.room.id)
onTriggered: matriqueController.forgetRoom(roomListMenu.room.id)
}
}
}

View File

@ -17,7 +17,7 @@ ApplicationWindow {
visible: true
width: 960
height: 640
minimumWidth: 640
minimumWidth: 800
minimumHeight: 480
title: qsTr("Matrique")
@ -166,6 +166,94 @@ ApplicationWindow {
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 {
contentItem: MaterialIcon { icon: "\ue8b8"; color: "white" }
page: settingPage
@ -173,9 +261,7 @@ ApplicationWindow {
SideNavButton {
contentItem: MaterialIcon { icon: "\ue879"; color: "white" }
onClicked: {
Qt.quit();
}
onClicked: Qt.quit()
}
}
}

View File

@ -28,6 +28,6 @@
<file>qml/form/SettingForm.qml</file>
<file>qml/Setting.qml</file>
<file>qml/form/SettingAccountForm.qml</file>
<file>qml/form/SettingAppearancePage.qml</file>
<file>qml/form/SettingAppearanceForm.qml</file>
</qresource>
</RCC>

View File

@ -4,26 +4,25 @@
#include "events/eventcontent.h"
#include "events/roommessageevent.h"
#include "csapi/create_room.h"
#include "csapi/joining.h"
#include "csapi/leaving.h"
#include <QFile>
#include <QImage>
#include <QMimeDatabase>
Controller::Controller(QObject* parent) : QObject(parent) {
connect(m_connection, &Connection::connected, this,
&Controller::connected);
connect(m_connection, &Connection::connected, this, &Controller::connected);
connect(m_connection, &Connection::resolveError, this,
&Controller::reconnect);
connect(m_connection, &Connection::syncError, this,
&Controller::reconnect);
connect(m_connection, &Connection::syncDone, this,
&Controller::resync);
connect(m_connection, &Connection::syncError, this, &Controller::reconnect);
connect(m_connection, &Connection::syncDone, this, &Controller::resync);
connect(m_connection, &Connection::connected, this,
&Controller::connectionChanged);
connect(m_connection, &Connection::connected,
[=] { setBusy(true); });
connect(m_connection, &Connection::syncDone,
[=] { setBusy(false); });
connect(m_connection, &Connection::connected, [=] { setBusy(true); });
connect(m_connection, &Connection::syncDone, [=] { setBusy(false); });
}
Controller::~Controller() {
@ -52,6 +51,7 @@ void Controller::loginWithCredentials(QString serverAddr, QString user,
}
void Controller::logout() {
m_connection->logout();
setUserID("");
setToken("");
setIsLogin(false);
@ -66,10 +66,7 @@ void Controller::connected() {
setIsLogin(true);
}
void Controller::resync() {
m_connection->sync(30000);
m_connection->saveState();
}
void Controller::resync() { m_connection->sync(30000); }
void Controller::reconnect() {
qDebug() << "Connection lost. Reconnecting...";
@ -97,3 +94,29 @@ QString Controller::getMIME(const QUrl& fileUrl) const {
delete db;
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);
}

View File

@ -95,9 +95,12 @@ class Controller : public QObject {
void errorOccured();
public slots:
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;
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

View File

@ -9,6 +9,7 @@
#include "room.h"
#include "roomlistmodel.h"
#include "csapi/joining.h"
#include "csapi/leaving.h"
using namespace QMatrixClient;
@ -28,8 +29,6 @@ int main(int argc, char *argv[]) {
// QNetworkProxy::setApplicationProxy(proxy);
qRegisterMetaType<Room *>("Room*");
qRegisterMetaType<LeaveRoomJob *>("LeaveRoomJob*");
qRegisterMetaType<ForgetRoomJob *>("ForgetRoomJob*");
qRegisterMetaType<User *>("User*");