Move dialogs into a separate dir and create them dynamically.

Add "ignore user".
Update libqmatrixclient.
This commit is contained in:
Black Hat 2019-04-26 19:59:01 +08:00
parent 6a2f0c2105
commit 5ae1d41e92
23 changed files with 766 additions and 482 deletions

View File

@ -9,6 +9,7 @@ import Spectral 0.1
import Spectral.Setting 0.1
import Spectral.Component 2.0
import Spectral.Dialog 2.0
import Spectral.Font 0.1
ColumnLayout {
@ -111,16 +112,19 @@ ColumnLayout {
onSecondaryClicked: messageContextMenu.popup()
Component {
id: messageSourceDialog
MessageSourceDialog {}
}
Menu {
id: messageContextMenu
MenuItem {
text: "View Source"
onTriggered: {
sourceDialog.sourceText = toolTip
sourceDialog.open()
}
onTriggered: messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open()
}
MenuItem {
text: "Open Externally"

View File

@ -9,6 +9,7 @@ import Spectral 0.1
import Spectral.Setting 0.1
import Spectral.Component 2.0
import Spectral.Dialog 2.0
import Spectral.Effect 2.0
import Spectral.Font 0.1
@ -133,16 +134,19 @@ ColumnLayout {
onSecondaryClicked: messageContextMenu.popup()
Component {
id: messageSourceDialog
MessageSourceDialog {}
}
Menu {
id: messageContextMenu
MenuItem {
text: "View Source"
onTriggered: {
sourceDialog.sourceText = toolTip
sourceDialog.open()
}
onTriggered: messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open()
}
MenuItem {

View File

@ -7,6 +7,7 @@ import Spectral 0.1
import Spectral.Setting 0.1
import Spectral.Component 2.0
import Spectral.Dialog 2.0
import Spectral.Effect 2.0
import Spectral.Font 0.1
@ -84,6 +85,12 @@ ColumnLayout {
onSecondaryClicked: messageContextMenu.popup()
Component {
id: messageSourceDialog
MessageSourceDialog {}
}
Menu {
readonly property string selectedText: contentLabel.selectedText
@ -92,10 +99,7 @@ ColumnLayout {
MenuItem {
text: "View Source"
onTriggered: {
sourceDialog.sourceText = toolTip
sourceDialog.open()
}
onTriggered: messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open()
}
MenuItem {
text: "Reply"

View File

@ -0,0 +1,38 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Spectral.Component 2.0
Dialog {
anchors.centerIn: parent
width: 360
id: root
title: "Create a Room"
contentItem: ColumnLayout {
AutoTextField {
Layout.fillWidth: true
id: roomNameField
placeholderText: "Room Name"
}
AutoTextField {
Layout.fillWidth: true
id: roomTopicField
placeholderText: "Room Topic"
}
}
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: spectralController.createRoom(spectralController.connection, roomNameField.text, roomTopicField.text)
onClosed: destroy()
}

View File

@ -0,0 +1,28 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Spectral.Component 2.0
Dialog {
property var room
anchors.centerIn: parent
width: 360
id: root
title: "Invite User"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: AutoTextField {
id: inviteUserDialogTextField
placeholderText: "User ID"
}
onAccepted: room.inviteToRoom(inviteUserDialogTextField.text)
onClosed: destroy()
}

View File

@ -0,0 +1,38 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Spectral.Component 2.0
Dialog {
anchors.centerIn: parent
width: 360
id: root
title: "Start a Chat"
contentItem: ColumnLayout {
AutoTextField {
Layout.fillWidth: true
id: identifierField
placeholderText: "Room Alias/User ID"
}
}
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
var identifier = identifierField.text
var firstChar = identifier.charAt(0)
if (firstChar == "@") {
spectralController.createDirectChat(spectralController.connection, identifier)
} else if (firstChar == "!" || firstChar == "#") {
spectralController.joinRoom(spectralController.connection, identifier)
}
}
onClosed: destroy()
}

View File

@ -0,0 +1,56 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Spectral.Component 2.0
Dialog {
anchors.centerIn: parent
width: 360
id: root
title: "Login"
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: doLogin()
contentItem: ColumnLayout {
AutoTextField {
Layout.fillWidth: true
id: serverField
placeholderText: "Server Address"
text: "https://matrix.org"
}
AutoTextField {
Layout.fillWidth: true
id: usernameField
placeholderText: "Username"
onAccepted: passwordField.forceActiveFocus()
}
AutoTextField {
Layout.fillWidth: true
id: passwordField
placeholderText: "Password"
echoMode: TextInput.Password
onAccepted: root.doLogin()
}
}
function doLogin() {
spectralController.loginWithCredentials(serverField.text, usernameField.text, passwordField.text)
}
onClosed: root.destroy()
}

View File

@ -0,0 +1,27 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
Popup {
property string sourceText
anchors.centerIn: parent
width: 480
id: root
modal: true
padding: 16
closePolicy: Dialog.CloseOnEscape | Dialog.CloseOnPressOutside
contentItem: ScrollView {
clip: true
Label {
text: sourceText
}
}
onClosed: root.destroy()
}

View File

@ -0,0 +1,218 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Spectral.Component 2.0
import Spectral.Effect 2.0
import Spectral.Setting 0.1
Dialog {
property var room
anchors.centerIn: parent
width: 480
id: root
title: "Room Settings - " + (room ? room.displayName : "")
modal: true
contentItem: ColumnLayout {
RowLayout {
Layout.fillWidth: true
spacing: 16
Avatar {
Layout.preferredWidth: 72
Layout.preferredHeight: 72
Layout.alignment: Qt.AlignTop
hint: room ? room.displayName : "No name"
source: room ? room.avatarMediaId : null
}
ColumnLayout {
Layout.fillWidth: true
Layout.margins: 4
AutoTextField {
Layout.fillWidth: true
text: room ? room.name : ""
placeholderText: "Room Name"
}
AutoTextField {
Layout.fillWidth: true
text: room ? room.topic : ""
placeholderText: "Room Topic"
}
}
}
Control {
Layout.fillWidth: true
visible: room ? room.predecessorId : false
padding: 8
contentItem: RowLayout {
MaterialIcon {
Layout.preferredWidth: 48
Layout.preferredHeight: 48
icon: "\ue8d4"
}
ColumnLayout {
Layout.fillWidth: true
spacing: 0
Label {
Layout.fillWidth: true
font.bold: true
color: MPalette.foreground
text: "This room is a continuation of another conversation."
}
Label {
Layout.fillWidth: true
color: MPalette.lighter
text: "Click here to see older messages."
}
}
}
background: Rectangle {
color: MPalette.banner
RippleEffect {
anchors.fill: parent
onClicked: {
roomListForm.enteredRoom = spectralController.connection.room(room.predecessorId)
root.close()
}
}
}
}
Control {
Layout.fillWidth: true
visible: room ? room.successorId : false
padding: 8
contentItem: RowLayout {
MaterialIcon {
Layout.preferredWidth: 48
Layout.preferredHeight: 48
icon: "\ue8d4"
}
ColumnLayout {
Layout.fillWidth: true
spacing: 0
Label {
Layout.fillWidth: true
font.bold: true
color: MPalette.foreground
text: "This room has been replaced and is no longer active."
}
Label {
Layout.fillWidth: true
color: MPalette.lighter
text: "The conversation continues here."
}
}
}
background: Rectangle {
color: MPalette.banner
RippleEffect {
anchors.fill: parent
onClicked: {
roomListForm.enteredRoom = spectralController.connection.room(room.successorId)
root.close()
}
}
}
}
MenuSeparator {
Layout.fillWidth: true
}
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Label {
Layout.preferredWidth: 100
wrapMode: Label.Wrap
text: "Main Alias"
color: MPalette.lighter
}
ComboBox {
Layout.fillWidth: true
model: room ? room.aliases : null
currentIndex: room ? room.aliases.indexOf(room.canonicalAlias) : -1
}
}
RowLayout {
Layout.fillWidth: true
Label {
Layout.preferredWidth: 100
Layout.alignment: Qt.AlignTop
wrapMode: Label.Wrap
text: "Aliases"
color: MPalette.lighter
}
ColumnLayout {
Layout.fillWidth: true
Repeater {
model: room ? room.aliases : null
delegate: Label {
Layout.fillWidth: true
text: modelData
font.pixelSize: 12
color: MPalette.lighter
}
}
}
}
}
}
onClosed: destroy()
}

View File

@ -0,0 +1,162 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Spectral.Component 2.0
import Spectral.Effect 2.0
import Spectral.Setting 0.1
Dialog {
property var room
property var user
anchors.centerIn: parent
width: 360
id: root
modal: true
contentItem: ColumnLayout {
RowLayout {
Layout.fillWidth: true
spacing: 16
Avatar {
Layout.preferredWidth: 72
Layout.preferredHeight: 72
hint: user ? user.displayName : "No name"
source: user ? user.avatarMediaId : null
}
ColumnLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
font.pixelSize: 18
font.bold: true
wrapMode: Label.Wrap
text: user ? user.displayName : "No Name"
color: MPalette.foreground
}
Label {
Layout.fillWidth: true
wrapMode: Label.Wrap
text: "Online"
color: MPalette.lighter
}
}
}
MenuSeparator {
Layout.fillWidth: true
}
RowLayout {
Layout.fillWidth: true
spacing: 8
MaterialIcon {
Layout.preferredWidth: 32
Layout.preferredHeight: 32
Layout.alignment: Qt.AlignTop
icon: "\ue88f"
color: MPalette.lighter
}
ColumnLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
wrapMode: Label.Wrap
text: user ? user.id : "No ID"
color: MPalette.accent
}
Label {
Layout.fillWidth: true
wrapMode: Label.Wrap
text: "User ID"
color: MPalette.lighter
}
}
}
MenuSeparator {
Layout.fillWidth: true
}
Control {
Layout.fillWidth: true
contentItem: RowLayout {
MaterialIcon {
Layout.preferredWidth: 32
Layout.preferredHeight: 32
Layout.alignment: Qt.AlignTop
icon: room.connection.isIgnored(user) ? "\ue7f5" : "\ue7f6"
color: MPalette.lighter
}
Label {
Layout.fillWidth: true
wrapMode: Label.Wrap
text: room.connection.isIgnored(user) ? "Unignore this user" : "Ignore this user"
color: MPalette.accent
}
}
background: RippleEffect {
onPrimaryClicked: {
room.connection.isIgnored(user) ? room.connection.removeFromIgnoredUsers(user) : room.connection.addToIgnoredUsers(user)
root.close()
}
}
}
Control {
Layout.fillWidth: true
contentItem: RowLayout {
MaterialIcon {
Layout.preferredWidth: 32
Layout.preferredHeight: 32
Layout.alignment: Qt.AlignTop
icon: "\ue5d9"
color: MPalette.lighter
}
Label {
Layout.fillWidth: true
wrapMode: Label.Wrap
text: "Kick this user"
color: MPalette.accent
}
}
background: RippleEffect {
onPrimaryClicked: room.kickMember(user.id)
}
}
}
onClosed: destroy()
}

View File

@ -0,0 +1,8 @@
module Spectral.Dialog
RoomSettingsDialog 2.0 RoomSettingsDialog.qml
UserDetailDialog 2.0 UserDetailDialog.qml
MessageSourceDialog 2.0 MessageSourceDialog.qml
LoginDialog 2.0 LoginDialog.qml
CreateRoomDialog 2.0 CreateRoomDialog.qml
JoinRoomDialog 2.0 JoinRoomDialog.qml
InviteUserDialog 2.0 InviteUserDialog.qml

View File

@ -4,6 +4,7 @@ import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
import Spectral.Component 2.0
import Spectral.Dialog 2.0
import Spectral.Effect 2.0
import Spectral.Setting 0.1
@ -115,7 +116,7 @@ Drawer {
}
background: RippleEffect {
onPrimaryClicked: roomDetailDialog.open()
onPrimaryClicked: roomSettingDialog.createObject(ApplicationWindow.overlay, {"room": room}).open()
}
}
@ -153,7 +154,7 @@ Drawer {
color: MPalette.lighter
}
onClicked: inviteUserDialog.open()
onClicked: inviteUserDialog.createObject(ApplicationWindow.overlay, {"room": room}).open()
}
}
@ -198,6 +199,8 @@ Drawer {
RippleEffect {
anchors.fill: parent
onPrimaryClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": room, "user": user}).open()
}
}
@ -205,225 +208,21 @@ Drawer {
}
}
Dialog {
anchors.centerIn: parent
width: 360
Component {
id: roomSettingDialog
RoomSettingsDialog {}
}
Component {
id: userDetailDialog
UserDetailDialog {}
}
Component {
id: inviteUserDialog
parent: ApplicationWindow.overlay
title: "Invite User"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: AutoTextField {
id: inviteUserDialogTextField
placeholderText: "User ID"
}
onAccepted: room.inviteToRoom(inviteUserDialogTextField.text)
}
Dialog {
anchors.centerIn: parent
width: 480
id: roomDetailDialog
parent: ApplicationWindow.overlay
title: "Room Settings - " + (room ? room.displayName : "")
modal: true
contentItem: ColumnLayout {
RowLayout {
Layout.fillWidth: true
spacing: 16
Avatar {
Layout.preferredWidth: 72
Layout.preferredHeight: 72
Layout.alignment: Qt.AlignTop
hint: room ? room.displayName : "No name"
source: room ? room.avatarMediaId : null
}
ColumnLayout {
Layout.fillWidth: true
Layout.margins: 4
AutoTextField {
Layout.fillWidth: true
text: room ? room.name : ""
placeholderText: "Room Name"
}
AutoTextField {
Layout.fillWidth: true
text: room ? room.topic : ""
placeholderText: "Room Topic"
}
}
}
Control {
Layout.fillWidth: true
visible: room ? room.predecessorId : false
padding: 8
contentItem: RowLayout {
MaterialIcon {
Layout.preferredWidth: 48
Layout.preferredHeight: 48
icon: "\ue8d4"
}
ColumnLayout {
Layout.fillWidth: true
spacing: 0
Label {
Layout.fillWidth: true
font.bold: true
color: MPalette.foreground
text: "This room is a continuation of another conversation."
}
Label {
Layout.fillWidth: true
color: MPalette.lighter
text: "Click here to see older messages."
}
}
}
background: Rectangle {
color: MPalette.banner
RippleEffect {
anchors.fill: parent
onClicked: roomListForm.enteredRoom = spectralController.connection.room(room.predecessorId)
}
}
}
Control {
Layout.fillWidth: true
visible: room ? room.successorId : false
padding: 8
contentItem: RowLayout {
MaterialIcon {
Layout.preferredWidth: 48
Layout.preferredHeight: 48
icon: "\ue8d4"
}
ColumnLayout {
Layout.fillWidth: true
spacing: 0
Label {
Layout.fillWidth: true
font.bold: true
color: MPalette.foreground
text: "This room has been replaced and is no longer active."
}
Label {
Layout.fillWidth: true
color: MPalette.lighter
text: "The conversation continues here."
}
}
}
background: Rectangle {
color: MPalette.banner
RippleEffect {
anchors.fill: parent
onClicked: roomListForm.enteredRoom = spectralController.connection.room(room.successorId)
}
}
}
MenuSeparator {
Layout.fillWidth: true
}
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Label {
Layout.preferredWidth: 100
wrapMode: Label.Wrap
text: "Main Alias"
color: MPalette.lighter
}
ComboBox {
Layout.fillWidth: true
model: room ? room.aliases : null
currentIndex: room ? room.aliases.indexOf(room.canonicalAlias) : -1
}
}
RowLayout {
Layout.fillWidth: true
Label {
Layout.preferredWidth: 100
Layout.alignment: Qt.AlignTop
wrapMode: Label.Wrap
text: "Aliases"
color: MPalette.lighter
}
ColumnLayout {
Layout.fillWidth: true
Repeater {
model: room ? room.aliases : null
delegate: Label {
Layout.fillWidth: true
text: modelData
font.pixelSize: 12
color: MPalette.lighter
}
}
}
}
}
}
InviteUserDialog {}
}
}

View File

@ -88,9 +88,11 @@ Item {
sourceModel: messageEventModel
filters: ExpressionFilter {
filters: [
ExpressionFilter {
expression: marks !== 0x10 && eventType !== "other"
}
]
onModelReset: {
if (currentRoom) {
@ -272,31 +274,6 @@ Item {
onClicked: messageListView.positionViewAtBeginning()
}
Popup {
property string sourceText
anchors.centerIn: parent
width: 480
id: sourceDialog
parent: ApplicationWindow.overlay
padding: 16
closePolicy: Dialog.CloseOnEscape | Dialog.CloseOnPressOutside
contentItem: ScrollView {
clip: true
TextArea {
readOnly: true
selectByMouse: true
text: sourceDialog.sourceText
}
}
}
}
Control {

@ -1 +1 @@
Subproject commit af55d9a0f23ed48c7dcec26efe6b01fb44a8c4fc
Subproject commit 52a81dfa8a5415be369d819837f445479b833cde

View File

@ -7,6 +7,7 @@ import Qt.labs.platform 1.0 as Platform
import Spectral.Panel 2.0
import Spectral.Component 2.0
import Spectral.Dialog 2.0
import Spectral.Page 2.0
import Spectral.Effect 2.0
@ -39,16 +40,14 @@ ApplicationWindow {
menu: Platform.Menu {
Platform.MenuItem {
text: qsTr("Hide Window")
onTriggered: hideWindow()
text: qsTr("Toggle Window")
onTriggered: window.visible ? hideWindow() : showWindow()
}
Platform.MenuItem {
text: qsTr("Quit")
onTriggered: Qt.quit()
}
}
onActivated: showWindow()
}
Controller {
@ -74,102 +73,6 @@ ApplicationWindow {
onActivated: Qt.quit()
}
Dialog {
property bool busy: false
width: 360
x: (window.width - width) / 2
y: (window.height - height) / 2
id: loginDialog
parent: ApplicationWindow.overlay
title: "Login"
contentItem: ColumnLayout {
AutoTextField {
Layout.fillWidth: true
id: serverField
placeholderText: "Server Address"
text: "https://matrix.org"
}
AutoTextField {
Layout.fillWidth: true
id: usernameField
placeholderText: "Username"
onAccepted: passwordField.forceActiveFocus()
}
AutoTextField {
Layout.fillWidth: true
id: passwordField
placeholderText: "Password"
echoMode: TextInput.Password
onAccepted: loginDialog.doLogin()
}
}
footer: DialogButtonBox {
Button {
text: "Cancel"
flat: true
enabled: !loginDialog.busy
onClicked: loginDialog.close()
}
Button {
text: "OK"
flat: true
enabled: !loginDialog.busy
onClicked: loginDialog.doLogin()
}
ToolTip {
id: loginButtonTooltip
}
}
onVisibleChanged: {
if (visible) spectralController.onErrorOccured.connect(showError)
else spectralController.onErrorOccured.disconnect(showError)
}
function showError(error, detail) {
loginDialog.busy = false
loginButtonTooltip.text = error + ": " + detail
loginButtonTooltip.open()
}
function doLogin() {
if (!(serverField.text.startsWith("http") && serverField.text.includes("://"))) {
loginButtonTooltip.text = "Server address should start with http(s)://"
loginButtonTooltip.open()
return
}
loginDialog.busy = true
spectralController.loginWithCredentials(serverField.text, usernameField.text, passwordField.text)
spectralController.connectionAdded.connect(function(conn) {
busy = false
loginDialog.close()
})
}
}
Dialog {
anchors.centerIn: parent
@ -267,7 +170,7 @@ ApplicationWindow {
color: MPalette.lighter
}
onClicked: loginDialog.open()
onClicked: loginDialog.createObject(ApplicationWindow.overlay).open()
}
}
@ -294,7 +197,7 @@ ApplicationWindow {
RippleEffect {
anchors.fill: parent
onPrimaryClicked: joinRoomDialog.open()
onPrimaryClicked: joinRoomDialog.createObject(ApplicationWindow.overlay).open()
}
}
@ -321,7 +224,7 @@ ApplicationWindow {
RippleEffect {
anchors.fill: parent
onPrimaryClicked: createRoomDialog.open()
onPrimaryClicked: createRoomDialog.createObject(ApplicationWindow.overlay).open()
}
}
@ -433,66 +336,22 @@ ApplicationWindow {
}
}
Dialog {
anchors.centerIn: parent
width: 360
Component {
id: loginDialog
LoginDialog {}
}
Component {
id: joinRoomDialog
title: "Start a Chat"
contentItem: ColumnLayout {
AutoTextField {
Layout.fillWidth: true
id: identifierField
placeholderText: "Room Alias/User ID"
}
JoinRoomDialog {}
}
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
var identifier = identifierField.text
var firstChar = identifier.charAt(0)
if (firstChar == "@") {
spectralController.createDirectChat(spectralController.connection, identifier)
} else if (firstChar == "!" || firstChar == "#") {
spectralController.joinRoom(spectralController.connection, identifier)
}
}
}
Dialog {
anchors.centerIn: parent
width: 360
Component {
id: createRoomDialog
title: "Create a Room"
contentItem: ColumnLayout {
AutoTextField {
Layout.fillWidth: true
id: roomNameField
placeholderText: "Room Name"
}
AutoTextField {
Layout.fillWidth: true
id: roomTopicField
placeholderText: "Room Topic"
}
}
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: spectralController.createRoom(spectralController.connection, roomNameField.text, roomTopicField.text)
CreateRoomDialog {}
}
Drawer {

View File

@ -44,5 +44,13 @@
<file>imports/Spectral/Setting/Palette.qml</file>
<file>imports/Spectral/Component/Timeline/FileDelegate.qml</file>
<file>imports/Spectral/Component/FullScreenImage.qml</file>
<file>imports/Spectral/Dialog/qmldir</file>
<file>imports/Spectral/Dialog/RoomSettingsDialog.qml</file>
<file>imports/Spectral/Dialog/UserDetailDialog.qml</file>
<file>imports/Spectral/Dialog/MessageSourceDialog.qml</file>
<file>imports/Spectral/Dialog/LoginDialog.qml</file>
<file>imports/Spectral/Dialog/CreateRoomDialog.qml</file>
<file>imports/Spectral/Dialog/JoinRoomDialog.qml</file>
<file>imports/Spectral/Dialog/InviteUserDialog.qml</file>
</qresource>
</RCC>

View File

@ -7,6 +7,7 @@
#include "events/eventcontent.h"
#include "events/roommessageevent.h"
#include "csapi/account-data.h"
#include "csapi/joining.h"
#include "csapi/logout.h"

View File

@ -3,9 +3,9 @@
#include "connection.h"
#include "notifications/manager.h"
#include "room.h"
#include "settings.h"
#include "user.h"
#include "room.h"
#include <QApplication>
#include <QMediaPlayer>
@ -54,13 +54,16 @@ class Controller : public QObject {
}
Connection* connection() {
if (m_connection.isNull()) return nullptr;
if (m_connection.isNull())
return nullptr;
return m_connection;
}
void setConnection(Connection* conn) {
if (!conn) return;
if (conn == m_connection) return;
if (!conn)
return;
if (conn == m_connection)
return;
m_connection = conn;
emit connectionChanged();
}
@ -100,9 +103,12 @@ class Controller : public QObject {
void createDirectChat(Connection* c, const QString& userID);
void copyToClipboard(const QString& text);
void playAudio(QUrl localFile);
void postNotification(const QString& roomId, const QString& eventId,
const QString& roomName, const QString& senderName,
const QString& text, const QImage& icon);
void postNotification(const QString& roomId,
const QString& eventId,
const QString& roomName,
const QString& senderName,
const QString& text,
const QImage& icon);
};
#endif // CONTROLLER_H

View File

@ -60,7 +60,9 @@ int main(int argc, char *argv[]) {
qmlRegisterUncreatableType<RoomType>("Spectral", 0, 1, "RoomType", "ENUM");
qRegisterMetaType<User*>("User*");
qRegisterMetaType<User*>("const User*");
qRegisterMetaType<Room*>("Room*");
qRegisterMetaType<Connection*>("Connection*");
qRegisterMetaType<MessageEventType>("MessageEventType");
qRegisterMetaType<SpectralRoom*>("SpectralRoom*");
qRegisterMetaType<SpectralUser*>("SpectralUser*");
@ -78,7 +80,8 @@ int main(int argc, char *argv[]) {
engine.addImageProvider(QLatin1String("mxc"), m_provider);
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
if (engine.rootObjects().isEmpty()) return -1;
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}

View File

@ -53,7 +53,8 @@ MessageEventModel::MessageEventModel(QObject *parent)
MessageEventModel::~MessageEventModel() {}
void MessageEventModel::setRoom(SpectralRoom* room) {
if (room == m_currentRoom) return;
if (room == m_currentRoom)
return;
beginResetModel();
if (m_currentRoom) {
@ -97,7 +98,8 @@ void MessageEventModel::setRoom(SpectralRoom *room) {
&MessageEventModel::endInsertRows);
connect(m_currentRoom, &Room::pendingEventAboutToMerge, this,
[this](RoomEvent*, int i) {
if (i == 0) return; // No need to move anything, just refresh
if (i == 0)
return; // No need to move anything, just refresh
movingEvent = true;
// Reverse i because row 0 is bottommost in the model
@ -148,6 +150,11 @@ void MessageEventModel::setRoom(SpectralRoom *room) {
refreshEventRoles(fromEventId, {UserMarkerRole});
refreshEventRoles(toEventId, {UserMarkerRole});
});
connect(m_currentRoom->connection(), &Connection::ignoredUsersListChanged,
this, [=] {
beginResetModel();
endResetModel();
});
qDebug() << "Connected to room" << room->id() << "as"
<< room->localUser()->id();
} else
@ -159,7 +166,9 @@ int MessageEventModel::refreshEvent(const QString &eventId) {
return refreshEventRoles(eventId);
}
void MessageEventModel::refreshRow(int row) { refreshEventRoles(row); }
void MessageEventModel::refreshRow(int row) {
refreshEventRoles(row);
}
int MessageEventModel::timelineBaseIndex() const {
return m_currentRoom ? int(m_currentRoom->pendingEvents().size()) : 0;
@ -191,7 +200,8 @@ QDateTime MessageEventModel::makeMessageTimestamp(
const QMatrixClient::Room::rev_iter_t& baseIt) const {
const auto& timeline = m_currentRoom->messageEvents();
auto ts = baseIt->event()->timestamp();
if (ts.isValid()) return ts;
if (ts.isValid())
return ts;
// The event is most likely redacted or just invalid.
// Look for the nearest date around and slap zero time to it.
@ -210,11 +220,14 @@ QDateTime MessageEventModel::makeMessageTimestamp(
QString MessageEventModel::renderDate(QDateTime timestamp) const {
auto date = timestamp.toLocalTime().date();
if (date == QDate::currentDate()) return tr("Today");
if (date == QDate::currentDate().addDays(-1)) return tr("Yesterday");
if (date == QDate::currentDate())
return tr("Today");
if (date == QDate::currentDate().addDays(-1))
return tr("Yesterday");
if (date == QDate::currentDate().addDays(-2))
return tr("The day before yesterday");
if (date > QDate::currentDate().addDays(-7)) return date.toString("dddd");
if (date > QDate::currentDate().addDays(-7))
return date.toString("dddd");
return date.toString(Qt::DefaultLocaleShortDate);
}
@ -236,7 +249,8 @@ void MessageEventModel::refreshLastUserEvents(int baseTimelineRow) {
}
int MessageEventModel::rowCount(const QModelIndex& parent) const {
if (!m_currentRoom || parent.isValid()) return 0;
if (!m_currentRoom || parent.isValid())
return 0;
return m_currentRoom->timelineSize();
}
@ -282,7 +296,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
return e->hasFileContent() ? "file" : "message";
}
}
if (evt.isStateEvent()) return "state";
if (evt.isStateEvent())
return "state";
return "other";
}
@ -323,21 +338,29 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
};
}
if (role == HighlightRole) return m_currentRoom->isEventHighlighted(&evt);
if (role == HighlightRole)
return m_currentRoom->isEventHighlighted(&evt);
if (role == ReadMarkerRole)
return evt.id() == lastReadEventId && row > timelineBaseIndex();
if (role == SpecialMarksRole) {
if (isPending) return pendingIt->deliveryStatus();
if (isPending)
return pendingIt->deliveryStatus();
if (is<RedactionEvent>(evt)) return EventStatus::Hidden;
if (evt.isRedacted()) return EventStatus::Hidden;
if (is<RedactionEvent>(evt))
return EventStatus::Hidden;
if (evt.isRedacted())
return EventStatus::Hidden;
if (evt.isStateEvent() &&
static_cast<const StateEventBase&>(evt).repeatsState())
return EventStatus::Hidden;
if (m_currentRoom->connection()->isIgnored(
m_currentRoom->user(evt.senderId())))
return EventStatus::Hidden;
return EventStatus::Normal;
}
@ -351,7 +374,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
}
if (role == AnnotationRole)
if (isPending) return pendingIt->annotation();
if (isPending)
return pendingIt->annotation();
if (role == TimeRole || role == SectionRole) {
auto ts =
@ -362,7 +386,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
if (role == UserMarkerRole) {
QVariantList variantList;
for (User* user : m_currentRoom->usersAtEventId(evt.id())) {
if (user == m_currentRoom->localUser()) continue;
if (user == m_currentRoom->localUser())
continue;
variantList.append(QVariant::fromValue(user));
}
return variantList;
@ -374,18 +399,20 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
.toObject()["m.in_reply_to"]
.toObject()["event_id"]
.toString();
if (replyEventId.isEmpty()) return {};
if (replyEventId.isEmpty())
return {};
const auto replyIt = m_currentRoom->findInTimeline(replyEventId);
if (replyIt == m_currentRoom->timelineEdge()) return {};
if (replyIt == m_currentRoom->timelineEdge())
return {};
const auto& replyEvt = **replyIt;
switch (role) {
case ReplyEventIdRole:
return replyEventId;
case ReplyDisplayRole:
return utils::removeReply(m_currentRoom->eventToString(replyEvt, Qt::RichText));
return utils::removeReply(
m_currentRoom->eventToString(replyEvt, Qt::RichText));
case ReplyAuthorRole:
return QVariant::fromValue(
m_currentRoom->user(replyEvt.senderId()));
return QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()));
}
return {};
}
@ -394,7 +421,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
role == AboveAuthorRole || role == AboveTimeRole)
for (auto r = row + 1; r < rowCount(); ++r) {
auto i = index(r);
if (data(i, SpecialMarksRole) != EventStatus::Hidden) switch (role) {
if (data(i, SpecialMarksRole) != EventStatus::Hidden)
switch (role) {
case AboveEventTypeRole:
return data(i, EventTypeRole);
case AboveSectionRole:

View File

@ -6,6 +6,7 @@
#include "csapi/content-repo.h"
#include "csapi/leaving.h"
#include "csapi/typing.h"
#include "events/accountdataevents.h"
#include "events/typingevent.h"
#include <QFileDialog>

View File

@ -14,14 +14,16 @@ UserListModel::UserListModel(QObject* parent)
: QAbstractListModel(parent), m_currentRoom(nullptr) {}
void UserListModel::setRoom(QMatrixClient::Room* room) {
if (m_currentRoom == room) return;
if (m_currentRoom == room)
return;
using namespace QMatrixClient;
beginResetModel();
if (m_currentRoom) {
m_currentRoom->disconnect(this);
// m_currentRoom->connection()->disconnect(this);
for (User* user : m_users) user->disconnect(this);
for (User* user : m_users)
user->disconnect(this);
m_users.clear();
}
m_currentRoom = room;
@ -49,12 +51,14 @@ void UserListModel::setRoom(QMatrixClient::Room* room) {
}
QMatrixClient::User* UserListModel::userAt(QModelIndex index) {
if (index.row() < 0 || index.row() >= m_users.size()) return nullptr;
if (index.row() < 0 || index.row() >= m_users.size())
return nullptr;
return m_users.at(index.row());
}
QVariant UserListModel::data(const QModelIndex& index, int role) const {
if (!index.isValid()) return QVariant();
if (!index.isValid())
return QVariant();
if (index.row() >= m_users.count()) {
qDebug()
@ -71,12 +75,16 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
if (role == AvatarRole) {
return user->avatarMediaId();
}
if (role == ObjectRole) {
return QVariant::fromValue(user);
}
return QVariant();
}
int UserListModel::rowCount(const QModelIndex& parent) const {
if (parent.isValid()) return 0;
if (parent.isValid())
return 0;
return m_users.count();
}
@ -111,7 +119,8 @@ void UserListModel::refresh(QMatrixClient::User* user, QVector<int> roles) {
void UserListModel::avatarChanged(QMatrixClient::User* user,
const QMatrixClient::Room* context) {
if (context == m_currentRoom) refresh(user, {AvatarRole});
if (context == m_currentRoom)
refresh(user, {AvatarRole});
}
int UserListModel::findUserPos(User* user) const {
@ -127,5 +136,6 @@ QHash<int, QByteArray> UserListModel::roleNames() const {
roles[NameRole] = "name";
roles[UserIDRole] = "userId";
roles[AvatarRole] = "avatar";
roles[ObjectRole] = "user";
return roles;
}

View File

@ -17,7 +17,12 @@ class UserListModel : public QAbstractListModel {
Q_PROPERTY(
QMatrixClient::Room* room READ room WRITE setRoom NOTIFY roomChanged)
public:
enum EventRoles { NameRole = Qt::UserRole + 1, UserIDRole, AvatarRole };
enum EventRoles {
NameRole = Qt::UserRole + 1,
UserIDRole,
AvatarRole,
ObjectRole
};
using User = QMatrixClient::User;