diff options
-rw-r--r-- | events/accountdataevents.h | 4 | ||||
-rw-r--r-- | room.cpp | 20 | ||||
-rw-r--r-- | room.h | 19 |
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()) { } @@ -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) @@ -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 */ |