Support the order parameter in m.space.child events
Support the order parameter in m.space.child events, with the exception of always putting spaces higher than non-spaces see https://spec.matrix.org/v1.8/client-server-api/#ordering-of-children-within-a-space for the spec algorithm
This commit is contained in:
@@ -244,6 +244,20 @@ QVariant SpaceChildrenModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
return QVariant::fromValue(nullptr);
|
||||
}
|
||||
if (role == OrderRole) {
|
||||
if (child->parentItem() == nullptr) {
|
||||
return QString();
|
||||
}
|
||||
const auto childState = child->parentItem()->childStateContent(child);
|
||||
return childState[QLatin1String("order")].toString();
|
||||
}
|
||||
if (role == ChildTimestampRole) {
|
||||
if (child->parentItem() == nullptr) {
|
||||
return QString();
|
||||
}
|
||||
const auto childState = child->parentItem()->childState(child);
|
||||
return childState[QLatin1String("origin_server_ts")].toString();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
@@ -325,6 +339,8 @@ QHash<int, QByteArray> SpaceChildrenModel::roleNames() const
|
||||
roles[IsDeclaredParentRole] = "isDeclaredParent";
|
||||
roles[CanRemove] = "canRemove";
|
||||
roles[ParentRoomRole] = "parentRoom";
|
||||
roles[OrderRole] = "order";
|
||||
roles[ChildTimestampRole] = "childTimestamp";
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
IsDeclaredParentRole,
|
||||
CanRemove,
|
||||
ParentRoomRole,
|
||||
OrderRole,
|
||||
ChildTimestampRole,
|
||||
};
|
||||
|
||||
explicit SpaceChildrenModel(QObject *parent = nullptr);
|
||||
|
||||
@@ -26,10 +26,27 @@ QString SpaceChildSortFilterModel::filterText() const
|
||||
|
||||
bool SpaceChildSortFilterModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
||||
{
|
||||
if (!source_left.data(SpaceChildrenModel::IsSpaceRole).toBool() && source_right.data(SpaceChildrenModel::IsSpaceRole).toBool()) {
|
||||
if (source_left.data(SpaceChildrenModel::IsSpaceRole).toBool() && source_right.data(SpaceChildrenModel::IsSpaceRole).toBool()) {
|
||||
if (!source_left.data(SpaceChildrenModel::OrderRole).toString().isEmpty() && !source_right.data(SpaceChildrenModel::OrderRole).toString().isEmpty()) {
|
||||
return QString::compare(source_left.data(SpaceChildrenModel::OrderRole).toString(), source_right.data(SpaceChildrenModel::OrderRole).toString())
|
||||
< 0;
|
||||
}
|
||||
return source_left.data(SpaceChildrenModel::ChildTimestampRole).toDateTime() > source_right.data(SpaceChildrenModel::ChildTimestampRole).toDateTime();
|
||||
}
|
||||
if (source_left.data(SpaceChildrenModel::IsSpaceRole).toBool()) {
|
||||
return true;
|
||||
} else if (source_right.data(SpaceChildrenModel::IsSpaceRole).toBool()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (!source_left.data(SpaceChildrenModel::OrderRole).toString().isEmpty() && !source_right.data(SpaceChildrenModel::OrderRole).toString().isEmpty()) {
|
||||
return QString::compare(source_left.data(SpaceChildrenModel::OrderRole).toString(), source_right.data(SpaceChildrenModel::OrderRole).toString()) < 0;
|
||||
}
|
||||
if (!source_left.data(SpaceChildrenModel::OrderRole).toString().isEmpty()) {
|
||||
return true;
|
||||
} else if (!source_right.data(SpaceChildrenModel::OrderRole).toString().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return source_left.data(SpaceChildrenModel::ChildTimestampRole).toDateTime() > source_right.data(SpaceChildrenModel::ChildTimestampRole).toDateTime();
|
||||
}
|
||||
|
||||
bool SpaceChildSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
|
||||
@@ -141,6 +141,22 @@ bool SpaceTreeItem::isSpace() const
|
||||
return m_isSpace;
|
||||
}
|
||||
|
||||
QJsonObject SpaceTreeItem::childState(const SpaceTreeItem *child) const
|
||||
{
|
||||
if (child == nullptr) {
|
||||
return {};
|
||||
}
|
||||
if (child->parentItem() != this) {
|
||||
return {};
|
||||
}
|
||||
for (const auto &childState : m_childStates) {
|
||||
if (childState->stateKey() == child->id()) {
|
||||
return childState->fullJson();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QJsonObject SpaceTreeItem::childStateContent(const SpaceTreeItem *child) const
|
||||
{
|
||||
if (child == nullptr) {
|
||||
|
||||
@@ -125,6 +125,11 @@ public:
|
||||
*/
|
||||
bool isSpace() const;
|
||||
|
||||
/**
|
||||
* @brief Return the m.space.child stripped state Json for the given child.
|
||||
*/
|
||||
QJsonObject childState(const SpaceTreeItem *child) const;
|
||||
|
||||
/**
|
||||
* @brief Return the m.space.child state event content for the given child.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user