diff --git a/lib/modules/chat/message_chat_page.dart b/lib/modules/chat/message_chat_page.dart index 23b53fe..5af2282 100644 --- a/lib/modules/chat/message_chat_page.dart +++ b/lib/modules/chat/message_chat_page.dart @@ -146,6 +146,7 @@ class _SCMessageChatPageState extends State { SocialChatUserProfile? friend; SCVipResourceRes? _selfVipChatBubble; bool _isSelfVipChatBubbleLoading = false; + final Map _localCpInviteStates = {}; ///是否显示发送按钮 bool showSend = false; @@ -602,6 +603,8 @@ class _SCMessageChatPageState extends State { currentConversationMessageList[i].sender == "administrator", friend: friend, currentConversationMessageList: currentConversationMessageList, + localCpInviteStates: _localCpInviteStates, + onCpInviteStateChanged: _setLocalCpInviteState, updateCall: () { setState(() {}); }, @@ -614,6 +617,17 @@ class _SCMessageChatPageState extends State { ); } + void _setLocalCpInviteState(String applyId, _CpInviteMessageState state) { + final normalizedApplyId = applyId.trim(); + if (normalizedApplyId.isEmpty) { + return; + } + _localCpInviteStates[normalizedApplyId] = state; + if (mounted) { + setState(() {}); + } + } + List _messagesInDisplayOrder(List messages) { final indexedMessages = messages.asMap().entries.toList(); indexedMessages.sort((left, right) { @@ -1177,6 +1191,9 @@ class _MessageItem extends StatelessWidget { final SocialChatUserProfile? friend; bool isSystem = false; List currentConversationMessageList = []; + final Map localCpInviteStates; + final void Function(String applyId, _CpInviteMessageState state)? + onCpInviteStateChanged; Function updateCall; ///上一条 @@ -1190,6 +1207,8 @@ class _MessageItem extends StatelessWidget { // this.userProfile, this.isSystem = false, required this.currentConversationMessageList, + this.localCpInviteStates = const {}, + this.onCpInviteStateChanged, this.friend, required this.updateCall, }); @@ -1526,7 +1545,7 @@ class _MessageItem extends StatelessWidget { if (data == null || !_isCpInvitePayload(data)) { return null; } - if (_cpInviteStateFromData(data) != _CpInviteMessageState.accepted) { + if (_cpInviteStateForMessage(data) != _CpInviteMessageState.accepted) { return null; } final cpInvite = _cpInviteFromMessageData(data); @@ -1667,7 +1686,7 @@ class _MessageItem extends StatelessWidget { if (data == null || !_isCpInvitePayload(data)) { return null; } - final state = _cpInviteStateFromData(data); + final state = _cpInviteStateForMessage(data); if (state == _CpInviteMessageState.pending) { return null; } @@ -1922,6 +1941,10 @@ class _MessageItem extends StatelessWidget { return; } SmartDialog.dismiss(tag: RoomCpInviteDialog.dialogTag); + onCpInviteStateChanged?.call( + applyId, + agree ? _CpInviteMessageState.accepted : _CpInviteMessageState.rejected, + ); _cpMessageLog( 'process submitted applyId=$applyId agree=$agree ' 'wait_backend_result=true', @@ -2009,6 +2032,10 @@ class _MessageItem extends StatelessWidget { } _CpInviteMessageState _cpInviteStateForMessage(Map data) { + final localState = _localCpInviteStateForData(data); + if (localState != null) { + return localState; + } final explicitState = _cpInviteStateFromConversation(data); if (explicitState != _CpInviteMessageState.pending) { return explicitState; @@ -2022,6 +2049,10 @@ class _MessageItem extends StatelessWidget { Map currentData, ) { final applyId = _cpApplyIdFromData(currentData); + final localState = _localCpInviteStateForApplyId(applyId); + if (localState != null) { + return localState; + } final currentState = _cpInviteStateFromData(currentData); if (currentState != _CpInviteMessageState.pending || applyId.isEmpty) { return currentState; @@ -2043,6 +2074,18 @@ class _MessageItem extends StatelessWidget { return _CpInviteMessageState.pending; } + _CpInviteMessageState? _localCpInviteStateForData(Map data) { + return _localCpInviteStateForApplyId(_cpApplyIdFromData(data)); + } + + _CpInviteMessageState? _localCpInviteStateForApplyId(String applyId) { + final normalizedApplyId = applyId.trim(); + if (normalizedApplyId.isEmpty) { + return null; + } + return localCpInviteStates[normalizedApplyId]; + } + bool _isDuplicateCpInviteMessageForConversation(Map data) { final currentKey = _cpInviteMessageDedupKey(data); if (currentKey.isEmpty) { @@ -2086,7 +2129,7 @@ class _MessageItem extends StatelessWidget { if (!_isCpInvitePayload(data)) { return ""; } - final state = _cpInviteStateFromData(data); + final state = _cpInviteStateForMessage(data); final applyId = _cpApplyIdFromData(data); if (applyId.isEmpty) { return "";