Move Controller::createRoom and Controller::createSpace to NeoChatConnection
This commit is contained in:
committed by
James Graham
parent
ff0990bb7c
commit
f7d2ffac66
@@ -371,36 +371,6 @@ void Controller::saveWindowGeometry()
|
|||||||
WindowController::instance().saveGeometry();
|
WindowController::instance().saveGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::createRoom(const QString &name, const QString &topic)
|
|
||||||
{
|
|
||||||
auto createRoomJob = m_connection->createRoom(Connection::PublishRoom, QString(), name, topic, QStringList());
|
|
||||||
connect(createRoomJob, &CreateRoomJob::failure, this, [this, createRoomJob] {
|
|
||||||
Q_EMIT errorOccured(i18n("Room creation failed: %1", createRoomJob->errorString()));
|
|
||||||
});
|
|
||||||
connectSingleShot(this, &Controller::roomAdded, &RoomManager::instance(), &RoomManager::enterRoom, Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::createSpace(const QString &name, const QString &topic)
|
|
||||||
{
|
|
||||||
auto createRoomJob = m_connection->createRoom(Connection::UnpublishRoom,
|
|
||||||
{},
|
|
||||||
name,
|
|
||||||
topic,
|
|
||||||
QStringList(),
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
false,
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
QJsonObject{
|
|
||||||
{"type"_ls, "m.space"_ls},
|
|
||||||
});
|
|
||||||
connect(createRoomJob, &CreateRoomJob::failure, this, [this, createRoomJob] {
|
|
||||||
Q_EMIT errorOccured(i18n("Space creation failed: %1", createRoomJob->errorString()));
|
|
||||||
});
|
|
||||||
connectSingleShot(this, &Controller::roomAdded, &RoomManager::instance(), &RoomManager::enterRoom, Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Controller::isOnline() const
|
bool Controller::isOnline() const
|
||||||
{
|
{
|
||||||
return m_isOnline;
|
return m_isOnline;
|
||||||
|
|||||||
@@ -113,16 +113,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool saveAccessTokenToKeyChain(const Quotient::AccountSettings &account, const QByteArray &accessToken);
|
bool saveAccessTokenToKeyChain(const Quotient::AccountSettings &account, const QByteArray &accessToken);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create new room for a group chat.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void createRoom(const QString &name, const QString &topic);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create new space.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void createSpace(const QString &name, const QString &topic);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Join a room.
|
* @brief Join a room.
|
||||||
*/
|
*/
|
||||||
@@ -216,7 +206,6 @@ Q_SIGNALS:
|
|||||||
void userConsentRequired(QUrl url);
|
void userConsentRequired(QUrl url);
|
||||||
void isOnlineChanged(bool isOnline);
|
void isOnlineChanged(bool isOnline);
|
||||||
void activeConnectionIndexChanged();
|
void activeConnectionIndexChanged();
|
||||||
void roomAdded(NeoChatRoom *room);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void saveWindowGeometry();
|
void saveWindowGeometry();
|
||||||
|
|||||||
@@ -144,7 +144,6 @@ void RoomListModel::doAddRoom(Room *r)
|
|||||||
m_rooms.append(room);
|
m_rooms.append(room);
|
||||||
connectRoomSignals(room);
|
connectRoomSignals(room);
|
||||||
Q_EMIT roomAdded(room);
|
Q_EMIT roomAdded(room);
|
||||||
Q_EMIT Controller::instance().roomAdded(room);
|
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "Attempt to add nullptr to the room list";
|
qCritical() << "Attempt to add nullptr to the room list";
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "jobs/neochatchangepasswordjob.h"
|
#include "jobs/neochatchangepasswordjob.h"
|
||||||
#include "jobs/neochatdeactivateaccountjob.h"
|
#include "jobs/neochatdeactivateaccountjob.h"
|
||||||
|
#include "roommanager.h"
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
#include <qt5keychain/keychain.h>
|
#include <qt5keychain/keychain.h>
|
||||||
@@ -15,8 +16,11 @@
|
|||||||
#include <qt6keychain/keychain.h>
|
#include <qt6keychain/keychain.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <KLocalizedString>
|
||||||
|
|
||||||
#include <Quotient/csapi/content-repo.h>
|
#include <Quotient/csapi/content-repo.h>
|
||||||
#include <Quotient/csapi/profile.h>
|
#include <Quotient/csapi/profile.h>
|
||||||
|
#include <Quotient/qt_connection_util.h>
|
||||||
#include <Quotient/settings.h>
|
#include <Quotient/settings.h>
|
||||||
#include <Quotient/user.h>
|
#include <Quotient/user.h>
|
||||||
|
|
||||||
@@ -156,4 +160,26 @@ void NeoChatConnection::deactivateAccount(const QString &password)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NeoChatConnection::createRoom(const QString &name, const QString &topic)
|
||||||
|
{
|
||||||
|
const auto job = Connection::createRoom(Connection::PublishRoom, {}, name, topic, {});
|
||||||
|
connect(job, &CreateRoomJob::failure, this, [this, job] {
|
||||||
|
Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString()));
|
||||||
|
});
|
||||||
|
connectSingleShot(this, &Connection::newRoom, this, [](Room *room) {
|
||||||
|
RoomManager::instance().enterRoom(dynamic_cast<NeoChatRoom *>(room));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void NeoChatConnection::createSpace(const QString &name, const QString &topic)
|
||||||
|
{
|
||||||
|
const auto job = Connection::createRoom(Connection::UnpublishRoom, {}, name, topic, {}, {}, {}, false, {}, {}, QJsonObject{{"type"_ls, "m.space"_ls}});
|
||||||
|
connect(job, &CreateRoomJob::failure, this, [this, job] {
|
||||||
|
Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString()));
|
||||||
|
});
|
||||||
|
connectSingleShot(this, &Connection::newRoom, this, [](Room *room) {
|
||||||
|
RoomManager::instance().enterRoom(dynamic_cast<NeoChatRoom *>(room));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_neochatconnection.cpp"
|
#include "moc_neochatconnection.cpp"
|
||||||
|
|||||||
@@ -48,6 +48,16 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void deactivateAccount(const QString &password);
|
Q_INVOKABLE void deactivateAccount(const QString &password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create new room for a group chat.
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE void createRoom(const QString &name, const QString &topic);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create new space.
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE void createSpace(const QString &name, const QString &topic);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void labelChanged();
|
void labelChanged();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ FormCard.FormCardPage {
|
|||||||
|
|
||||||
title: i18nc("@title", "Create a Room")
|
title: i18nc("@title", "Create a Room")
|
||||||
|
|
||||||
|
required property NeoChatConnection connection
|
||||||
|
|
||||||
Component.onCompleted: roomNameField.forceActiveFocus()
|
Component.onCompleted: roomNameField.forceActiveFocus()
|
||||||
|
|
||||||
FormCard.FormHeader {
|
FormCard.FormHeader {
|
||||||
@@ -35,7 +37,7 @@ FormCard.FormCardPage {
|
|||||||
text: i18nc("@action:button", "Ok")
|
text: i18nc("@action:button", "Ok")
|
||||||
enabled: roomNameField.text.length > 0
|
enabled: roomNameField.text.length > 0
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Controller.createRoom(roomNameField.text, roomTopicField.text);
|
root.connection.createRoom(roomNameField.text, roomTopicField.text);
|
||||||
root.closeDialog()
|
root.closeDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import org.kde.kirigamiaddons.formcard 1.0 as FormCard
|
|||||||
FormCard.FormCardPage {
|
FormCard.FormCardPage {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
required property NeoChatConnection connection
|
||||||
|
|
||||||
title: i18n("Create a Space")
|
title: i18n("Create a Space")
|
||||||
|
|
||||||
Kirigami.Theme.colorSet: Kirigami.Theme.Window
|
Kirigami.Theme.colorSet: Kirigami.Theme.Window
|
||||||
@@ -30,7 +32,7 @@ FormCard.FormCardPage {
|
|||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
text: i18n("Create space")
|
text: i18n("Create space")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Controller.createSpace(nameDelegate.text, topicDelegate.text)
|
root.connection.createSpace(nameDelegate.text, topicDelegate.text)
|
||||||
root.close()
|
root.close()
|
||||||
root.destroy()
|
root.destroy()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ RowLayout {
|
|||||||
|
|
||||||
property var desiredWidth
|
property var desiredWidth
|
||||||
property bool collapsed: false
|
property bool collapsed: false
|
||||||
|
required property NeoChatConnection connection
|
||||||
|
|
||||||
property Kirigami.Action exploreAction: Kirigami.Action {
|
property Kirigami.Action exploreAction: Kirigami.Action {
|
||||||
text: i18n("Explore rooms")
|
text: i18n("Explore rooms")
|
||||||
@@ -38,7 +39,7 @@ RowLayout {
|
|||||||
text: i18n("Create a Room")
|
text: i18n("Create a Room")
|
||||||
icon.name: "system-users"
|
icon.name: "system-users"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
pageStack.pushDialogLayer("qrc:/CreateRoomDialog.qml", {}, {title: i18nc("@title", "Create a Room")})
|
pageStack.pushDialogLayer("qrc:/CreateRoomDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Create a Room")})
|
||||||
}
|
}
|
||||||
shortcut: StandardKey.New
|
shortcut: StandardKey.New
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,7 @@ RowLayout {
|
|||||||
text: i18n("Create a Space")
|
text: i18n("Create a Space")
|
||||||
icon.name: "list-add"
|
icon.name: "list-add"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
pageStack.pushDialogLayer("qrc:/CreateSpaceDialog.qml", {}, {title: i18nc("@title", "Create a Space")})
|
pageStack.pushDialogLayer("qrc:/CreateSpaceDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Create a Space")})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ Kirigami.Page {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
desiredWidth: root.width - Kirigami.Units.largeSpacing
|
desiredWidth: root.width - Kirigami.Units.largeSpacing
|
||||||
collapsed: root.collapsed
|
collapsed: root.collapsed
|
||||||
|
connection: root.connection
|
||||||
}
|
}
|
||||||
|
|
||||||
padding: 0
|
padding: 0
|
||||||
|
|||||||
@@ -320,12 +320,16 @@ Kirigami.ApplicationWindow {
|
|||||||
Component {
|
Component {
|
||||||
id: createRoomDialog
|
id: createRoomDialog
|
||||||
|
|
||||||
CreateRoomDialog {}
|
CreateRoomDialog {
|
||||||
|
connection: Controller.activeConnection
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: createSpaceDialog
|
id: createSpaceDialog
|
||||||
CreateSpaceDialog {}
|
CreateSpaceDialog {
|
||||||
|
connection: Controller.activeConnection
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
|||||||
Reference in New Issue
Block a user