diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/room.cpp | 30 | ||||
-rw-r--r-- | lib/room.h | 2 |
2 files changed, 28 insertions, 4 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 4b349f44..af6ef8c4 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -689,12 +689,27 @@ TagRecord Room::tag(const QString& name) const return d->tags.value(name); } +std::pair<bool, QString> validatedTag(QString name) +{ + if (name.contains('.')) + return { false, name }; + + qWarning(MAIN) << "The tag" << name + << "doesn't follow the CS API conventions, check your client code"; + name.prepend("u."); + qWarning(MAIN) << "Using " << name << "instead"; + + return { true, name }; +} + void Room::addTag(const QString& name, const TagRecord& record) { - if (d->tags.contains(name)) + const auto& checkRes = validatedTag(name); + if (d->tags.contains(name) || + (checkRes.first && d->tags.contains(checkRes.second))) return; - d->tags.insert(name, record); + d->tags.insert(checkRes.second, record); d->broadcastTagUpdates(); } @@ -712,10 +727,19 @@ void Room::removeTag(const QString& name) d->broadcastTagUpdates(); } -void Room::setTags(const TagsMap& newTags) +void Room::setTags(TagsMap newTags) { if (newTags == d->tags) return; + + const auto& tagNames = newTags.keys(); + for (const auto& t: tagNames) + { + const auto& checkRes = validatedTag(t); + if (checkRes.first) + newTags.insert(checkRes.second, newTags.take(t)); + } + d->tags = newTags; d->broadcastTagUpdates(); } @@ -315,7 +315,7 @@ namespace QMatrixClient * (because tags are saved in account data rather than in shared * room state). */ - void setTags(const TagsMap& newTags); + void setTags(TagsMap newTags); /** Check whether the list of tags has m.favourite */ bool isFavourite() const; |