From f7c7cb82decc9786e4c2aec578173bb2e3ab1047 Mon Sep 17 00:00:00 2001 From: td Date: Mon, 20 Feb 2023 17:57:29 +0530 Subject: [PATCH 1/3] chore: add useServerCache option to fetchOwnProfileFromServer and fix missing awaits --- lib/src/client.dart | 52 ++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 8cc2f692..57891faa 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -757,21 +757,23 @@ class Client extends MatrixApi { /// Returns the user's own displayname and avatar url. In Matrix it is possible that /// one user can have different displaynames and avatar urls in different rooms. /// Tries to get the profile from homeserver first, if failed, falls back to a profile - /// from a room where the user exists. - Future fetchOwnProfileFromServer() async { + /// from a room where the user exists. Set `useServerCache` to true to get any + /// prior value from this function + Future fetchOwnProfileFromServer( + {bool useServerCache = false}) async { try { - return getProfileFromUserId( + return await getProfileFromUserId( userID!, getFromRooms: false, - cache: false, + cache: useServerCache, ); } catch (e) { Logs().w( '[Matrix] getting profile from homeserver failed, falling back to first room with required profile'); - return getProfileFromUserId( + return await getProfileFromUserId( userID!, getFromRooms: true, - cache: false, + cache: true, ); } } @@ -790,7 +792,8 @@ class Client extends MatrixApi { cache: cache, ); - final Map _profileCache = {}; + final Map _profileRoomsCache = {}; + final Map _profileServerCache = {}; /// Get the combined profile information for this user. /// If [getFromRooms] is true then the profile will first be searched from the @@ -801,12 +804,14 @@ class Client extends MatrixApi { /// become outdated if the user changes the displayname or avatar in this session. Future getProfileFromUserId(String userId, {bool cache = true, bool getFromRooms = true}) async { - var profile = _profileCache[userId]; + var profile = + getFromRooms ? _profileRoomsCache[userId] : _profileServerCache[userId]; if (cache && profile != null) { return Profile( - userId: userId, - displayName: profile.displayname, - avatarUrl: profile.avatarUrl); + userId: userId, + displayName: profile.displayname, + avatarUrl: profile.avatarUrl, + ); } if (getFromRooms) { @@ -816,20 +821,27 @@ class Client extends MatrixApi { if (room != null) { final user = room.getParticipants().firstWhere((User user) => user.id == userId); - return Profile( - userId: userId, - displayName: user.displayName, - avatarUrl: user.avatarUrl); + 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 || _profileCache.containsKey(userId)) { - _profileCache[userId] = profile; + if (cache || _profileServerCache.containsKey(userId)) { + _profileServerCache[userId] = profile; } return Profile( - userId: userId, - displayName: profile.displayname, - avatarUrl: profile.avatarUrl); + userId: userId, + displayName: profile.displayname, + avatarUrl: profile.avatarUrl, + ); } final List _archivedRooms = []; From 0c555919af8aa334fff3a430069c2020e3b1ab24 Mon Sep 17 00:00:00 2001 From: td Date: Mon, 20 Feb 2023 18:04:56 +0530 Subject: [PATCH 2/3] chore: add missing awaits in group call enter and leave funcs --- lib/src/voip/group_call.dart | 32 ++++++++++++++++---------------- lib/src/voip/voip.dart | 14 +++++++------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/src/voip/group_call.dart b/lib/src/voip/group_call.dart index f6b44a78..34fdb7e0 100644 --- a/lib/src/voip/group_call.dart +++ b/lib/src/voip/group_call.dart @@ -406,7 +406,7 @@ class GroupCall { } /// enter the group call. - void enter() async { + Future enter() async { if (!(state == GroupCallState.LocalCallFeedUninitialized || state == GroupCallState.LocalCallFeedInitialized)) { throw Exception('Cannot enter call in the $state state'); @@ -449,14 +449,14 @@ class GroupCall { voip.delegate.handleNewGroupCall(this); } - void dispose() { + Future dispose() async { if (localUserMediaStream != null) { removeUserMediaStream(localUserMediaStream!); localUserMediaStream = null; } if (localScreenshareStream != null) { - stopMediaStream(localScreenshareStream!.stream); + await stopMediaStream(localScreenshareStream!.stream); removeScreenshareStream(localScreenshareStream!); localScreenshareStream = null; localDesktopCapturerSourceId = null; @@ -464,7 +464,7 @@ class GroupCall { _removeParticipant(client.userID!); - removeMemberStateEvent(); + await removeMemberStateEvent(); final callsCopy = calls.toList(); callsCopy.forEach((element) { @@ -473,11 +473,11 @@ class GroupCall { activeSpeaker = null; activeSpeakerLoopTimeout?.cancel(); - _callSubscription?.cancel(); + await _callSubscription?.cancel(); } - void leave() { - dispose(); + Future leave() async { + await dispose(); setState(GroupCallState.LocalCallFeedUninitialized); voip.currentGroupCID = null; voip.delegate.handleGroupCallEnded(this); @@ -487,7 +487,7 @@ class GroupCall { justLeftGroupCall.intent != 'm.room' && justLeftGroupCall.participants.isEmpty && room.canCreateGroupCall) { - terminate(); + await terminate(); } else { Logs().d( '[VOIP] left group call but cannot terminate. participants: ${participants.length}, pl: ${room.canCreateGroupCall}'); @@ -495,10 +495,10 @@ class GroupCall { } /// terminate group call. - void terminate({bool emitStateEvent = true}) async { + Future terminate({bool emitStateEvent = true}) async { final existingStateEvent = room.getState(EventTypes.GroupCallPrefix, groupCallId); - dispose(); + await dispose(); participants = []; voip.groupCalls.remove(room.id); voip.groupCalls.remove(groupCallId); @@ -1116,8 +1116,8 @@ class GroupCall { onGroupCallEvent.add(GroupCallEvent.UserMediaStreamsChanged); } - void replaceUserMediaStream( - WrappedMediaStream existingStream, WrappedMediaStream replacementStream) { + Future replaceUserMediaStream(WrappedMediaStream existingStream, + WrappedMediaStream replacementStream) async { final streamIndex = userMediaStreams .indexWhere((stream) => stream.userId == existingStream.userId); @@ -1127,7 +1127,7 @@ class GroupCall { userMediaStreams.replaceRange(streamIndex, 1, [replacementStream]); - existingStream.dispose(); + await existingStream.dispose(); //replacementStream.measureVolumeActivity(true); onGroupCallEvent.add(GroupCallEvent.UserMediaStreamsChanged); } @@ -1225,8 +1225,8 @@ class GroupCall { onGroupCallEvent.add(GroupCallEvent.ScreenshareStreamsChanged); } - void replaceScreenshareStream( - WrappedMediaStream existingStream, WrappedMediaStream replacementStream) { + Future replaceScreenshareStream(WrappedMediaStream existingStream, + WrappedMediaStream replacementStream) async { final streamIndex = screenshareStreams .indexWhere((stream) => stream.userId == existingStream.userId); @@ -1236,7 +1236,7 @@ class GroupCall { screenshareStreams.replaceRange(streamIndex, 1, [replacementStream]); - existingStream.dispose(); + await existingStream.dispose(); onGroupCallEvent.add(GroupCallEvent.ScreenshareStreamsChanged); } diff --git a/lib/src/voip/voip.dart b/lib/src/voip/voip.dart index 939d5d0f..1a719cb9 100644 --- a/lib/src/voip/voip.dart +++ b/lib/src/voip/voip.dart @@ -660,15 +660,15 @@ class VoIP { Future startGroupCalls() async { final rooms = client.rooms; - rooms.forEach((element) { - createGroupCallForRoom(element); - }); + for (final room in rooms) { + await createGroupCallForRoom(room); + } } - void stopGroupCalls() { - groupCalls.forEach((_, groupCall) { - groupCall.terminate(); - }); + Future stopGroupCalls() async { + for (final groupCall in groupCalls.values) { + await groupCall.terminate(); + } groupCalls.clear(); } From 6f2c0b83fb81b8a6b9114344668d815d7355c445 Mon Sep 17 00:00:00 2001 From: td Date: Mon, 20 Feb 2023 18:06:41 +0530 Subject: [PATCH 3/3] chore: version bump to 0.17.1 --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27383806..12b11d41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.17.1] - 20th Feb 2023 +- chore: add missing awaits in group call enter and leave funcs (td) +- chore: add useServerCache option to fetchOwnProfileFromServer and fix missing awaits (td) + ## [0.17.0] - 17th Feb 2023 - fix: ability to upgrade audio calls to video calls (td) - chore: add a fetchOwnProfileFromServer method which tries to get ownProfile from server first, disk then (td) diff --git a/pubspec.yaml b/pubspec.yaml index cee958b6..b13f79ad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: matrix description: Matrix Dart SDK -version: 0.17.0 +version: 0.17.1 homepage: https://famedly.com repository: https://gitlab.com/famedly/company/frontend/famedlysdk.git