Canonical Parent

So the original space parent and child stuff was technically a bit naughty in that it allowed multiple rooms to be set as the canonical parent. Because while a room can have multiple parents only one should be canonical. This adds the following:
- When adding a child or parent there is an extra check to select if the new parent should be canonical
- Any parent can be selected as the canonical one from the room settings
- All functions ensure that there is only ever one canonical parent by ensuring all others are false when a new one is set.
This commit is contained in:
James Graham
2023-10-13 12:00:47 +00:00
parent fe70e2773f
commit e480299563
5 changed files with 137 additions and 31 deletions

View File

@@ -133,6 +133,21 @@ class NeoChatRoom : public Quotient::Room
*/
Q_PROPERTY(QVector<QString> parentIds READ parentIds NOTIFY parentIdsChanged)
/**
* @brief The current canonical parent for the room.
*
* Empty if no canonical parent is set. The write method can only be used to
* set an existing parent as canonical; If you wish to add a new parent and set
* it as canonical use the addParent method and pass true to the canonical
* parameter.
*
* Setting will fail if the user doesn't have the required privileges (see
* canModifyParent) or if the given room ID is not a parent room.
*
* @sa canModifyParent, addParent
*/
Q_PROPERTY(QString canonicalParent READ canonicalParent WRITE setCanonicalParent NOTIFY canonicalParentChanged)
/**
* @brief If the room is a space.
*/
@@ -601,10 +616,8 @@ public:
QVector<QString> parentIds() const;
/**
* @brief Whether the given parent is the canonical parent of the room.
*/
Q_INVOKABLE bool isCanonicalParent(const QString &parentId) const;
QString canonicalParent() const;
void setCanonicalParent(const QString &parentId);
/**
* @brief Whether the local user has permission to set the given space as a parent.
@@ -622,7 +635,7 @@ public:
*
* @sa canModifyParent()
*/
Q_INVOKABLE void addParent(const QString &parentId);
Q_INVOKABLE void addParent(const QString &parentId, bool canonical = false, bool setParentChild = false);
/**
* @brief Remove the given room as a parent.
@@ -642,7 +655,7 @@ public:
* Will fail if the user doesn't have the required privileges or this room is
* not a space.
*/
Q_INVOKABLE void addChild(const QString &childId, bool setChildParent = false);
Q_INVOKABLE void addChild(const QString &childId, bool setChildParent = false, bool canonical = false);
/**
* @brief Remove the given room as a child.
@@ -927,6 +940,7 @@ Q_SIGNALS:
void backgroundChanged();
void readMarkerLoadedChanged();
void parentIdsChanged();
void canonicalParentChanged();
void lastActiveTimeChanged();
void isInviteChanged();
void displayNameChanged();