fix: race condition between getState and requestUser updates
This commit is contained in:
parent
8f350760c4
commit
4c4a062a27
|
|
@ -1694,10 +1694,9 @@ class Room {
|
||||||
required bool requestProfile,
|
required bool requestProfile,
|
||||||
}) async {
|
}) async {
|
||||||
// Is user already in cache?
|
// Is user already in cache?
|
||||||
final userFromState = getState(EventTypes.RoomMember, mxID)?.asUser(this);
|
|
||||||
|
|
||||||
// If not in cache, try the database
|
// If not in cache, try the database
|
||||||
var foundUser = userFromState;
|
User? foundUser = getState(EventTypes.RoomMember, mxID)?.asUser(this);
|
||||||
|
|
||||||
// If the room is not postloaded, check the database
|
// If the room is not postloaded, check the database
|
||||||
if (partial && foundUser == null) {
|
if (partial && foundUser == null) {
|
||||||
|
|
@ -1706,8 +1705,10 @@ class Room {
|
||||||
|
|
||||||
// If not in the database, try fetching the member from the server
|
// If not in the database, try fetching the member from the server
|
||||||
if (requestState && foundUser == null) {
|
if (requestState && foundUser == null) {
|
||||||
foundUser = await _requestSingleParticipantViaState(mxID,
|
foundUser = await _requestSingleParticipantViaState(
|
||||||
ignoreErrors: ignoreErrors);
|
mxID,
|
||||||
|
ignoreErrors: ignoreErrors,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user isn't found or they have left and no displayname set anymore, request their profile from the server
|
// If the user isn't found or they have left and no displayname set anymore, request their profile from the server
|
||||||
|
|
@ -1739,11 +1740,14 @@ class Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundUser == null) return null;
|
if (foundUser == null) return null;
|
||||||
|
// make sure we didn't actually store anything by the time we did those requests
|
||||||
|
final userFromCurrentState =
|
||||||
|
getState(EventTypes.RoomMember, mxID)?.asUser(this);
|
||||||
|
|
||||||
// Set user in the local state if the state changed.
|
// Set user in the local state if the state changed.
|
||||||
// If we set the state unconditionally, we might end up with a client calling this over and over thinking the user changed.
|
// If we set the state unconditionally, we might end up with a client calling this over and over thinking the user changed.
|
||||||
if (userFromState == null ||
|
if (userFromCurrentState == null ||
|
||||||
userFromState.displayName != foundUser.displayName) {
|
userFromCurrentState.displayName != foundUser.displayName) {
|
||||||
setState(foundUser);
|
setState(foundUser);
|
||||||
// ignore: deprecated_member_use_from_same_package
|
// ignore: deprecated_member_use_from_same_package
|
||||||
onUpdate.add(id);
|
onUpdate.add(id);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue