aboutsummaryrefslogtreecommitdiff
path: root/lib/room.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-12-11 21:18:52 +0300
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-12-11 21:18:52 +0300
commitc15771776cf277e6235fce6ebb6c6d7e3702a257 (patch)
tree12fedfd4ea14eaab983677b5176bbbe868cb31c0 /lib/room.cpp
parent7b5f65ba64ae4df54919336f4beec19493d1b5ee (diff)
parent6b2847de2325f2b818dc336c9339d50de58604ea (diff)
downloadlibquotient-c15771776cf277e6235fce6ebb6c6d7e3702a257.tar.gz
libquotient-c15771776cf277e6235fce6ebb6c6d7e3702a257.zip
Merge branch 'kitsune-better-upgrade-ux'
Diffstat (limited to 'lib/room.cpp')
-rw-r--r--lib/room.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index fe50aa9a..60b9a684 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -387,11 +387,31 @@ QString Room::predecessorId() const
return d->getCurrentState<RoomCreateEvent>()->predecessor().roomId;
}
+Room* Room::predecessor(JoinStates statesFilter) const
+{
+ if (const auto& predId = predecessorId(); !predId.isEmpty())
+ if (auto* r = connection()->room(predId, statesFilter);
+ r && r->successorId() == id())
+ return r;
+
+ return nullptr;
+}
+
QString Room::successorId() const
{
return d->getCurrentState<RoomTombstoneEvent>()->successorRoomId();
}
+Room* Room::successor(JoinStates statesFilter) const
+{
+ if (const auto& succId = successorId(); !succId.isEmpty())
+ if (auto* r = connection()->room(succId, statesFilter);
+ r && r->predecessorId() == id())
+ return r;
+
+ return nullptr;
+}
+
const Room::Timeline& Room::messageEvents() const { return d->timeline; }
const Room::PendingEvents& Room::pendingEvents() const
@@ -928,12 +948,27 @@ void Room::removeTag(const QString& name)
<< "not found, nothing to remove";
}
-void Room::setTags(TagsMap newTags)
+void Room::setTags(TagsMap newTags, ActionScope applyOn)
{
+ bool propagate = applyOn != ActionScope::ThisRoomOnly;
+ auto joinStates =
+ applyOn == ActionScope::WithinSameState ? joinState() :
+ applyOn == ActionScope::OmitLeftState ? JoinState::Join|JoinState::Invite :
+ JoinState::Join|JoinState::Invite|JoinState::Leave;
+ if (propagate) {
+ for (auto* r = this; (r = r->predecessor(joinStates));)
+ r->setTags(newTags, ActionScope::ThisRoomOnly);
+ }
+
d->setTags(move(newTags));
connection()->callApi<SetAccountDataPerRoomJob>(
localUser()->id(), id(), TagEvent::matrixTypeId(),
TagEvent(d->tags).contentJson());
+
+ if (propagate) {
+ for (auto* r = this; (r = r->successor(joinStates));)
+ r->setTags(newTags, ActionScope::ThisRoomOnly);
+ }
}
void Room::Private::setTags(TagsMap newTags)