diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-11-08 18:57:44 +0100 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-11-08 18:57:44 +0100 |
commit | f4db6988bf2fd71f74ac851557d82c6f65cc89b1 (patch) | |
tree | dcad7010f50fa44a984b9dd02b904e88551f5037 /lib/user.cpp | |
parent | 7355e2f801eb85e771a6c454c77f9eb62398f38b (diff) | |
download | libquotient-f4db6988bf2fd71f74ac851557d82c6f65cc89b1.tar.gz libquotient-f4db6988bf2fd71f74ac851557d82c6f65cc89b1.zip |
More robust member profile data retrieval
MemberEventContent: displayname and avatarUrl are now Omittables;
CS API doesn't guarantee their presence (see also
https://github.com/matrix-org/matrix-doc/issues/1375) but Quotient
used to assume they are always there, causing #412.
RoomMemberEvent: displayname() -> newDisplayName() and
avatarUrl() -> newAvatarUrl(), to emphasise the actual semantics (and
also the changed interface). The old signatures still work but are
deprecated.
Instead of roomMembername() (with weird camel-casing), three new
methods in addition to safeMemberName() are introduced to Room:
- memberName() - produces the "best known" display name for a
given member; User::name() uses it to avoid the pitfall of #412.
- disambiguatedMemberName() - this is what roomMembername() used to be;
not recommended for direct use when UI is concerned.
- safeMemberName() - remains as is, with the fix to the documentation
that used to mislead that the function returns HTML-escaped content
(it didn't, and doesn't).
- htmlSafeMemberName() - does what safeMemberName() claimed to do.
Respectively, memberNames() is deprecated in favor of safeMemberNames()
and htmlSafeMemberNames(). The corresponding Q_PROPERTY uses
safeMemberNames() now.
Similar to memberName(), Room has got memberAvatarUrl() to spare
User class from diving into Room state to find the member avatar URL.
Closes #412.
Diffstat (limited to 'lib/user.cpp')
-rw-r--r-- | lib/user.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/user.cpp b/lib/user.cpp index ffa4efb9..45a9c121 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -88,8 +88,7 @@ int User::hue() const { return int(hueF() * 359); } QString User::name(const Room* room) const { - return room ? room->getCurrentState<RoomMemberEvent>(id())->displayName() - : d->defaultName; + return room ? room->memberName(id()) : d->defaultName; } QString User::rawName(const Room* room) const { return name(room); } @@ -169,9 +168,8 @@ bool User::isIgnored() const { return connection()->isIgnored(this); } QString User::displayname(const Room* room) const { - return room ? room->roomMembername(this) - : d->defaultName.isEmpty() ? d->id - : d->defaultName; + return room ? room->safeMemberName(id()) + : d->defaultName.isEmpty() ? d->id : d->defaultName; } QString User::fullName(const Room* room) const @@ -187,7 +185,7 @@ const Avatar& User::avatarObject(const Room* room) const if (!room) return d->defaultAvatar; - const auto& url = room->getCurrentState<RoomMemberEvent>(id())->avatarUrl(); + const auto& url = room->memberAvatarUrl(id()); const auto& mediaId = url.authority() + url.path(); return d->otherAvatars.try_emplace(mediaId, url).first->second; } |