sendMsgToCurrentChat static method
void
sendMsgToCurrentChat({
- required CreateMsgType createMsgType,
- dynamic data,
- String? customMsgDesc,
- String? customMsgExtension,
发送消息到当前打开的聊天中
自定义消息
Implementation
static void sendMsgToCurrentChat({
required CreateMsgType createMsgType,
dynamic data,
String? customMsgDesc,
String? customMsgExtension,
}) async {
if (createMsgType == CreateMsgType.custom) {
if (data is! String) {
developerLog('自定义消息,data 参数只允许传入 字符串 类型');
throw Exception('自定义消息,data 参数只允许传入 字符串 类型');
}
}
if (ImState.currentFocusConversationNative.value != null) {
ConversationType? conversationType;
if (ImState.currentFocusConversationNative.value!['conv_type'] == 2) {
conversationType = ConversationType.convGroup;
} else if (ImState.currentFocusConversationNative.value!['conv_type'] == 1) {
conversationType = ConversationType.convC2c;
} else {
debugPrint('${ImState.currentFocusConversationNative.value!['conv_type']} 发送消息方式暂未完成开发,若需要请您联系插件开发者');
}
if (conversationType != null) {
try {
final res = await ImPluginTencent.sendMessage(
createMsgType: createMsgType,
createMsgInfo: CreateMsgInfo(
to: ImState.currentFocusConversationNative.value!['conv_id'],
conversationType: conversationType,
payload: data,
),
);
Map<String, dynamic> msg = Map<String, dynamic>.from(res['json_param']);
ImState.addMessageNative(msg);
EventBus.instance.fire(MyEvent(key: 'chat-onSendMessage', data: {
'convId': msg['message_conv_id'],
}));
} catch(e) {
debugPrint('发送消息失败 | $e');
}
}
}
}