|
|
|
@ -45,6 +45,9 @@ class ChatController extends GetxController { |
|
|
|
// 需要显示508错误提示的消息ID集合(临时状态,不持久化) |
|
|
|
final Set<String> _roseErrorMessageIds = <String>{}; |
|
|
|
|
|
|
|
// 需要显示敏感词错误提示的消息ID集合(临时状态,不持久化) |
|
|
|
final Set<String> _sensitiveWordMessageIds = <String>{}; |
|
|
|
|
|
|
|
// 网络服务 |
|
|
|
final NetworkService _networkService = NetworkService(); |
|
|
|
|
|
|
|
@ -58,6 +61,17 @@ class ChatController extends GetxController { |
|
|
|
_roseErrorMessageIds.add(messageId); |
|
|
|
update(); |
|
|
|
} |
|
|
|
|
|
|
|
/// 检查消息是否需要显示敏感词错误提示 |
|
|
|
bool shouldShowSensitiveWordError(String messageId) { |
|
|
|
return _sensitiveWordMessageIds.contains(messageId); |
|
|
|
} |
|
|
|
|
|
|
|
/// 添加需要显示敏感词错误提示的消息ID |
|
|
|
void addSensitiveWordMessageId(String messageId) { |
|
|
|
_sensitiveWordMessageIds.add(messageId); |
|
|
|
update(); |
|
|
|
} |
|
|
|
|
|
|
|
ChatController({ |
|
|
|
required this.userId, |
|
|
|
@ -753,6 +767,22 @@ class ChatController extends GetxController { |
|
|
|
.toList(); |
|
|
|
|
|
|
|
if (newMessages.isNotEmpty) { |
|
|
|
// 从新消息的 attributes 中恢复错误码状态 |
|
|
|
for (var msg in newMessages) { |
|
|
|
if (msg.status == MessageStatus.FAIL && msg.direction == MessageDirection.SEND) { |
|
|
|
try { |
|
|
|
final errorCode = msg.attributes?['errorCode'] as String?; |
|
|
|
if (errorCode == 'E0002') { |
|
|
|
_roseErrorMessageIds.add(msg.msgId); |
|
|
|
} else if (errorCode == 'E0001') { |
|
|
|
_sensitiveWordMessageIds.add(msg.msgId); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
// 忽略错误 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
messages.insertAll(0, newMessages); |
|
|
|
// 更新游标为最旧的消息ID(列表开头) |
|
|
|
_cursor = newMessages.first.msgId; |
|
|
|
@ -769,8 +799,9 @@ class ChatController extends GetxController { |
|
|
|
} else { |
|
|
|
// 刷新时替换整个列表,但需要去重(处理重发消息的情况) |
|
|
|
// 对于相同内容的消息,只保留最新的(msgId更大的) |
|
|
|
// 重新进入页面时,清空临时错误提示状态(不持久化) |
|
|
|
// 重新进入页面时,清空临时错误提示状态,然后从消息 attributes 中恢复 |
|
|
|
_roseErrorMessageIds.clear(); |
|
|
|
_sensitiveWordMessageIds.clear(); |
|
|
|
|
|
|
|
final Map<String, EMMessage> contentToMessage = {}; |
|
|
|
|
|
|
|
@ -802,6 +833,22 @@ class ChatController extends GetxController { |
|
|
|
// 按时间戳排序(从旧到新) |
|
|
|
deduplicatedMessages.sort((a, b) => a.serverTime.compareTo(b.serverTime)); |
|
|
|
|
|
|
|
// 从消息 attributes 中恢复错误码状态 |
|
|
|
for (var msg in deduplicatedMessages) { |
|
|
|
if (msg.status == MessageStatus.FAIL && msg.direction == MessageDirection.SEND) { |
|
|
|
try { |
|
|
|
final errorCode = msg.attributes?['errorCode'] as String?; |
|
|
|
if (errorCode == 'E0002') { |
|
|
|
_roseErrorMessageIds.add(msg.msgId); |
|
|
|
} else if (errorCode == 'E0001') { |
|
|
|
_sensitiveWordMessageIds.add(msg.msgId); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
// 忽略错误 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
messages.assignAll(deduplicatedMessages); |
|
|
|
// 更新游标为最旧的消息ID(列表开头) |
|
|
|
if (deduplicatedMessages.isNotEmpty) { |
|
|
|
|