public class MessageApi extends Object
构造器和说明 |
---|
MessageApi(Context context) |
限定符和类型 | 方法和说明 |
---|---|
reactor.core.publisher.Flux<MissedMessageCount> |
countMissedMessages(String username)
查询用户离线消息数。
|
reactor.core.publisher.Mono<Void> |
deleteChannel(String username,
String channelName,
String channelType,
Boolean deleteRoam)
服务端单向删除会话。
|
reactor.core.publisher.Mono<Path> |
getHistoryAsLocalFile(Instant instant,
Path dir,
String filename)
下载消息历史文件到本地。
|
reactor.core.publisher.Mono<String> |
getHistoryAsUri(Instant instant)
获取消息历史文件的下载地址。
|
reactor.core.publisher.Mono<String> |
importChatGroupMessage(String from,
String to,
EMMessage message,
Set<EMKeyValue> extensions,
Boolean isAckRead,
Long msgTimestamp,
Boolean needDownload)
导入群聊消息
API使用示例:
例如,导入带扩展字段的文本消息
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
Instant time = Instant.parse("2021-05-20T18:00:00.631Z").minusMillis((TimeUnit.HOURS.toMillis(8)));
Long msgTimestamp = time.toEpochMilli();
String groupId = "18273849454"
String messageId = service.message()
.importChatGroupMessage("fromUserName", groupId,
textMessage, exts, true, msgTimestamp, false)
.block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
|
reactor.core.publisher.Mono<String> |
importChatMessage(String from,
String to,
EMMessage message,
Set<EMKeyValue> extensions,
Boolean isAckRead,
Long msgTimestamp,
Boolean needDownload)
导入单聊消息
API使用示例:
例如,导入带扩展字段的文本消息
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
Instant time = Instant.parse("2021-05-20T18:00:00.631Z").minusMillis((TimeUnit.HOURS.toMillis(8)));
Long msgTimestamp = time.toEpochMilli();
String messageId = service.message()
.importChatMessage("fromUserName", "toUserName",
textMessage, exts, true, msgTimestamp, false)
.block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
|
ImportMessage |
importMessage()
构造消息并导入。
|
reactor.core.publisher.Mono<Boolean> |
isMessageDeliveredToUser(String messageId,
String toUser)
查询某条离线消息的状态,如是否已经传达。
|
reactor.core.publisher.Mono<Void> |
modifyTextOrCustomMessage(String messageId,
String username,
NewMessage newMessage,
Map<String,Object> newExt,
Boolean isCombineExt)
修改文本或自定义消息,若使用该功能,需联系环信商务开通。
|
reactor.core.publisher.Mono<Void> |
oneWayClearGroupOrRoomRoamingMessagesWithinPeriod(String username,
String id,
long time)
单向清空指定群组或聊天室会话一段时间内的漫游消息
清空后,该用户无法从环信服务端拉取到这些漫游消息。
|
reactor.core.publisher.Mono<Void> |
oneWayClearUserAllRoamingMessage(String username)
单向清空指定用户的漫游消息
清空指定用户当前时间及之前的所有漫游消息。
|
reactor.core.publisher.Mono<Void> |
oneWayClearUserRoamingMessagesWithinPeriod(String username,
String clearUser,
long time)
单向清空指定单聊会话一段时间内的漫游消息
清空后,该用户无法从服务端拉取到漫游消息,而且该用户的所有会话也会被清除,也拉不到会话列表。
|
reactor.core.publisher.Mono<Void> |
recallMessage(List<RecallMessageSource> messageSources)
已过时。
|
reactor.core.publisher.Mono<Void> |
recallMsg(RecallMessageSource recallMessage)
消息撤回。
|
SendMessage |
send()
已过时。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
send(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions)
已过时。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
send(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
Boolean syncDevice)
已过时。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
send(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
String routeType)
已过时。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
send(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
String routeType,
Boolean syncDevice)
已过时。
|
MessageSend |
sendMsg()
构造消息并发送。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendMsg(String from,
Set<String> toGroups,
EMMessage message,
Set<String> toGroupUsers,
Set<EMKeyValue> extensions,
Boolean syncDevice)
指定群组用户发送消息,你可以向群组中指定的一个或多个成员发送消息,但单次仅支持指定一个群组。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendMsg(String from,
Set<String> toRooms,
EMMessage message,
Set<String> toRoomUsers,
Set<EMKeyValue> extensions,
Boolean syncDevice,
ChatroomMsgLevel chatroomMsgLevel)
指定聊天室用户发送消息,你可以向聊天室中指定的一个或多个成员发送消息,但单次仅支持指定一个聊天室。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendMsg(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions)
发送消息。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendMsg(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
Boolean syncDevice)
发送消息。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendMsg(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
String routeType)
发送消息(只投递在线消息)。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendMsg(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
String routeType,
Boolean syncDevice)
发送消息。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendMsg(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
String routeType,
Boolean syncDevice,
ChatroomMsgLevel chatroomMsgLevel)
发送消息,支持设置聊天室消息优先级。
|
reactor.core.publisher.Mono<EMSentMessageIds> |
sendRoomBroadcastMsg(String from,
EMMessage message,
Set<EMKeyValue> extensions,
Boolean syncDevice,
ChatroomMsgLevel chatroomMsgLevel)
发送聊天室全局广播消息。
|
reactor.core.publisher.Mono<EMSentMessageResults> |
sendWithoutMsgId(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions)
已过时。
|
reactor.core.publisher.Mono<EMSentMessageResults> |
sendWithoutMsgId(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
Boolean syncDevice)
已过时。
|
reactor.core.publisher.Mono<EMSentMessageResults> |
sendWithoutMsgId(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
String routeType)
已过时。
|
reactor.core.publisher.Mono<EMSentMessageResults> |
sendWithoutMsgId(String from,
String toType,
Set<String> tos,
EMMessage message,
Set<EMKeyValue> extensions,
String routeType,
Boolean syncDevice)
已过时。
|
public MessageApi(Context context)
public reactor.core.publisher.Flux<MissedMessageCount> countMissedMessages(String username)
API使用示例:
EMService service;
try {
List<MissedMessageCount> messages = service.message().countMissedMessages("username").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 用户名public reactor.core.publisher.Mono<Boolean> isMessageDeliveredToUser(String messageId, String toUser)
API使用示例:
EMService service;
try {
Boolean isDelivered = service.message().isMessageDeliveredToUser("messageId", "toUser").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
messageId
- 要查看对消息IDtoUser
- 消息接收方的用户名@Deprecated public SendMessage send()
例如,向用户发送一条带有扩展字段的文本消息:
EMService service;
try {
service.message().send()
.fromUser("alice").toUser("rabbit")
.text(msg -> msg.text("hello"))
.extension(exts -> exts.add(EMKeyValue.of("timeout", 1)))
.send()
.block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
如果需要向一个群组或聊天室发消息,将示例中的 toUser 改成 toGroup 或 toRoom,并传入对应的群组或聊天室id
如果需要向多个用户或群组或聊天室发消息,将示例中的 toUser 改成 toUsers 或 toGroups 或 toRooms,并传入对应的用户或群组或聊天室id
将上述发送文本消息示例中的 `.text(...) `替换掉,来发送其他类型消息示例:
发送图片消息:.image(msg -> msg.uri(URI.create("http://example/image.png")).secret("secret").displayName("image.png"))
发送语音消息:.voice(msg -> msg.uri(URI.create("http://example/voice.amr")).duration(3).secret("secret").displayName("voice.amr"))
发送视频消息:.video(msg -> msg.uri(URI.create("http://example/video.mp4")).duration(3).secret("secret").displayName("video.mp4").thumb("http://example/videoThumbnail").thumbSecret("thumbSecret"))
发送文件消息:.file(msg -> msg.uri(URI.create("http://example/file.txt")).secret("secret").displayName("file.txt"))
发送位置消息:.location(msg -> msg.latitude(1.234567).longitude(1.234567).address("some where"))
发送自定义类型消息:.custom(msg -> msg.customEvent("liked").customExtension("name", "forest"))
public MessageSend sendMsg()
例如,向用户发送一条带有扩展字段的文本消息:
EMService service;
try {
service.message().sendMsg()
.fromUser("alice").toUser("rabbit")
.text(msg -> msg.text("hello"))
.extension(exts -> exts.add(EMKeyValue.of("timeout", 1)))
.send()
.block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
如果需要向一个群组或聊天室发消息,将示例中的 toUser 改成 toGroup 或 toRoom,并传入对应的群组或聊天室id
如果需要向多个用户或群组或聊天室发消息,将示例中的 toUser 改成 toUsers 或 toGroups 或 toRooms,并传入对应的用户或群组或聊天室id
将上述发送文本消息示例中的 `.text(...) `替换掉,来发送其他类型消息示例:
发送图片消息:.image(msg -> msg.uri(URI.create("http://example/image.png")).secret("secret").displayName("image.png"))
发送语音消息:.voice(msg -> msg.uri(URI.create("http://example/voice.amr")).duration(3).secret("secret").displayName("voice.amr"))
发送视频消息:.video(msg -> msg.uri(URI.create("http://example/video.mp4")).duration(3).secret("secret").displayName("video.mp4").thumb("http://example/videoThumbnail").thumbSecret("thumbSecret"))
发送文件消息:.file(msg -> msg.uri(URI.create("http://example/file.txt")).secret("secret").displayName("file.txt"))
发送位置消息:.location(msg -> msg.latitude(1.234567).longitude(1.234567).address("some where"))
发送自定义类型消息:.custom(msg -> msg.customEvent("liked").customExtension("name", "forest"))
@Deprecated public reactor.core.publisher.Mono<EMSentMessageIds> send(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "users", toUsers, textMessage, exts).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "chatgroups", toGroups, imageMessage, exts1).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息,EMTextMessage文本消息,EMImageMessage图片消息,EMVoiceMessage语音消息,
EMVideoMessage视频消息,EMFileMessage文件消息,EMCommandMessage透传消息,EMCustomMessage自定义类型消息,
各种类型消息需要自己构造extensions
- 要发送的扩展,可以为空public reactor.core.publisher.Mono<EMSentMessageIds> sendMsg(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "users", toUsers, textMessage, exts).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "chatgroups", toGroups, imageMessage, exts1).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息,EMTextMessage文本消息,EMImageMessage图片消息,EMVoiceMessage语音消息,
EMVideoMessage视频消息,EMFileMessage文件消息,EMCommandMessage透传消息,EMCustomMessage自定义类型消息,
各种类型消息需要自己构造extensions
- 要发送的扩展,可以为空@Deprecated public reactor.core.publisher.Mono<EMSentMessageResults> sendWithoutMsgId(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendWithoutMsgId("fromUserName", "users", toUsers, textMessage, exts).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().sendWithoutMsgId("fromUserName", "chatgroups", toGroups, imageMessage, exts1).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息,EMTextMessage文本消息,EMImageMessage图片消息,EMVoiceMessage语音消息,
EMVideoMessage视频消息,EMFileMessage文件消息,EMCommandMessage透传消息,EMCustomMessage自定义类型消息,
各种类型消息需要自己构造extensions
- 要发送的扩展,可以为空@Deprecated public reactor.core.publisher.Mono<EMSentMessageIds> send(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, String routeType)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "users", toUsers, textMessage, exts, "ROUTE_ONLINE").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "chatgroups", toGroups, imageMessage, exts1, "ROUTE_ONLINE").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空routeType
- 只投递在线消息,请传入 `ROUTE_ONLINE`public reactor.core.publisher.Mono<EMSentMessageIds> sendMsg(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, String routeType)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "users", toUsers, textMessage, exts, "ROUTE_ONLINE").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "chatgroups", toGroups, imageMessage, exts1, "ROUTE_ONLINE").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空routeType
- 只投递在线消息,请传入 `ROUTE_ONLINE`public reactor.core.publisher.Mono<EMSentMessageIds> sendMsg(String from, Set<String> toGroups, EMMessage message, Set<String> toGroupUsers, Set<EMKeyValue> extensions, Boolean syncDevice)
API使用示例:
EMService service;
例如,向指定群组用户发送一条带有扩展字段的文本消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
Set<String> toGroupUsers = new HashSet<>();
toGroupUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", toGroups, textMessage, toGroupUsers, exts, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toGroups
- 消息接收方所属的群组 ID。目前每次只能传 1 个群组 ID。message
- 要发送的消息toGroupUsers
- 接收消息的群成员的用户 ID 数组。每次最多可传 20 个用户 ID。extensions
- 要发送的扩展,可以为空syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方public reactor.core.publisher.Mono<EMSentMessageIds> sendMsg(String from, Set<String> toRooms, EMMessage message, Set<String> toRoomUsers, Set<EMKeyValue> extensions, Boolean syncDevice, ChatroomMsgLevel chatroomMsgLevel)
API使用示例:
EMService service;
例如,向指定聊天室用户发送一条带有扩展字段的文本消息
Set<String> toRooms = new HashSet<>();
toRooms.add("toRoomId");
Set<String> toRoomUsers = new HashSet<>();
toRoomUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", toRooms, textMessage, toRoomUsers, exts, true, ChatroomMsgLevel.NORMAL).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toRooms
- 消息接收方所属的聊天室 ID。目前每次只能传 1 个聊天室 ID。message
- 要发送的消息toRoomUsers
- 接收消息的聊天室成员的用户 ID 数组。每次最多可传 20 个用户 ID。extensions
- 要发送的扩展,可以为空syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方chatroomMsgLevel
- 聊天室消息优先级: LOW-低优先级,NORMAL-普通优先级,HIGH-高优先级@Deprecated public reactor.core.publisher.Mono<EMSentMessageResults> sendWithoutMsgId(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, String routeType)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageResults messageResults = service.message().send("fromUserName", "users", toUsers, textMessage, exts, "ROUTE_ONLINE").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageResults messageResults = service.message().send("fromUserName", "chatgroups", toGroups, imageMessage, exts1, "ROUTE_ONLINE").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空routeType
- 只投递在线消息,请传入 `ROUTE_ONLINE`@Deprecated public reactor.core.publisher.Mono<EMSentMessageIds> send(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, Boolean syncDevice)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "users", toUsers, textMessage, exts, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "chatgroups", toGroups, imageMessage, exts1, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方public reactor.core.publisher.Mono<EMSentMessageIds> sendMsg(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, Boolean syncDevice)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "users", toUsers, textMessage, exts, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "chatgroups", toGroups, imageMessage, exts1, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方@Deprecated public reactor.core.publisher.Mono<EMSentMessageResults> sendWithoutMsgId(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, Boolean syncDevice)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageResults messageResults = service.message().sendWithoutMsgId("fromUserName", "users", toUsers, textMessage, exts, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageResults messageResults = service.message().sendWithoutMsgId("fromUserName", "chatgroups", toGroups, imageMessage, exts1, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方@Deprecated public reactor.core.publisher.Mono<EMSentMessageIds> send(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, String routeType, Boolean syncDevice)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "users", toUsers, textMessage, exts, "ROUTE_ONLINE", true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().send("fromUserName", "chatgroups", toGroups, imageMessage, exts1, "ROUTE_ONLINE", true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空routeType
- 只投递在线消息,请传入 `ROUTE_ONLINE`syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方public reactor.core.publisher.Mono<EMSentMessageIds> sendMsg(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, String routeType, Boolean syncDevice)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "users", toUsers, textMessage, exts, "ROUTE_ONLINE", true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "chatgroups", toGroups, imageMessage, exts1, "ROUTE_ONLINE", true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空routeType
- 只投递在线消息,请传入 `ROUTE_ONLINE`syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方public reactor.core.publisher.Mono<EMSentMessageIds> sendMsg(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, String routeType, Boolean syncDevice, ChatroomMsgLevel chatroomMsgLevel)
API使用示例:
EMService service;
例如,向聊天室发送一条带有扩展字段的图片消息
Set<String> toChatRooms = new HashSet<>();
toChatRooms.add("toChatroomId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
exts.add(EMKeyValue.of("key1", 10));
exts.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageIds messageIds = service.message().sendMsg("fromUserName", "chatrooms", toChatRooms, imageMessage, exts, "ROUTE_ONLINE", true, ChatroomMsgLevel.NORMAL).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空routeType
- 只投递在线消息,请传入 `ROUTE_ONLINE`syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方chatroomMsgLevel
- 聊天室消息优先级: LOW-低优先级,NORMAL-普通优先级,HIGH-高优先级public reactor.core.publisher.Mono<EMSentMessageIds> sendRoomBroadcastMsg(String from, EMMessage message, Set<EMKeyValue> extensions, Boolean syncDevice, ChatroomMsgLevel chatroomMsgLevel)
API使用示例:
EMService service;
例如,发送一条带有扩展字段的文本消息
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageIds messageIds = service.message().sendRoomBroadcastMsg("fromUserName", textMessage, exts, true, ChatroomMsgLevel.NORMAL).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名message
- 要发送的消息extensions
- 要发送的扩展,可以为空syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方chatroomMsgLevel
- 聊天室消息优先级: LOW-低优先级,NORMAL-普通优先级,HIGH-高优先级@Deprecated public reactor.core.publisher.Mono<EMSentMessageResults> sendWithoutMsgId(String from, String toType, Set<String> tos, EMMessage message, Set<EMKeyValue> extensions, String routeType, Boolean syncDevice)
API使用示例:
EMService service;
例如,向用户发送一条带有扩展字段的文本消息
Set<String> toUsers = new HashSet<>();
toUsers.add("toUserName");
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
EMSentMessageResults messageResults = service.message().sendWithoutMsgId("fromUserName", "users", toUsers, textMessage, exts, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
例如,向群组发送一条带有扩展字段的图片消息
Set<String> toGroups = new HashSet<>();
toGroups.add("toGroupId");
EMImageMessage imageMessage =
new EMImageMessage().uri(URI.create("http://example/image.png")).secret("secret")
.displayName("image.png");
Set<EMKeyValue> exts1 = new HashSet<>();
exts1.add(EMKeyValue.of("key", "value"));
exts1.add(EMKeyValue.of("key1", 10));
exts1.add(EMKeyValue.of("key2", new HashMap<String, String>() {
{
put("mkey1", "mvalue1");
put("mkey2", "mvalue2");
}
}));
try {
EMSentMessageResults messageResults = service.message().sendWithoutMsgId("fromUserName", "chatgroups", toGroups, imageMessage, exts1, "ROUTE_ONLINE", true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名toType
- 目标类型,可以是 `users`, `chatgroups`, `chatrooms`tos
- 目标id列表message
- 要发送的消息extensions
- 要发送的扩展,可以为空routeType
- 只投递在线消息,请传入 `ROUTE_ONLINE`syncDevice
- 消息发送成功后,是否将消息同步到发送方,true:是同步给发送方,false:是不同给发送方public reactor.core.publisher.Mono<String> getHistoryAsUri(Instant instant)
历史文件是每小时一个文件,比如指定12:10,则返回12点的历史文件。
API使用示例:
EMService service;
try {
Instant now = Instant.parse("2021-05-20T18:00:00.631Z").minusMillis((TimeUnit.HOURS.toMillis(8)));
String historyUrl = service.message().getHistoryAsUri(now).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
instant
- 时间点public reactor.core.publisher.Mono<Path> getHistoryAsLocalFile(Instant instant, Path dir, String filename)
消息历史文件是gz压缩的。
API使用示例:
EMService service;
Instant now = Instant.parse("2021-05-20T18:00:00.631Z").minusMillis((TimeUnit.HOURS.toMillis(8)));
Path dir = Paths.get("/local/path/...");
try {
Path path = service.message().getHistoryAsLocalFile(now, dir, "filename.gz").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
instant
- 时间点dir
- 下载目录filename
- 文件名,如果为空,则默认为YYYYMMDD.gz@Deprecated public reactor.core.publisher.Mono<Void> recallMessage(List<RecallMessageSource> messageSources)
API使用示例:
EMService service;
try {
List<RecallMessageSource> messageSources = new ArrayList<>();
messageSources.add(new RecallMessageSource("messageId", "chat", "u1", "u2", true));
service.message().recallMessage(messageSources).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
messageSources
- messageSourcespublic reactor.core.publisher.Mono<Void> recallMsg(RecallMessageSource recallMessage)
API使用示例:
EMService service;
try {
RecallMessageSource recallMessage = new RecallMessageSource("messageId", "chat", "u1", "u2", true);
service.message().recallMessage(recallMessage).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
recallMessage
- recallMessagepublic reactor.core.publisher.Mono<Void> deleteChannel(String username, String channelName, String channelType, Boolean deleteRoam)
API使用示例:
EMService service;
try {
service.message().deleteChannel("u1", "u2", "chat", false).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- username 删除会话方,例如 A 要将与 B 的单聊会话删除,username 为 A,channelName 为 BchannelName
- channelName 要删除的会话 IDchannelType
- channelType 会话类型。chat:单聊会话;groupchat:群聊会话deleteRoam
- deleteRoam 是否删除服务端消息,不允许为空。true:是;false:否public ImportMessage importMessage()
例如,导入一条带有扩展字段的单聊文本消息:
EMService service;
try {
service.message().importMessage()
.from("alice")
.toUser("rabbit")
.text(msg -> msg.text("hello"))
.extension(exts -> exts.add(EMKeyValue.of("timeout", 1)))
.isAckRead(true)
.msgTimestamp(Instant.now().toEpochMilli())
.needDownload(true)
.importChatMessage()
.block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
如果需要向一个群组导入消息,将示例中的 toUser 改成 toGroup,并传入对应的群组或聊天室id
将上述发送文本消息示例中的 `.text(...) `替换掉,来发送其他类型消息示例:
导入图片消息:.image(msg -> msg.uri(URI.create("http://example/image.png")).secret("secret").displayName("image.png"))
导入语音消息:.voice(msg -> msg.uri(URI.create("http://example/voice.amr")).duration(3).secret("secret").displayName("voice.amr"))
导入视频消息:.video(msg -> msg.uri(URI.create("http://example/video.mp4")).duration(3).secret("secret").displayName("video.mp4").thumb("http://example/videoThumbnail").thumbSecret("thumbSecret"))
导入文件消息:.file(msg -> msg.uri(URI.create("http://example/file.txt")).secret("secret").displayName("file.txt"))
导入位置消息:.location(msg -> msg.latitude(1.234567).longitude(1.234567).address("some where"))
导入自定义类型消息:.custom(msg -> msg.customEvent("liked").customExtension("name", "forest"))
public reactor.core.publisher.Mono<String> importChatMessage(String from, String to, EMMessage message, Set<EMKeyValue> extensions, Boolean isAckRead, Long msgTimestamp, Boolean needDownload)
例如,导入带扩展字段的文本消息
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
Instant time = Instant.parse("2021-05-20T18:00:00.631Z").minusMillis((TimeUnit.HOURS.toMillis(8)));
Long msgTimestamp = time.toEpochMilli();
String messageId = service.message()
.importChatMessage("fromUserName", "toUserName",
textMessage, exts, true, msgTimestamp, false)
.block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名to
- 目标用户名message
- 要导入的消息,EMTextMessage文本消息,EMImageMessage图片消息,EMVoiceMessage语音消息,
EMVideoMessage视频消息,EMFileMessage文件消息,EMCommandMessage透传消息,EMCustomMessage自定义类型消息,
各种类型消息需要自己构造extensions
- 要导入的扩展内容,可以为空isAckRead
- 是否设置消息为已读msgTimestamp
- 导入的消息的时间戳needDownload
- 是否需要下载附件资源public reactor.core.publisher.Mono<String> importChatGroupMessage(String from, String to, EMMessage message, Set<EMKeyValue> extensions, Boolean isAckRead, Long msgTimestamp, Boolean needDownload)
例如,导入带扩展字段的文本消息
EMTextMessage textMessage = new EMTextMessage().text("hello");
Set<EMKeyValue> exts = new HashSet<>();
exts.add(EMKeyValue.of("key", "value"));
try {
Instant time = Instant.parse("2021-05-20T18:00:00.631Z").minusMillis((TimeUnit.HOURS.toMillis(8)));
Long msgTimestamp = time.toEpochMilli();
String groupId = "18273849454"
String messageId = service.message()
.importChatGroupMessage("fromUserName", groupId,
textMessage, exts, true, msgTimestamp, false)
.block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
from
- 发送者用户名to
- 目标群idmessage
- 要导入的消息,EMTextMessage文本消息,EMImageMessage图片消息,EMVoiceMessage语音消息,
EMVideoMessage视频消息,EMFileMessage文件消息,EMCommandMessage透传消息,EMCustomMessage自定义类型消息,
各种类型消息需要自己构造extensions
- 要导入的扩展内容,可以为空isAckRead
- 是否设置消息为已读msgTimestamp
- 导入的消息的时间戳needDownload
- 是否需要下载附件资源public reactor.core.publisher.Mono<Void> oneWayClearUserAllRoamingMessage(String username)
清空指定用户当前时间及之前的所有漫游消息。 清空后,该用户无法从服务端拉取到漫游消息,而且该用户的所有会话也会被清除,也拉不到会话列表。 不过,其他用户不受影响,仍然可以拉取与该用户的漫游消息和会话。
API使用示例:
EMService service;
try {
service.message().oneWayClearUserAllRoamingMessage("username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 要清空哪个用户的漫游消息。需传入该用户的用户 ID。public reactor.core.publisher.Mono<Void> oneWayClearUserRoamingMessagesWithinPeriod(String username, String clearUser, long time)
清空后,该用户无法从服务端拉取到漫游消息,而且该用户的所有会话也会被清除,也拉不到会话列表。 不过,其他用户不受影响,仍然可以拉取与该用户的漫游消息和会话。
API使用示例:
EMService service;
try {
service.message().oneWayClearUserRoamingMessagesWithinPeriod("username", "clearUser", 1659014868000).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 调用该接口的用户的用户 IDclearUser
- 要清空与哪个用户的单聊会话的漫游消息。需传入该用户的用户 ID。time
- 要清空哪个时间点及之前的单聊漫游消息。该时间为 Unix 时间戳,单位为毫秒public reactor.core.publisher.Mono<Void> oneWayClearGroupOrRoomRoamingMessagesWithinPeriod(String username, String id, long time)
清空后,该用户无法从环信服务端拉取到这些漫游消息。若清除了该会话的全部漫游消息,该用户的这个会话在服务端也会被清除,拉取会话列表时拉不到该会话。 不过,其他用户不受影响,仍然可以拉取这些漫游消息和会话。
API使用示例:
EMService service;
try {
service.message().oneWayClearGroupOrRoomRoamingMessagesWithinPeriod("username", "227918582185992", 1659014868000).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 调用该接口的用户的用户 IDid
- 要清空哪个群组或聊天室的漫游消息。你可以传入群组 ID 或聊天室 ID。time
- 要清空哪个时间点及之前的群组或聊天室的漫游消息。该时间为 Unix 时间戳,单位为毫秒。public reactor.core.publisher.Mono<Void> modifyTextOrCustomMessage(String messageId, String username, NewMessage newMessage, Map<String,Object> newExt, Boolean isCombineExt)
API使用示例:
EMService service;
try {
NewMessage newMessage = NewMessage.builder()
.type("txt")
.msg("hello world")
.build();
Map<String, Object> newExt = new HashMap<>();
newExt.put("key", "value");
service.message().modifyTextOrCustomizeMessage("messageId", "username", newMessage, newExt, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
messageId
- 要修改的消息的 ID。username
- 修改消息的用户 ID。newMessage
- 修改后的消息。newExt
- 修改后的消息扩展信息。isCombineExt
- 修改后的消息扩展信息与原有扩展信息是合并还是替换。- (默认)true:合并;- false:替换。Copyright © 2024. All rights reserved.