From 9be5c32d812a55ca55e1cf80d8e29fe593c85a62 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 27 Apr 2018 13:26:28 +0900 Subject: User::processEvent: fix bridge postfix not being stripped Closes #197. --- lib/user.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/user.cpp') diff --git a/lib/user.cpp b/lib/user.cpp index 6143a061..f469128c 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -389,12 +389,12 @@ void User::processEvent(RoomMemberEvent* event, const Room* room) // FIXME: the hint doesn't work for bridged users auto oldNameHint = d->nameForRoom(room, event->prevContent()->displayName); - updateName(event->displayName(), oldNameHint, room); + updateName(newName, oldNameHint, room); updateAvatarUrl(event->avatarUrl(), d->avatarUrlForRoom(room, event->prevContent()->avatarUrl), room); } else { - updateName(event->displayName(), room); + updateName(newName, room); updateAvatarUrl(event->avatarUrl(), d->avatarUrlForRoom(room), room); } } -- cgit v1.2.3 From e74e48507f68e36c289c5dbe4b75f32a6910f3c1 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 27 Apr 2018 13:28:35 +0900 Subject: User::rawName(); bonus, bring order to doc comments This new function allows to get the username along with its bridge (basically, undoing the change applied by processEvent for cases when it is undesirable). --- lib/user.cpp | 6 ++++++ lib/user.h | 27 ++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'lib/user.cpp') diff --git a/lib/user.cpp b/lib/user.cpp index f469128c..88d20276 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -220,6 +220,12 @@ QString User::name(const Room* room) const return d->nameForRoom(room); } +QString User::rawName(const Room* room) const +{ + return d->bridged.isEmpty() ? name(room) : + name(room) % " (" % d->bridged % ')'; +} + void User::updateName(const QString& newName, const Room* room) { updateName(newName, d->nameForRoom(room), room); diff --git a/lib/user.h b/lib/user.h index f76f9e0a..f94fbee4 100644 --- a/lib/user.h +++ b/lib/user.h @@ -50,24 +50,33 @@ namespace QMatrixClient /** Get the name chosen by the user * This may be empty if the user didn't choose the name or cleared - * it. - * \sa displayName + * it. If the user is bridged, the bridge postfix (such as '(IRC)') + * is stripped out. No disambiguation for the room is done. + * \sa displayName, rawName */ QString name(const Room* room = nullptr) const; + /** Get the user name along with the bridge postfix + * This function is similar to name() but appends the bridge postfix + * (such as '(IRC)') to the user name. No disambiguation is done. + * \sa name, displayName + */ + QString rawName(const Room* room = nullptr) const; + /** Get the displayed user name - * This method returns the result of name() if its non-empty; - * otherwise it returns user id. This is convenient to show a user - * name outside of a room context. In a room context, user names - * should be disambiguated. - * \sa name, id, fullName Room::roomMembername + * When \p room is null, this method returns result of name() if + * the name is non-empty; otherwise it returns user id. + * When \p room is non-null, this call is equivalent to + * Room::roomMembername invocation for the user (i.e. the user's + * disambiguated room-specific name is returned). + * \sa name, id, fullName, Room::roomMembername */ QString displayname(const Room* room = nullptr) const; /** Get user name and id in one string * The constructed string follows the format 'name (id)' - * used for users disambiguation in a room context and in other - * places. + * which the spec recommends for users disambiguation in + * a room context and in other places. * \sa displayName, Room::roomMembername */ QString fullName(const Room* room = nullptr) const; -- cgit v1.2.3 From 3a763fd470b8aeffa3d412e6f605231492fb5b0c Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 27 Apr 2018 13:34:52 +0900 Subject: Fix broken User::displayName() logic Also, add an assert to Connection::user() to make sure it doesn't create users with invalid ids. Closes #201. --- lib/connection.cpp | 1 + lib/user.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/user.cpp') diff --git a/lib/connection.cpp b/lib/connection.cpp index 241fa43d..f2bbf903 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -590,6 +590,7 @@ Room* Connection::invitation(const QString& roomId) const User* Connection::user(const QString& userId) { + Q_ASSERT(userId.startsWith('@') && userId.contains(':')); if( d->userMap.contains(userId) ) return d->userMap.value(userId); auto* user = userFactory(this, userId); diff --git a/lib/user.cpp b/lib/user.cpp index 88d20276..c4fbfe35 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -311,7 +311,7 @@ QString User::displayname(const Room* room) const { auto name = d->nameForRoom(room); return name.isEmpty() ? d->userId : - room ? room->roomMembername(name) : name; + room ? room->roomMembername(this) : name; } QString User::fullName(const Room* room) const -- cgit v1.2.3