Fix room bottom mic visibility after feature sync
This commit is contained in:
parent
76daf8e32c
commit
02b4fafb3e
@ -523,6 +523,30 @@ class RealTimeCommunicationManager extends ChangeNotifier {
|
|||||||
return currentUserId.isNotEmpty && currentUserId == userId.trim();
|
return currentUserId.isNotEmpty && currentUserId == userId.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<String> _currentUserIdentityKeys() {
|
||||||
|
return _userProfileIdentityKeys(
|
||||||
|
AccountStorage().getCurrentUser()?.userProfile,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> _userProfileIdentityKeys(SocialChatUserProfile? user) {
|
||||||
|
return {
|
||||||
|
user?.id?.trim() ?? "",
|
||||||
|
user?.account?.trim() ?? "",
|
||||||
|
user?.getID().trim() ?? "",
|
||||||
|
}..removeWhere((item) => item.isEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _userProfileMatchesAnyIdentity(
|
||||||
|
SocialChatUserProfile? user,
|
||||||
|
Set<String> identityKeys,
|
||||||
|
) {
|
||||||
|
if (identityKeys.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return _userProfileIdentityKeys(user).any(identityKeys.contains);
|
||||||
|
}
|
||||||
|
|
||||||
///房间红包列表
|
///房间红包列表
|
||||||
List<SCRoomRedPacketListRes> redPacketList = [];
|
List<SCRoomRedPacketListRes> redPacketList = [];
|
||||||
|
|
||||||
@ -5418,14 +5442,15 @@ class RealTimeCommunicationManager extends ChangeNotifier {
|
|||||||
|
|
||||||
///自己是否在麦上
|
///自己是否在麦上
|
||||||
bool isOnMai() {
|
bool isOnMai() {
|
||||||
final currentUserId =
|
final currentUserKeys = _currentUserIdentityKeys();
|
||||||
(AccountStorage().getCurrentUser()?.userProfile?.id ?? "").trim();
|
if (currentUserKeys.isEmpty) {
|
||||||
if (currentUserId.isEmpty) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (final entry in roomWheatMap.entries) {
|
for (final entry in roomWheatMap.entries) {
|
||||||
if ((micAtIndexForDisplay(entry.key)?.user?.id ?? "").trim() ==
|
if (_userProfileMatchesAnyIdentity(
|
||||||
currentUserId) {
|
micAtIndexForDisplay(entry.key)?.user,
|
||||||
|
currentUserKeys,
|
||||||
|
)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5434,25 +5459,39 @@ class RealTimeCommunicationManager extends ChangeNotifier {
|
|||||||
|
|
||||||
///自己是否在指定的麦上
|
///自己是否在指定的麦上
|
||||||
bool isOnMaiInIndex(num index) {
|
bool isOnMaiInIndex(num index) {
|
||||||
return (micAtIndexForDisplay(index)?.user?.id ?? "").trim() ==
|
return _userProfileMatchesAnyIdentity(
|
||||||
(AccountStorage().getCurrentUser()?.userProfile?.id ?? "").trim();
|
micAtIndexForDisplay(index)?.user,
|
||||||
|
_currentUserIdentityKeys(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
///点击的用户在哪个麦上
|
///点击的用户在哪个麦上
|
||||||
num userOnMaiInIndex(String userId) {
|
num userOnMaiInIndex(String userId) {
|
||||||
|
return _findUserOnMaiInIndex(userId, useDisplaySeatForCurrentUser: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
num _findUserOnMaiInIndex(
|
||||||
|
String userId, {
|
||||||
|
required bool useDisplaySeatForCurrentUser,
|
||||||
|
}) {
|
||||||
final normalizedUserId = userId.trim();
|
final normalizedUserId = userId.trim();
|
||||||
if (normalizedUserId.isEmpty) {
|
if (normalizedUserId.isEmpty) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
num index = -1;
|
num index = -1;
|
||||||
|
final currentUserKeys = _currentUserIdentityKeys();
|
||||||
|
final isCurrentUserQuery = currentUserKeys.contains(normalizedUserId);
|
||||||
|
final lookupKeys = <String>{normalizedUserId};
|
||||||
|
if (isCurrentUserQuery) {
|
||||||
|
lookupKeys.addAll(currentUserKeys);
|
||||||
|
}
|
||||||
|
lookupKeys.removeWhere((item) => item.isEmpty);
|
||||||
roomWheatMap.forEach((k, value) {
|
roomWheatMap.forEach((k, value) {
|
||||||
final visibleSeat =
|
final candidateSeat =
|
||||||
normalizedUserId ==
|
useDisplaySeatForCurrentUser && isCurrentUserQuery
|
||||||
(AccountStorage().getCurrentUser()?.userProfile?.id ?? "")
|
|
||||||
.trim()
|
|
||||||
? micAtIndexForDisplay(k)
|
? micAtIndexForDisplay(k)
|
||||||
: value;
|
: value;
|
||||||
if ((visibleSeat?.user?.id ?? "").trim() == normalizedUserId) {
|
if (_userProfileMatchesAnyIdentity(candidateSeat?.user, lookupKeys)) {
|
||||||
index = k;
|
index = k;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,4 +30,33 @@ void main() {
|
|||||||
expect(rtcProvider.roomWheatMap[3]?.user?.id, 'user-1');
|
expect(rtcProvider.roomWheatMap[3]?.user?.id, 'user-1');
|
||||||
expect(rtcProvider.isOnMai(), isTrue);
|
expect(rtcProvider.isOnMai(), isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('self mic lookup matches account when mic user id differs', () {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
AccountStorage().setCurrentUser(
|
||||||
|
SocialChatLoginRes(
|
||||||
|
userProfile: SocialChatUserProfile(
|
||||||
|
id: 'local-user-id',
|
||||||
|
account: 'account-1',
|
||||||
|
userNickname: 'Me',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final rtcProvider =
|
||||||
|
RealTimeCommunicationManager()
|
||||||
|
..roomWheatMap = {
|
||||||
|
2: MicRes(
|
||||||
|
micIndex: 2,
|
||||||
|
user: SocialChatUserProfile(
|
||||||
|
id: 'mic-user-id',
|
||||||
|
account: 'account-1',
|
||||||
|
userNickname: 'Me',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(rtcProvider.isOnMai(), isTrue);
|
||||||
|
expect(rtcProvider.isOnMaiInIndex(2), isTrue);
|
||||||
|
expect(rtcProvider.userOnMaiInIndex('local-user-id'), 2);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user