getProfileFromUserId method
Get the combined profile information for this user.
If getFromRooms
is true then the profile will first be searched from the
room memberships. This is unstable if the given user makes use of different displaynames
and avatars per room, which is common for some bots and bridges.
If cache
is true then
the profile get cached for this session. Please note that then the profile may
become outdated if the user changes the displayname or avatar in this session.
Implementation
Future<Profile> getProfileFromUserId(String userId,
{bool cache = true, bool getFromRooms = true}) async {
var profile =
getFromRooms ? _profileRoomsCache[userId] : _profileServerCache[userId];
if (cache && profile != null) {
return Profile(
userId: userId,
displayName: profile.displayname,
avatarUrl: profile.avatarUrl,
);
}
if (getFromRooms) {
final room = rooms.firstWhereOrNull((Room room) =>
room.getParticipants().indexWhere((User user) => user.id == userId) !=
-1);
if (room != null) {
final user =
room.getParticipants().firstWhere((User user) => user.id == userId);
final profileFromRooms = Profile(
userId: userId,
displayName: user.displayName,
avatarUrl: user.avatarUrl,
);
_profileRoomsCache[userId] = ProfileInformation(
avatarUrl: profileFromRooms.avatarUrl,
displayname: profileFromRooms.displayName,
);
return profileFromRooms;
}
}
profile = await getUserProfile(userId);
if (cache || _profileServerCache.containsKey(userId)) {
_profileServerCache[userId] = profile;
}
return Profile(
userId: userId,
displayName: profile.displayname,
avatarUrl: profile.avatarUrl,
);
}