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