Fix room bottom mic visibility after feature sync

This commit is contained in:
roxy 2026-07-07 19:13:27 +08:00
parent 76daf8e32c
commit 02b4fafb3e
2 changed files with 80 additions and 12 deletions

View File

@ -523,6 +523,30 @@ class RealTimeCommunicationManager extends ChangeNotifier {
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 = [];
@ -5418,14 +5442,15 @@ class RealTimeCommunicationManager extends ChangeNotifier {
///
bool isOnMai() {
final currentUserId =
(AccountStorage().getCurrentUser()?.userProfile?.id ?? "").trim();
if (currentUserId.isEmpty) {
final currentUserKeys = _currentUserIdentityKeys();
if (currentUserKeys.isEmpty) {
return false;
}
for (final entry in roomWheatMap.entries) {
if ((micAtIndexForDisplay(entry.key)?.user?.id ?? "").trim() ==
currentUserId) {
if (_userProfileMatchesAnyIdentity(
micAtIndexForDisplay(entry.key)?.user,
currentUserKeys,
)) {
return true;
}
}
@ -5434,25 +5459,39 @@ class RealTimeCommunicationManager extends ChangeNotifier {
///
bool isOnMaiInIndex(num index) {
return (micAtIndexForDisplay(index)?.user?.id ?? "").trim() ==
(AccountStorage().getCurrentUser()?.userProfile?.id ?? "").trim();
return _userProfileMatchesAnyIdentity(
micAtIndexForDisplay(index)?.user,
_currentUserIdentityKeys(),
);
}
///
num userOnMaiInIndex(String userId) {
return _findUserOnMaiInIndex(userId, useDisplaySeatForCurrentUser: true);
}
num _findUserOnMaiInIndex(
String userId, {
required bool useDisplaySeatForCurrentUser,
}) {
final normalizedUserId = userId.trim();
if (normalizedUserId.isEmpty) {
return -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) {
final visibleSeat =
normalizedUserId ==
(AccountStorage().getCurrentUser()?.userProfile?.id ?? "")
.trim()
final candidateSeat =
useDisplaySeatForCurrentUser && isCurrentUserQuery
? micAtIndexForDisplay(k)
: value;
if ((visibleSeat?.user?.id ?? "").trim() == normalizedUserId) {
if (_userProfileMatchesAnyIdentity(candidateSeat?.user, lookupKeys)) {
index = k;
}
});

View File

@ -30,4 +30,33 @@ void main() {
expect(rtcProvider.roomWheatMap[3]?.user?.id, 'user-1');
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);
});
}