Merge branch 'feature' of gitea.haiyihy.com:hy/chatapp3-flutter into feature

This commit is contained in:
zhx 2026-05-23 20:43:31 +08:00
commit 8096ca6acc

View File

@ -1046,6 +1046,22 @@ class RealTimeMessagingManager extends ChangeNotifier {
return;
}
final context = navigatorKey.currentState?.context;
if (context == null || !context.mounted) {
_cpInviteLog(
'skip local gift waiting reason=no_context '
'receiverId=$receiverId relationType=$normalizedRelationType',
);
return;
}
if (!_canAutoShowCpInviteDialog(context)) {
_cpInviteLog(
'skip local gift waiting reason=not_in_visible_voice_room '
'receiverId=$receiverId relationType=$normalizedRelationType',
);
return;
}
final applyId = await _latestCpGiftApplyId(
receiverId,
relationType: normalizedRelationType,
@ -1060,6 +1076,13 @@ class RealTimeMessagingManager extends ChangeNotifier {
if (!await _isCpInviteApplyWaitingForAutoPopup(applyId)) {
return;
}
if (!context.mounted || !_canAutoShowCpInviteDialog(context)) {
_cpInviteLog(
'skip local gift waiting reason=voice_room_hidden_after_status '
'applyId=$applyId receiverId=$receiverId',
);
return;
}
if (!_shownCpInviteMessageKeys.add(applyId)) {
_cpInviteLog(
'skip duplicated local gift waiting applyId=$applyId '
@ -1068,15 +1091,6 @@ class RealTimeMessagingManager extends ChangeNotifier {
return;
}
final context = navigatorKey.currentState?.context;
if (context == null || !context.mounted) {
_cpInviteLog(
'skip local gift waiting reason=no_context '
'applyId=$applyId receiverId=$receiverId',
);
return;
}
final currentName = _cpInviteDisplayName(
nickname: currentProfile.userNickname,
account: currentProfile.account,
@ -1161,16 +1175,6 @@ class RealTimeMessagingManager extends ChangeNotifier {
);
return;
}
if (!await _isCpInviteApplyWaitingForAutoPopup(applyId)) {
return;
}
final messageKey = applyId.isNotEmpty ? applyId : message?.msgID ?? "";
if (messageKey.isNotEmpty && !_shownCpInviteMessageKeys.add(messageKey)) {
_cpInviteLog(
'skip duplicated CP_BUILD applyId=$applyId msgId=${message?.msgID}',
);
return;
}
final context = navigatorKey.currentState?.context;
final currentProfile = AccountStorage().getCurrentUser()?.userProfile;
if (context == null || currentProfile == null) {
@ -1183,6 +1187,29 @@ class RealTimeMessagingManager extends ChangeNotifier {
_cpInviteLog('skip CP_BUILD reason=context_unmounted applyId=$applyId');
return;
}
if (!_canAutoShowCpInviteDialog(context)) {
_cpInviteLog(
'skip CP_BUILD reason=not_in_visible_voice_room applyId=$applyId',
);
return;
}
if (!await _isCpInviteApplyWaitingForAutoPopup(applyId)) {
return;
}
if (!context.mounted || !_canAutoShowCpInviteDialog(context)) {
_cpInviteLog(
'skip CP_BUILD reason=voice_room_hidden_after_status '
'applyId=$applyId',
);
return;
}
final messageKey = applyId.isNotEmpty ? applyId : message?.msgID ?? "";
if (messageKey.isNotEmpty && !_shownCpInviteMessageKeys.add(messageKey)) {
_cpInviteLog(
'skip duplicated CP_BUILD applyId=$applyId msgId=${message?.msgID}',
);
return;
}
if (_cpInviteTargetsCurrentAsSenderAndReceiver(
invite,
currentProfile,
@ -1507,6 +1534,13 @@ class RealTimeMessagingManager extends ChangeNotifier {
required _CpInviteProcessResult result,
required String relationType,
}) async {
if (!_canAutoShowCpInviteDialog(context)) {
_cpInviteLog(
'skip CP invite result dialog reason=not_in_visible_voice_room '
'result=${result.name} relationType=$relationType',
);
return;
}
final isSender = _cpInviteSenderMatchesCurrent(
invite,
currentProfile,
@ -1890,6 +1924,29 @@ class RealTimeMessagingManager extends ChangeNotifier {
.trim();
}
bool _canAutoShowCpInviteDialog(BuildContext context) {
if (!context.mounted) {
return false;
}
try {
final rtcProvider = Provider.of<RealTimeCommunicationManager>(
context,
listen: false,
);
final roomProfile = rtcProvider.currenRoom?.roomProfile?.roomProfile;
final roomId = roomProfile?.id?.trim() ?? "";
final groupId = roomProfile?.roomAccount?.trim() ?? "";
return rtcProvider.isVoiceRoomRouteVisible &&
(roomId.isNotEmpty || groupId.isNotEmpty);
} catch (error) {
_cpInviteLog(
'skip auto CP invite dialog reason=voice_room_state_unavailable '
'error=$error',
);
return false;
}
}
SocialChatUserProfile _cpInviteInviterProfile(
SCSystemInvitMessageRes invite,
) {
@ -3112,6 +3169,10 @@ class RealTimeMessagingManager extends ChangeNotifier {
msg.noticeAction != "RELATION_ESTABLISHED") {
return;
}
final currentContext = context;
if (currentContext == null || !_canAutoShowCpInviteDialog(currentContext)) {
return;
}
final currentProfile = AccountStorage().getCurrentUser()?.userProfile;
if (currentProfile == null) {
return;
@ -3175,18 +3236,19 @@ class RealTimeMessagingManager extends ChangeNotifier {
}
void _showCpInviteRejectedDialog(String relationType, {String? dedupKey}) {
final context = navigatorKey.currentState?.context;
if (context == null || !_canAutoShowCpInviteDialog(context)) {
_cpInviteLog(
'skip rejected dialog reason=not_in_visible_voice_room '
'relationType=$relationType',
);
return;
}
final key = dedupKey?.trim() ?? "";
if (key.isNotEmpty && !_shownCpInviteRejectedDialogKeys.add(key)) {
_cpInviteLog('skip duplicated rejected dialog key=$key');
return;
}
final context = navigatorKey.currentState?.context;
if (context == null) {
_cpInviteLog(
'skip rejected dialog reason=no_context relationType=$relationType',
);
return;
}
final localizations = SCAppLocalizations.of(context);
SmartDialog.show(
tag: "showConfirmDialog",