fix: own profile containing mxid

There are a few ways to fix this. We could skip events, where we don't
have the state in memory yet or always do a /profile request and cache
that.

I chose to go with loading the event from the database if necessary. If
we have a room in the db, we should have our memberevent in the db. In
some cases we might not (if the server thinks our memberevent is super
redundant), but I think the spec doesn't really allow that and it
doesn't happen in practice. And even if it would, we probably would want
our member event ASAP. And if we have no rooms, we fetch it from the
server as before instead of constructing a member with an MXID as the
username.

fixes https://gitlab.com/famedly/company/frontend/frontend-issue-inbox/-/issues/65
This commit is contained in:
Nicolas Werner 2022-03-15 02:13:09 +01:00
parent d047678971
commit 83298cc98b
2 changed files with 18 additions and 6 deletions

View File

@ -675,12 +675,14 @@ class Client extends MatrixApi {
if (rooms.isNotEmpty) { if (rooms.isNotEmpty) {
final profileSet = <Profile>{}; final profileSet = <Profile>{};
for (final room in rooms) { for (final room in rooms) {
final user = room.getUserByMXIDSync(userID!); final user = await room.requestUser(userID!);
profileSet.add(Profile( if (user != null) {
avatarUrl: user.avatarUrl, profileSet.add(Profile(
displayName: user.displayName, avatarUrl: user.avatarUrl,
userId: user.id, displayName: user.displayName,
)); userId: user.id,
));
}
} }
if (profileSet.length == 1) return profileSet.single; if (profileSet.length == 1) return profileSet.single;
} }

File diff suppressed because one or more lines are too long