aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--events/accountdataevents.h4
-rw-r--r--room.cpp20
-rw-r--r--room.h19
3 files changed, 41 insertions, 2 deletions
diff --git a/events/accountdataevents.h b/events/accountdataevents.h
index 78cf9c46..f3ba27bb 100644
--- a/events/accountdataevents.h
+++ b/events/accountdataevents.h
@@ -30,8 +30,8 @@ namespace QMatrixClient
struct TagRecord
{
- TagRecord (QString order) : order(std::move(order)) { }
- explicit TagRecord(const QJsonValue& jv = {})
+ TagRecord (QString order = {}) : order(std::move(order)) { }
+ explicit TagRecord(const QJsonValue& jv)
: order(jv.toObject().value("order").toString())
{ }
diff --git a/room.cpp b/room.cpp
index 86d1e6cd..cb94ddb6 100644
--- a/room.cpp
+++ b/room.cpp
@@ -586,6 +586,26 @@ TagRecord Room::tag(const QString& name) const
return d->tags.value(name);
}
+void Room::addTag(const QString& name, const TagRecord& record)
+{
+ if (d->tags.contains(name))
+ return;
+
+ d->tags.insert(name, record);
+ d->setAccountData(TagEvent(d->tags));
+ emit tagsChanged();
+}
+
+void Room::removeTag(const QString& name)
+{
+ if (!d->tags.contains(name))
+ return;
+
+ d->tags.remove(name);
+ d->setAccountData(TagEvent(d->tags));
+ emit tagsChanged();
+}
+
void Room::setTags(const TagsMap& newTags)
{
if (newTags == d->tags)
diff --git a/room.h b/room.h
index bdd11452..0eb5ecc3 100644
--- a/room.h
+++ b/room.h
@@ -240,6 +240,25 @@ namespace QMatrixClient
TagsMap tags() const;
TagRecord tag(const QString& name) const;
+ /** Add a new tag to this room
+ * If this room already has this tag, nothing happens. If it's a new
+ * tag for the room, the respective tag record is added to the set
+ * of tags and the new set is sent to the server to update other
+ * clients.
+ */
+ void addTag(const QString& name, const TagRecord& record = {});
+
+ /** Remove a tag from the room */
+ void removeTag(const QString& name);
+
+ /** Overwrite the room's tags
+ * This completely replaces the existing room's tags with a set
+ * of new ones and updates the new set on the server. Unlike
+ * most other methods in Room, this one sends a signal about changes
+ * immediately, not waiting for confirmation from the server
+ * (because tags are saved in account data rather than in shared
+ * room state).
+ */
void setTags(const TagsMap& newTags);
/** Check whether the list of tags has m.favourite */