logo
On this page

Insert local messages


Overview

The ZIM SDK supports inserting local messages into one-on-one and group conversations, and starting from version 2.13, it also supports inserting local messages into room conversations. The inserted messages will only exist locally on the device and will not be sent to other users or synchronized to other devices. Additionally, these messages will not be retained after uninstalling the client application.

You can use this feature to insert a message into the local database for displaying system notifications. For example, it can be used for local notifications such as joining or leaving a group, which do not need to be sent to other users across devices.

Warning
  • The ZIM SDK currently supports inserting local messages for "peer/group" conversations but does not support inserting local messages for "room" conversations.
  • The ZIM SDK does not support inserting signaling messages.

Implementation process

To insert a message into the local database, you need to call the insertMessageToLocalDB API and introduce the created ZIMMessage message, conversationID, conversationType, senderUserID, and other parameters.

Sample code
// 1. Create a ZIM object and pass in the appID and appSign
ZIMAppConfig appConfig = new ZIMAppConfig();
appConfig.appID = 12345;  // Replace with your assigned AppID
appConfig.appSign = "appSign";   // Replace with your assigned AppSign
ZIM.Create(appConfig);

// 2. Log in
ZIMUserInfo zimUserInfo = new ZIMUserInfo();
zimUserInfo.userID = "xxxx";
zimUserInfo.userName = "xxxx";
ZIM.GetInstance().Login(zimUserInfo, (ZIMError errorInfo) =>
{
    // Developers can use ZIMError to determine if the login is successful.
}
);

// 3. Insert a message into the local database
// Here is an example of inserting a custom message, you can modify it to insert other types of messages (signaling messages are not supported).
int subType = 0; // Custom message type defined by the business, with a value between 0 and 200
ZIMCustomMessage customMessage = new ZIMCustomMessage("message", subType);
string conversationID = "conversationID";
string senderUserID = "senderUserID";
ZIMConversationType type = ZIMConversationType.Peer;
ZIM.GetInstance().InsertMessageToLocalDB(customMessage, conversationID, type, senderUserID, (ZIMMessage message, ZIMError errorInfo) => 
{
    // You can listen to this callback to check if the message is inserted successfully
});
1
Copied!

Previous

Delete messages

Next

Recall messages