Skip to main content

Insert messages

The Nexconn SDK supports inserting messages into the local database. Inserted messages are not sent to the server or to other users.

tip
  • Inserted messages exist only in the local database.
  • They are not synced when the user reinstalls the app or logs in on another device.

Insert messages

The SDK provides a batch insert method that supports both sent and received messages.

kotlin
// Get the target channel instance first
val directChannel = DirectChannel("userId")
val groupChannel = GroupChannel("groupId")

// Insert a sent message into a direct channel
directChannel.insertMessages(
listOf(
InsertMessageItem(
content = TextMessage("Message content 1"),
direction = MessageDirection.SEND,
sentTime = System.currentTimeMillis(),
)
)
) { success, error ->
if (error == null && success == true) {
Log.d("Insert", "Messages inserted")
}
}

// Insert a received message into a group channel
groupChannel.insertMessages(
listOf(
InsertMessageItem(
content = TextMessage("Message content 2"),
direction = MessageDirection.RECEIVE,
senderUserId = "senderUserId",
sentTime = System.currentTimeMillis(),
)
)
) { success, error ->
if (error == null && success == true) {
Log.d("Insert", "Message inserted")
}
}

Parameters

channel.insertMessages(items, handler)

ParameterTypeDescription
itemsList<InsertMessageItem>The message items to insert.
handlerOperationHandler<Boolean>?The completion callback. result is true on success.

InsertMessageItem properties

PropertyTypeDescription
contentMessageContentThe message content.
directionMessageDirectionThe message direction (SEND or RECEIVE). Default: SEND.
senderUserIdStringThe sender user ID. Default: "". Required for received messages.
sentTimeLongThe sent timestamp in milliseconds. Default: current time.
sentStatusSentStatusSending status. Default: SentStatus.SENT.

Important notes

  • Insert no more than 500 messages per call. 10 or fewer is recommended.
  • sentTime affects message ordering. Ensure timestamps are correct.