sendDirectionalMessageWithOption static method
Future<Message?>
sendDirectionalMessageWithOption(
- int? conversationType,
- String? targetId,
- List userIdList,
- MessageContent? content,
- SendMessageOption option, {
- String? pushContent,
- String? pushData,
- dynamic finished()?,
发送定向消息
conversationType
会话类型,参见枚举 RCConversationType
targetId
会话 id
userIdList
接收消息的用户 ID 列表
content
消息内容 参见 MessageContent
pushContent
接收方离线时需要显示的远程推送内容
pushData
接收方离线时需要在远程推送中携带的非显示数据
此方法用于在群组中发送消息给其中的部分用户,其它用户不会收到这条消息。 目前仅支持群组。
Implementation
static Future<Message?> sendDirectionalMessageWithOption(int? conversationType, String? targetId, List userIdList, MessageContent? content, SendMessageOption option, {String? pushContent, String? pushData, Function(int messageId, int status, int code)? finished}) async {
if (conversationType == null || targetId == null || content == null) {
developer.log("send directional message fail: conversationType or targetId or content is null", name: "RongIMClient");
return null;
}
if (userIdList.length <= 0) {
developer.log("userIdList 为空", name: "RongIMClient");
return null;
}
if (pushContent == null) {
pushContent = "";
}
if (pushData == null) {
pushData = "";
}
String? jsonStr = content.encode();
String? objName = content.getObjectName();
// 此处获取当前时间戳传给原生方法,并且当做 sendMessageCallbacks 的 key 记录 finished
DateTime time = DateTime.now();
int timestamp = time.millisecondsSinceEpoch;
Map map = {'conversationType': conversationType, 'targetId': targetId, 'userIdList': userIdList, "content": jsonStr, "objectName": objName, "pushContent": pushContent, "pushData": pushData, "option": option.isVoIPPush, "timestamp": timestamp};
if (finished != null) {
sendMessageCallbacks[timestamp] = finished;
}
Map? resultMap = await _channel.invokeMethod(RCMethodKey.SendDirectionalMessage, map);
if (resultMap == null) {
return null;
}
String? messageString = resultMap["message"];
Message? msg = MessageFactory.instance!.string2Message(messageString);
return msg;
}