InboxMessageManager

Reads and manages Inbox messages, from both Marketing Cloud servers (MCE and MAM). Get the instance from InboxFeature.getInboxMessageManager; configure the feature with com.salesforce.marketingcloud.inboxfeature.config.InboxFeatureConfig.

A message is active from its start date until its end date, if it has one. The query and count methods only see active messages. MAM messages are scoped to the currently identified user (or to the anonymous user when none is set); MCE messages are shared by all users of the device.

Threading: the query and count methods (getMessages, getUnreadMessages, getReadMessages, getDeletedMessages and the get*Count methods) read and decrypt the local database synchronously on the calling thread, so they are annotated WorkerThread: call them off the main thread, e.g. withContext(Dispatchers.IO) { manager.getMessages() }, and post the result to the UI. The mutations and track methods only queue their work on an SDK background thread, and every listener is called on the main thread.

While Inbox is disabled (isInboxEnabled is false: blocked by privacy mode, disableInbox, or disabled in the config) the query methods return an empty list, the count methods return 0, the mutations and track methods are ignored (logged), and refreshInbox is refused. Registered listeners are kept but not called; the first fetch after Inbox is enabled again notifies them.

Types

Link copied to clipboard
fun interface InboxRefreshListener

Notified upon completion of a refreshInbox attempt, at most once per source.

Link copied to clipboard
fun interface InboxResponseListener

Notified when a fetch delivers a fresh set of Inbox messages.

Functions

Link copied to clipboard
abstract fun deleteMessage(message: InboxMessage)

Marks message deleted in local storage. It is returned by getDeletedMessages instead of getMessages. The status persists until the message changes on the server or local storage is cleared.

abstract fun deleteMessage(messageId: String)

Marks the message with messageId deleted in local storage. It is returned by getDeletedMessages instead of getMessages. The status persists until the message changes on the server or local storage is cleared.

Link copied to clipboard
abstract fun disableInbox()

Disables the Inbox feature at runtime. Stored messages are kept but hidden until enabled. The choice is persisted across restarts and takes precedence over com.salesforce.marketingcloud.inboxfeature.config.InboxFeatureConfig.inboxEnabled.

Link copied to clipboard
abstract fun enableInbox()

Enables the Inbox feature at runtime. The choice is persisted across restarts and takes precedence over com.salesforce.marketingcloud.inboxfeature.config.InboxFeatureConfig.inboxEnabled. Refused while GDPR-blocked.

Link copied to clipboard
@WorkerThread
abstract fun getDeletedMessageCount(): Int

Returns the number of active, deleted Inbox messages regardless of read status. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
@WorkerThread
abstract fun getDeletedMessages(): List<InboxMessage>

Returns the active, deleted Inbox messages ordered by start date descending. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
@WorkerThread
abstract fun getMessageCount(): Int

Returns the total number of active, not-deleted Inbox messages regardless of read status. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
@WorkerThread
abstract fun getMessages(): List<InboxMessage>

Returns the active, not-deleted Inbox messages ordered by start date descending. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
@WorkerThread
abstract fun getReadMessageCount(): Int

Returns the number of active, read, not-deleted Inbox messages. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
@WorkerThread
abstract fun getReadMessages(): List<InboxMessage>

Returns the active, read, not-deleted Inbox messages ordered by start date descending. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
@WorkerThread
abstract fun getUnreadMessageCount(): Int

Returns the number of active, unread, not-deleted Inbox messages. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
@WorkerThread
abstract fun getUnreadMessages(): List<InboxMessage>

Returns the active, unread, not-deleted Inbox messages ordered by start date descending. Reads the local database on the calling thread; call it off the main thread.

Link copied to clipboard
abstract fun isInboxEnabled(): Boolean

Returns true if the Inbox feature is currently enabled for this device. A GDPR block takes precedence over the runtime choice (enableInbox / disableInbox), which takes precedence over com.salesforce.marketingcloud.inboxfeature.config.InboxFeatureConfig.inboxEnabled.

Link copied to clipboard
abstract fun markAllMessagesDeleted()

Marks all active Inbox messages deleted.

Link copied to clipboard
abstract fun markAllMessagesRead()

Marks all active, unread, not-deleted Inbox messages read.

Link copied to clipboard

Requests an updated list of Inbox messages from Marketing Cloud. listener, if provided, is notified at most once per source for this call: once for each configured server (MCE, MAM) whose fetch completes, tagged with that server. Once the first server answers, a new refresh may be started; doing so stops this listener from receiving the remaining server's outcome. Outcomes are not matched to a specific call: a server's next outcome goes to the latest refresh's listener, even if it comes from a fetch started earlier. If the module itself refuses or cancels the request (a refresh is already in progress, Inbox is disabled or GDPR-blocked, or Inbox is disabled/torn down before any server has answered), listener is notified once with (false, Event.Producer.INBOX_FEATURE_MODULE). If Inbox is disabled/torn down after one server has answered, listener is released without a callback for the other server. Every listener callback, including a refusal, is made on the main thread after this call returns.

Link copied to clipboard

Registers a InboxResponseListener to be notified when a fetch delivers a fresh set of Inbox messages. The SDK holds listener until it is unregistered, so call unregisterInboxResponseListener when its owner is destroyed. Registering the same instance again has no effect.

Link copied to clipboard
abstract fun setMessageRead(message: InboxMessage)

Marks message read in local storage. The status persists until the message changes on the server or local storage is cleared. A deleted message is left unchanged.

abstract fun setMessageRead(messageId: String)

Marks the message with messageId read in local storage. The status persists until the message changes on the server or local storage is cleared. A deleted message is left unchanged.

Link copied to clipboard

Records that message was interacted with (a button/CTA click) via interaction. The message is validated against the module store before an interaction is recorded; interacting with an unknown message is a no-op.

Link copied to clipboard
abstract fun trackMessageOpenEvent(message: InboxMessage)

Records that message was opened by the app. The message is validated against the module store before an open is recorded; opening an unknown message is a no-op. This records the open analytic only — it does not mark the message read (that is the caller's responsibility).

Link copied to clipboard

Stops listener from receiving any further refreshInbox callbacks and releases the SDK's reference to it. Call this when the owner of listener is destroyed, so the SDK does not keep it (and anything it captures) alive while waiting for a server that may answer late or never.

Link copied to clipboard

Unregisters a previously registered InboxResponseListener.