sendMessage static method
Future<V2TimValueCallback<V2TimMessage> >
sendMessage({
- required String id,
- required String receiver,
- required String groupID,
- int priority = 0,
- bool onlineUserOnly = false,
- bool isExcludedFromUnreadCount = false,
- bool isExcludedFromLastMessage = false,
- bool? isSupportMessageExtension = false,
- bool needReadReceipt = false,
- bool? isExcludedFromContentModeration = true,
- Map<
String, dynamic> ? offlinePushInfo, - String? cloudCustomData,
- String? localCustomData,
Implementation
static Future<V2TimValueCallback<V2TimMessage>> sendMessage({
required String id,
required String receiver,
required String groupID,
int priority = 0,
bool onlineUserOnly = false,
bool isExcludedFromUnreadCount = false,
bool isExcludedFromLastMessage = false,
bool? isSupportMessageExtension = false,
bool needReadReceipt = false,
bool? isExcludedFromContentModeration = true,
Map<String, dynamic>? offlinePushInfo,
// 自定义消息需要
String? cloudCustomData, // 云自定义消息字段,只能在消息发送前添加
String? localCustomData,
}) async {
if (!createdMessage.containsKey(id)) {
return V2TimValueCallback<V2TimMessage>.fromJson({
"code": -1,
"desc": "id not exist please try create again",
});
} else {
Map<String, dynamic> message = createdMessage.remove(id)!;
Map<String, dynamic> fullmessage = Tools.createNativeSendMessage(
createdMessage: message,
groupId: groupID,
userID: receiver,
priority: priority,
onlineUserOnly: onlineUserOnly,
isExcludedFromLastMessage: isExcludedFromLastMessage,
isExcludedFromUnreadCount: isExcludedFromUnreadCount,
needReadReceipt: needReadReceipt,
localCustomData: localCustomData,
cloudCustomData: cloudCustomData,
isSupportMessageExtension: isSupportMessageExtension,
isExcludedFromContentModeration: isExcludedFromContentModeration,
offlinePushInfo: offlinePushInfo != null ? Tools.generateNativeOfflinePushInfoByDart(OfflinePushInfo.fromJson(offlinePushInfo)) : null,
);
String userData = Tools.generateUserData();
Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
Pointer<Uint8> json_msg_param = Tools.string2PointerInt8(json.encode(fullmessage));
Pointer<Uint8> conv_id = Tools.string2PointerInt8(groupID.isEmpty ? receiver : groupID);
int res = desktopSDK.D_TIMMsgSendMessage(
conv_id,
groupID.isEmpty ? 1 : 2,
json_msg_param,
user_data,
);
if (res != TIMResult.TIM_SUCC) {
return V2TimValueCallback<V2TimMessage>.fromJson({
"code": res,
"desc": "",
});
} else {
Map<String, dynamic> data = await getAsyncData(
apiKey: userData,
maxtimeout: 20000,
);
Map<String, dynamic> nativeData = Map<String, dynamic>.from(json.decode(data["json_param"].isEmpty ? json.encode({}) : data["json_param"]));
Map<String, dynamic> DartData = (await Tools.convertMessage2Dart(nativeData)).toJson();
DartData["id"] = id; // add id after send
return V2TimValueCallback<V2TimMessage>.fromJson({
"code": data["code"],
"desc": data["desc"],
"data": DartData,
});
}
}
}