Message options

Update time: 2024/03/07 11:13:59

You can set the options in NIMCustomMessageConfig used to specify whether the message history is stored on the servert and whether messages are roaming.

For more information, see NIMCustomMessageConfig.

Parameter
Type
Description
enableHistory bool Whether the message history is stored on the server.
enablePersist bool Whether the message is stored as offline message.
enablePush bool whether message alerts are enabled. If the value is set to true, alerts will show on the system notification bar when the message is received.
enablePushNick bool Whether a notification requires the nickname in the push notification (for iOS apps only).
If the value is set to true, the nickname will be displayed on iOS devices when the notification is received.
enableRoaming bool Whether the message is stored as roaming message.
enableRoute bool whether message routing is enabled. If the value is set to true, the message is sent following the default message route. If a endpoint URL is configured for data sync, the message will be synced.
enableSelfSync bool whether a message is synced with other devices. If multi-device login is enabled, a message sent on one device will be synced with other devices.
enableUnreadCount bool Whether a message is counted as unread. If the value is set to true, the unread count increments by 1 in the recent contacts list when the message is received.

The following is an example where messages are not stored on the server and are not delivered as roaming messages, and multi-device synchronization is not required:

dart// Test account
String account = 'testAccount';
// P2P chat
NIMSessionType sessionType = NIMSessionType.p2p;
String text = 'this is an example';
// Custom message configuration
NIMCustomMessageConfig config =
    NIMCustomMessageConfig(enableHistory: false,
    enableRoaming:false,
    enableSelfSync:false);
// Send the message
Future<NIMResult<NIMMessage>> result = MessageBuilder.createTextMessage(
    sessionId: account, sessionType: sessionType, text: text)
    .then((value) {
    if (value.isSuccess) {
    value.data!.config = config;
    return NimCore.instance.messageService
        .sendMessage(message: value.data!, resend: false);
    } else {
    return Future.value(value);
    }
});
Was this page helpful?
Yes
No