Reduce nesting
This commit is contained in:
@@ -886,11 +886,12 @@ void NeoChatRoom::addParent(const QString &parentId, bool canonical, bool setPar
|
||||
|
||||
setState("m.space.parent"_L1, parentId, QJsonObject{{"canonical"_L1, canonical}, {"via"_L1, QJsonArray{connection()->domain()}}});
|
||||
|
||||
if (setParentChild) {
|
||||
if (!setParentChild) {
|
||||
return;
|
||||
}
|
||||
if (auto parent = static_cast<NeoChatRoom *>(connection()->room(parentId))) {
|
||||
parent->setState("m.space.child"_L1, id(), QJsonObject{{"via"_L1, QJsonArray{connection()->domain()}}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NeoChatRoom::removeParent(const QString &parentId)
|
||||
@@ -940,25 +941,29 @@ void NeoChatRoom::addChild(const QString &childId, bool setChildParent, bool can
|
||||
}
|
||||
setState("m.space.child"_L1, childId, QJsonObject{{"via"_L1, QJsonArray{connection()->domain()}}, {"suggested"_L1, suggested}, {"order"_L1, order}});
|
||||
|
||||
if (setChildParent) {
|
||||
if (!setChildParent) {
|
||||
return;
|
||||
}
|
||||
if (auto child = static_cast<NeoChatRoom *>(connection()->room(childId))) {
|
||||
if (child->canSendState("m.space.parent"_L1)) {
|
||||
if (!child->canSendState("m.space.parent"_L1)) {
|
||||
return;
|
||||
}
|
||||
child->setState("m.space.parent"_L1, id(), QJsonObject{{"canonical"_L1, canonical}, {"via"_L1, QJsonArray{connection()->domain()}}});
|
||||
|
||||
if (canonical) {
|
||||
if (!canonical) {
|
||||
return;
|
||||
}
|
||||
// Only one canonical parent can exist so make sure others are set to false.
|
||||
auto parentEvents = child->currentState().eventsOfType("m.space.parent"_L1);
|
||||
for (const auto &parentEvent : parentEvents) {
|
||||
if (parentEvent->contentPart<bool>("canonical"_L1)) {
|
||||
if (!parentEvent->contentPart<bool>("canonical"_L1)) {
|
||||
continue;
|
||||
}
|
||||
auto content = parentEvent->contentJson();
|
||||
content.insert("canonical"_L1, false);
|
||||
setState("m.space.parent"_L1, parentEvent->stateKey(), content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NeoChatRoom::removeChild(const QString &childId, bool unsetChildParent)
|
||||
@@ -971,13 +976,15 @@ void NeoChatRoom::removeChild(const QString &childId, bool unsetChildParent)
|
||||
}
|
||||
setState("m.space.child"_L1, childId, {});
|
||||
|
||||
if (unsetChildParent) {
|
||||
if (!unsetChildParent) {
|
||||
return;
|
||||
}
|
||||
if (auto child = static_cast<NeoChatRoom *>(connection()->room(childId))) {
|
||||
if (child->canSendState("m.space.parent"_L1) && child->currentState().contains("m.space.parent"_L1, id())) {
|
||||
if (!child->canSendState("m.space.parent"_L1) || !child->currentState().contains("m.space.parent"_L1, id())) {
|
||||
return;
|
||||
}
|
||||
child->setState("m.space.parent"_L1, id(), {});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool NeoChatRoom::isSuggested(const QString &childId)
|
||||
|
||||
Reference in New Issue
Block a user