Allow creating spaces

gst-experiments
Nicolas Werner 2 years ago
parent c6bf1e6508
commit 1d7575036e
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 2
      CMakeLists.txt
  2. 2
      io.github.NhekoReborn.Nheko.yaml
  3. 9
      resources/qml/RoomList.qml
  4. 11
      resources/qml/dialogs/CreateRoom.qml
  5. 23
      src/timeline/CommunitiesModel.cpp
  6. 14
      src/ui/NhekoGlobalObject.cpp
  7. 8
      src/ui/NhekoGlobalObject.h

@ -582,7 +582,7 @@ if(USE_BUNDLED_MTXCLIENT)
FetchContent_Declare( FetchContent_Declare(
MatrixClient MatrixClient
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
GIT_TAG 43e88905659b027bc47c40fe0d31cf28fd639ef9 GIT_TAG a00a04adaddf856feaa21087217608e05b9c7ed3
) )
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")

@ -203,7 +203,7 @@ modules:
buildsystem: cmake-ninja buildsystem: cmake-ninja
name: mtxclient name: mtxclient
sources: sources:
- commit: 43e88905659b027bc47c40fe0d31cf28fd639ef9 - commit: a00a04adaddf856feaa21087217608e05b9c7ed3
#tag: v0.8.0 #tag: v0.8.0
type: git type: git
url: https://github.com/Nheko-Reborn/mtxclient.git url: https://github.com/Nheko-Reborn/mtxclient.git

@ -729,6 +729,15 @@ Page {
} }
} }
Platform.MenuItem {
text: qsTr("Create a new community")
onTriggered: {
var createRoom = createRoomComponent.createObject(timelineRoot, { "space": true });
createRoom.show();
timelineRoot.destroyOnClose(createRoom);
}
}
} }
} }

@ -12,7 +12,10 @@ import im.nheko 1.0
ApplicationWindow { ApplicationWindow {
id: createRoomRoot id: createRoomRoot
title: qsTr("Create Room")
property bool space: false
title: space ? qsTr("New community") : qsTr("New Room")
minimumWidth: Math.max(rootLayout.implicitWidth+2*rootLayout.anchors.margins, footer.implicitWidth + Nheko.paddingLarge) minimumWidth: Math.max(rootLayout.implicitWidth+2*rootLayout.anchors.margins, footer.implicitWidth + Nheko.paddingLarge)
minimumHeight: rootLayout.implicitHeight+footer.implicitHeight+2*rootLayout.anchors.margins minimumHeight: rootLayout.implicitHeight+footer.implicitHeight+2*rootLayout.anchors.margins
modality: Qt.NonModal modality: Qt.NonModal
@ -95,6 +98,7 @@ ApplicationWindow {
checked: false checked: false
} }
Label { Label {
visible: !space
Layout.preferredWidth: implicitWidth Layout.preferredWidth: implicitWidth
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
text: qsTr("Trusted") text: qsTr("Trusted")
@ -107,6 +111,7 @@ ApplicationWindow {
ToolTip.delay: Nheko.tooltipDelay ToolTip.delay: Nheko.tooltipDelay
} }
ToggleButton { ToggleButton {
visible: !space
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
Layout.preferredWidth: implicitWidth Layout.preferredWidth: implicitWidth
id: isTrusted id: isTrusted
@ -114,6 +119,7 @@ ApplicationWindow {
enabled: !isPublic.checked enabled: !isPublic.checked
} }
Label { Label {
visible: !space
Layout.preferredWidth: implicitWidth Layout.preferredWidth: implicitWidth
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
text: qsTr("Encryption") text: qsTr("Encryption")
@ -126,6 +132,7 @@ ApplicationWindow {
ToolTip.delay: Nheko.tooltipDelay ToolTip.delay: Nheko.tooltipDelay
} }
ToggleButton { ToggleButton {
visible: !space
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
Layout.preferredWidth: implicitWidth Layout.preferredWidth: implicitWidth
id: isEncrypted id: isEncrypted
@ -150,7 +157,7 @@ ApplicationWindow {
else { else {
preset = isTrusted.checked ? 2 : 0; preset = isTrusted.checked ? 2 : 0;
} }
Nheko.createRoom(newRoomName.text, newRoomTopic.text, newRoomAlias.text, isEncrypted.checked, preset) Nheko.createRoom(space, newRoomName.text, newRoomTopic.text, newRoomAlias.text, isEncrypted.checked, preset)
createRoomRoot.close(); createRoomRoot.close();
} }
} }

@ -449,7 +449,8 @@ CommunitiesModel::clear()
void void
CommunitiesModel::sync(const mtx::responses::Sync &sync_) CommunitiesModel::sync(const mtx::responses::Sync &sync_)
{ {
bool tagsUpdated = false; bool tagsUpdated = false;
const auto userid = http::client()->user_id().to_string();
for (const auto &[roomid, room] : sync_.rooms.join) { for (const auto &[roomid, room] : sync_.rooms.join) {
for (const auto &e : room.account_data.events) for (const auto &e : room.account_data.events)
@ -457,20 +458,28 @@ CommunitiesModel::sync(const mtx::responses::Sync &sync_)
mtx::events::AccountDataEvent<mtx::events::account_data::Tags>>(e)) { mtx::events::AccountDataEvent<mtx::events::account_data::Tags>>(e)) {
tagsUpdated = true; tagsUpdated = true;
} }
for (const auto &e : room.state.events) for (const auto &e : room.state.events) {
if (std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Child>>( if (std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Child>>(
e) || e) ||
std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Parent>>( std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Parent>>(
e)) { e))
tagsUpdated = true; tagsUpdated = true;
}
for (const auto &e : room.timeline.events) if (auto ev = std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(&e);
ev && ev->state_key == userid)
tagsUpdated = true;
}
for (const auto &e : room.timeline.events) {
if (std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Child>>( if (std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Child>>(
e) || e) ||
std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Parent>>( std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Parent>>(
e)) { e))
tagsUpdated = true; tagsUpdated = true;
}
if (auto ev = std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(&e);
ev && ev->state_key == userid)
tagsUpdated = true;
}
auto roomId = QString::fromStdString(roomid); auto roomId = QString::fromStdString(roomid);
auto &oldUnreads = roomNotificationCache[roomId]; auto &oldUnreads = roomNotificationCache[roomId];

@ -136,10 +136,22 @@ Nheko::setTransientParent(QWindow *window, QWindow *parentWindow) const
} }
void void
Nheko::createRoom(QString name, QString topic, QString aliasLocalpart, bool isEncrypted, int preset) Nheko::createRoom(bool space,
QString name,
QString topic,
QString aliasLocalpart,
bool isEncrypted,
int preset)
{ {
mtx::requests::CreateRoom req; mtx::requests::CreateRoom req;
if (space) {
req.creation_content = mtx::events::state::Create{};
req.creation_content->type = mtx::events::state::room_type::space;
req.creation_content->creator.clear();
req.creation_content->room_version.clear();
}
switch (preset) { switch (preset) {
case 1: case 1:
req.preset = mtx::requests::Preset::PublicChat; req.preset = mtx::requests::Preset::PublicChat;

@ -56,8 +56,12 @@ public:
Q_INVOKABLE void setStatusMessage(QString msg) const; Q_INVOKABLE void setStatusMessage(QString msg) const;
Q_INVOKABLE void showUserSettingsPage() const; Q_INVOKABLE void showUserSettingsPage() const;
Q_INVOKABLE void logout() const; Q_INVOKABLE void logout() const;
Q_INVOKABLE void Q_INVOKABLE void createRoom(bool space,
createRoom(QString name, QString topic, QString aliasLocalpart, bool isEncrypted, int preset); QString name,
QString topic,
QString aliasLocalpart,
bool isEncrypted,
int preset);
Q_INVOKABLE PowerlevelEditingModels *editPowerlevels(QString room_id_) const Q_INVOKABLE PowerlevelEditingModels *editPowerlevels(QString room_id_) const
{ {
return new PowerlevelEditingModels(room_id_); return new PowerlevelEditingModels(room_id_);

Loading…
Cancel
Save