|
|
|
@ -1743,7 +1743,7 @@ class IMManager { |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否是GIFT消息 |
|
|
|
if (content.startsWith('[GIFT:]')) { |
|
|
|
if (content != null && content.startsWith('[GIFT:]')) { |
|
|
|
return '[礼物]'; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1823,6 +1823,98 @@ class IMManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// 修改消息(可同时修改消息体和消息扩展属性) |
|
|
|
/// [messageId] 要修改的消息ID |
|
|
|
/// [msgBody] 新的消息体(可选,如果为null则不修改消息体) |
|
|
|
/// [attributes] 新的消息扩展属性(可选,如果为null则不修改扩展属性) |
|
|
|
Future<bool> modifyMessage({ |
|
|
|
required String messageId, |
|
|
|
EMMessageBody? msgBody, |
|
|
|
Map<String, String>? attributes, |
|
|
|
}) async { |
|
|
|
try { |
|
|
|
if (messageId.isEmpty) { |
|
|
|
if (Get.isLogEnable) { |
|
|
|
Get.log('❌ [IMManager] 消息ID为空,无法修改'); |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// 如果既没有提供消息体也没有提供扩展属性,则无法修改 |
|
|
|
if (msgBody == null && attributes == null) { |
|
|
|
if (Get.isLogEnable) { |
|
|
|
Get.log('❌ [IMManager] 消息体和扩展属性都为空,无法修改'); |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// 调用SDK的修改消息方法 |
|
|
|
await EMClient.getInstance.chatManager.modifyMessage( |
|
|
|
messageId: messageId, |
|
|
|
msgBody: msgBody, |
|
|
|
attributes: attributes, |
|
|
|
); |
|
|
|
|
|
|
|
// 刷新会话列表 |
|
|
|
_refreshConversationList(); |
|
|
|
|
|
|
|
// 通知对应的 ChatController 更新消息 |
|
|
|
_notifyMessageModified(messageId, msgBody, attributes); |
|
|
|
|
|
|
|
return true; |
|
|
|
} catch (e) { |
|
|
|
if (Get.isLogEnable) { |
|
|
|
Get.log('❌ [IMManager] 消息修改失败: messageId=$messageId, 错误: $e'); |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// 通知 ChatController 消息已被修改 |
|
|
|
void _notifyMessageModified( |
|
|
|
String messageId, |
|
|
|
EMMessageBody? msgBody, |
|
|
|
Map<String, String>? attributes, |
|
|
|
) { |
|
|
|
try { |
|
|
|
// 遍历所有活跃的 ChatController,查找包含该消息的控制器 |
|
|
|
for (var entry in _activeChatControllers.entries) { |
|
|
|
final controller = entry.value; |
|
|
|
final index = controller.messages.indexWhere((msg) => msg.msgId == messageId); |
|
|
|
if (index != -1) { |
|
|
|
// 找到消息,更新它 |
|
|
|
final message = controller.messages[index]; |
|
|
|
|
|
|
|
// 如果提供了新的消息体,更新消息体 |
|
|
|
if (msgBody != null) { |
|
|
|
// 注意:EMMessage 的 body 是只读的,需要通过重新获取消息来更新 |
|
|
|
// 这里我们更新消息的扩展属性,消息体需要通过重新获取消息来更新 |
|
|
|
if (Get.isLogEnable) { |
|
|
|
Get.log('⚠️ [IMManager] 消息体修改需要重新获取消息: messageId=$messageId'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 如果提供了新的扩展属性,更新扩展属性 |
|
|
|
if (attributes != null) { |
|
|
|
message.attributes ??= {}; |
|
|
|
message.attributes!.addAll(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
// 通知UI更新 |
|
|
|
controller.update(); |
|
|
|
|
|
|
|
if (Get.isLogEnable) { |
|
|
|
Get.log('✅ [IMManager] 已通知ChatController更新消息: userId=${entry.key}, messageId=$messageId'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
if (Get.isLogEnable) { |
|
|
|
Get.log('⚠️ [IMManager] 通知ChatController消息修改失败: $e'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// 撤回消息 |
|
|
|
Future<bool> recallMessage(EMMessage message) async { |
|
|
|
try { |
|
|
|
|