Extension features
Replies
A message without a reply is called a threaded message; a message with a reply is called a message reply.
A threaded message can be replied by multiple reply messages. The target of a reply message can be either a threaded message or a reply message. If the target of a reply message is a threaded message, the threaded message corresponding to the reply message is its reply object; otherwise, the thread message corresponding to the reply message is the same as the threaded message corresponding to the reply message.
All replies in the same thread consist of a thread session.
Reply
dart
Future<NIMResult<void>> replyMessage(
{required NIMMessage msg,
required NIMMessage replyMsg,
required bool resend});
Parameter |
Type |
Description |
msg |
NIMMessage |
Message body created by { MessageBuilder}. |
replyMsg |
NIMMessage |
Replied message |
resend |
bool |
True: resend a message for failure. Otherwise, false. |
dartNIMResult<NIMMessage> retCreateMsg =
await MessageBuilder.createTextMessage(
sessionId: inputParams['toAccount'] as String,
sessionType: NIMSessionType.p2p,
text: inputParams['text'] as String);
var message = retCreateMsg.data;
await NimCore.instance.messageService.replyMessage(
{msg: message,
message:message,
resend:true});
Note: In a superteam, uses SuperTeamService
to reply a message..
Query chat threads in the cloud
dart
Future<NIMResult<NIMThreadTalkHistory>> queryThreadTalkHistory(
{required NIMMessage anchor,
required int fromTime,
required int toTime,
required int limit,
required QueryDirection direction,
required bool persist});
Parameter |
Type |
Description |
anchor |
NIMMessage |
The search anchor. The search target is the messages in a thread. |
fromTime |
int |
The start time |
toTime |
int |
The end time |
limit |
int |
The limit of messages returned from a query. |
direction |
QueryDirection |
Query direction |
persist |
bool |
Whether the result is persisted. |
dart NIMResult<NIMMessage> retCreateMsg =
await MessageBuilder.createTextMessage(
sessionId: inputParams['toAccount'] as String,
sessionType: NIMSessionType.p2p,
text: inputParams['text'] as String);
var message = retCreateMsg.data;
await NimCore.instance.messageService.queryThreadTalkHistory(
{anchor:message,
fromTime:fromTime,
toTime:toTime,
limit:limit,
directio:direction,
persist:persist})
Get the number of replies in a thread
Get the number of replies in a thread in the local database.
dart
Future<NIMResult<int>> queryReplyCountInThreadTalkBlock(NIMMessage msg);
Parameter |
Type |
Description |
msg |
NIMMessage |
A message in a thread. |
dartint count = await NimCore.instance.messageService.queryReplyCountInThreadTalkBlock(msg:message);
Add a quick comment to a message. The comment content is not a message, but data of long type. and the upper layer specifies the association between the comment content and the interface.
dart
Future<NIMResult<int>> addQuickComment(NIMMessage msg, int replyType, String ext, bool needPush, bool needBadge, String pushTitle, String pushContent, Map<String, Object> pushPayload);
Parameter |
Type |
Description |
msg |
NIMMessage |
Message to be replied |
replyType |
int |
Type of a reply message |
ext |
String |
Extension field that can hold up to 8 characters |
needPush |
bool |
Whether the push service is required. |
needBadge |
bool |
Whether the badge is required. |
pushTitle |
String |
Title of a push notification notification |
pushContent |
String |
The body of a push notification |
pushPayload |
Map<String, Object> |
Custom push payload in JSON format |
dartawait NimCore.instance.messageService.addQuickComment(message, replytype, msgExt, needpush, needbadge,pushTitle, pushContent, pushPayload);
dart
Future<NIMResult<int>> removeQuickComment(NIMMessage msg, int replyType, String ext, bool needPush, bool needBadge, String pushTitle, String pushContent, Map<String, Object> pushPayload);
Parameter |
Type |
Description |
msg |
NIMMessage |
Message to be replied |
replyType |
int |
Type of a reply message |
ext |
String |
Extension field that can hold up to 8 characters |
needPush |
bool |
Whether the push service is required. |
needBadge |
bool |
Whether the badge is required. |
pushTitle |
String |
Title of a push notification notification |
pushContent |
String |
The body of a push notification |
pushPayload |
Map<String, Object> |
Custom push payload in JSON format |
dartawait NimCore.instance.messageService.removeQuickComment(message, replytype, msgExt, needpush, needbadge,pushTitle, pushContent, pushPayload);
dart
Future<NIMResult<List<NIMQuickCommentOptionWrapper>>> queryQuickComment(List<NIMMessage> msgList)
Parameter |
Type |
Description |
msgList |
List |
A list of messages for quick comments. Up to 20 messages are allowed. |
dartawait NimCore.instance.messageService.queryQuickComment(msglist)
dart
final StreamController<NIMHandleQuickCommentOption> onQuickCommentAdd =
StreamController<NIMHandleQuickCommentOption>.broadcast();
NIMHandleQuickCommentOption representation:
Parameter |
Type |
Description |
key |
NIMMessageKey |
The key of a message. The key can be used to fetch the full message on the server. |
commentOption |
NIMQuickCommentOption |
The data of a quick comment. |
dart NimCore.instance.messageService.onQuickCommentAdd.listen(( NIMHandleQuickCommentOption event) {
});
dart
final StreamController<NIMHandleQuickCommentOption> onQuickCommentRemove =
StreamController<NIMHandleQuickCommentOption>.broadcast();
NIMHandleQuickCommentOption representation:
Parameter |
Type |
Description |
key |
NIMMessageKey |
The key of a message. The key can be used to fetch the full message on the server. |
commentOption |
NIMQuickCommentOption |
The data of a quick comment. |
dart NimCore.instance.messageService.onQuickCommentRemove.listen(( NIMHandleQuickCommentOption event) {
});
Bookmarks
You can add a string within 20,000 characters long as a bookmark
Add a bookmark
dart
Future<NIMResult<NIMCollectInfo>> addCollect({
required int type,
required String data,
String? ext,
String? uniqueId,
}) ;
Parameter |
Type |
Description |
type |
int |
Bookmark type |
data |
String |
Data of a bookmark message. Up to 20KB is allowed. |
ext |
String |
Extension field that contains up to 1KB data |
uniqueId |
String |
Unique message ID |
javaawait NimCore.instance.messageService.addCollect(type, data, ext, uniqueId);
Remove multiple bookmark messages at a time
dart
Future<NIMResult<int>> removeCollect(List<NIMCollectInfo> collects);
Parameter |
Type |
Description |
collects |
List |
List of information about bookmarks to be removed. Each pair consists of a bookmark ID and the creation time |
dartawait NimCore.instance.messageService.removeCollect(collects);
Update the extension field of the bookmark
dart
Future<NIMResult<NIMCollectInfo>> updateCollect(NIMCollectInfo info);
Parameter |
Type |
Description |
info |
NIMCollectInfo |
a bookmark to be updated |
dartNIMCollectInfo info = ...;
collectInfo.ext = 'update collect ext';
await NimCore.instance.messageService.updateCollect(collectInfo);
Query paginated bookmarks
dart
Future<NIMResult<List<NIMCollectInfo>>> queryCollect({
NIMCollectInfo? anchor,
int toTime = 0,
int? type,
int limit = 100,
QueryDirection direction = QueryDirection.QUERY_OLD,
});
Parameter |
Type |
Description |
anchor |
NIMCollectInfo |
The last bookmark message in the query excluded in the query result. |
toTime |
int |
The end time of a time range in milliseconds |
limit |
int |
limit of messages returned from a query. A maximum of 100 messages are allowed. |
direction |
QueryDirection |
Query direction |
dartawait NimCore.instance.messageService.queryCollect(anchor,toTime,limit,direction);
PIN tag
All users in the session can add a PIN tag to a message, remove the PIN tag from a message, query PIN messages, and update the extension field. A message can only have one PIN tag. When multiple users add a PIN tag to the same message, the later PIN tag will overwrite the earlier PIN tag.
Add a PIN tag to a message
dart
Future<NIMResult<void>> addMessagePin(NIMMessage message, String? ext) ;
Parameter |
Type |
Description |
message |
NIMMessage |
The message with a PIN tag |
ext |
String |
Extension field |
dartawait NimCore.instance.messageService.addMessagePin(message, ext);
Update a PIN message
dart
Future<NIMResult<void>> updateMessagePin(NIMMessage message, String? ext);
Parameter |
Type |
Description |
message |
NIMMessage |
The message with a PIN tag |
ext |
String |
Extension field |
dartawait NimCore.instance.messageService.updateMessagePin(message, ext);
Remove the PIN tag of a message
dart
Future<NIMResult<void>> removeMessagePin(NIMMessage message, String? ext);
Parameter |
Type |
Description |
message |
NIMMessage |
The message with a PIN tag |
ext |
String |
Extension field |
dartawait NimCore.instance.messageService.removeMessagePin(message, ext);
Get a list of PIN messages
dart
Future<NIMResult<List<NIMMessagePin>>> queryMessagePinForSession( String sessionId, NIMSessionType sessionType);
Parameter |
Type |
Description |
sessionId |
String |
The ID of a session. |
sessionType |
NIMSessionType |
The type of a session. |
dartawait NimCore.instance.messageService.queryMessagePinForSession(sessionId, sessionType);
1caa590e5-28e2-4b79-b6fd-a64ff09c5bec
1caa590e5-28e2-4b79-b6fd-a64ff09c5bec
Listen for events of PIN messages
Events of PIN messages include adding a PIN tag, updating a PIN tag, and deleting the PIN tag. The base class of events is NIMMessagePinEvent
, and the derived classes include adding a PIN tag NIMMessagePinAddedEvent
, updating a PIN tag NIMMessagePinUpdatedEvent
, and deleting a PIN tag NIMMessagePinRemovedEvent
.
dartclass MessageService {
Stream<NIMMessagePinEvent> get onMessagePinNotify;
}
NIMMessagePinEvent
representation
Parameter |
Type |
Description |
pin |
NIMMessagePin |
PIN message |
dartawait NimCore.instance.messageService.onMessagePinNotify.listen(
(messagePinEvent) {
if (messagePinEvent is NIMMessagePinAddedEvent) {
} else if (messagePinEvent is NIMMessagePinUpdatedEvent) {
} else if (messagePinEvent is NIMMessagePinRemovedEvent) {
}
}
);
Pinned sessions
Add a pinned session
dart
Future<NIMResult<NIMStickTopSessionInfo>> addStickTopSession(String sessionId, NIMSessionType sessionType, String ext);
Parameter |
Type |
Description |
sessionId |
String |
The ID of a session. |
sessionType |
NIMSessionType |
The type of a session. |
ext |
String |
Extension field that can hold up to 512 characters |
dartNimCore.instance.messageService.addStickTopSession(sessionId, sessionType, ext);
Delete a pinned session
dart
Future<NIMResult<void>> removeStickTopSession(String sessionId, NIMSessionType sessionType, String ext);
Parameter |
Type |
Description |
sessionId |
String |
The ID of a session. |
sessionType |
NIMSessionType |
The type of a session. |
ext |
String |
Extension field that can contain up to 512 characters. The parameter is not supported for Windows and macOS. |
dartNimCore.instance.messageService.removeStickTopSession(sessionId, sessionType, ext);
Update the extension field of a pinned session
dart
Future<NIMResult<void>> updateStickTopSession(String sessionId, NIMSessionType sessionType, String ext);
Parameter |
Type |
Description |
sessionId |
String |
The ID of a session. |
sessionType |
NIMSessionType |
The type of a session. |
ext |
String |
Extension field that can hold up to 512 characters |
dartNimCore.instance.messageService.updateStickTopSession(sessionId, sessionType, ext);
Get the pinned sessions
Note: You need to set the notificationStickTopSession of the initialization parameter SDKOptions to true, and enable the synchronization of the pinned session list before you can query the accurate pinned session list using the following interface. Otherwise, the queried list does not include changes during the offline period.
dart
Future<NIMResult<List<NIMStickTopSessionInfo>>> queryStickTopSession()
dart NimCore.instance.messageService.queryStickTopSession();
Listen to the synchronization of pinned sessions
dart
final StreamController<List<NIMStickTopSessionInfo>> onSyncStickTopSession =
StreamController<List<NIMStickTopSessionInfo>>.broadcast();
dart NimCore.instance.messageService.onSyncStickTopSession.listen((List<NIMStickTopSessionInfo> event) {
});
Listen to new pinned sessions
dart
final StreamController<NIMStickTopSessionInfo> onStickTopSessionAdd =
StreamController<NIMStickTopSessionInfo>.broadcast();
dart NimCore.instance.messageService.onStickTopSessionAdd.listen((NIMStickTopSessionInfo event) {
});
Listen to removing pinned sessions
dart
final StreamController<NIMStickTopSessionInfo> onStickTopSessionRemove =
StreamController<NIMStickTopSessionInfo>.broadcast();
dart NimCore.instance.messageService.onStickTopSessionRemove.listen((NIMStickTopSessionInfo event) {
});
Listen to updating pinned sessions
dart
final StreamController<NIMStickTopSessionInfo> onStickTopSessionUpdate =
StreamController<NIMStickTopSessionInfo>.broadcast();
dart NimCore.instance.messageService.onStickTopSessionUpdate.listen((NIMStickTopSessionInfo event) {
});