MessagingInboxProvider

Messaging extension implementation of AepInboxContentProvider. MessagingInboxProvider is responsible for fetching the Inbox content for a given surface and managing the Inbox state through reactive updates when the content needs to be refreshed.

Constructor

data-slots=heading, code
data-repeat=1
data-languages=Kotlin

Kotlin

MessagingInboxProvider(surface: Surface)

Parameters

Parameter
Type
Description
surface
Surface
The surface to fetch inbox content for.

Methods

getInboxUI

Retrieves the Inbox content and updates the state as a flow. This method automatically loads initial content when first collected.

Returns

A Flow of InboxUIState representing the current state of the inbox.

Syntax

data-slots=heading, code
data-repeat=1
data-languages=Kotlin

Kotlin

override fun getInboxUI(): Flow<InboxUIState>

refresh

Refreshes the Inbox content by fetching new inbox and content cards propositions from the device cache and updating the flow returned by getInboxUI. This will cause all collectors of the flow to receive the updated inbox.

Emits InboxUIState.Loading before fetching, then emits InboxUIState.Success or InboxUIState.Error.

data-variant=info
data-slots=text
getInboxUI automatically loads initial content when first collected, so you only need refresh for manual refresh (for example after updatePropositionsForSurfaces).

Syntax

data-slots=heading, code
data-repeat=1
data-languages=Kotlin

Kotlin

override suspend fun refresh()

Usage Example

data-slots=heading, code
data-repeat=1
data-languages=Kotlin

Kotlin

class InboxViewModel : ViewModel() {
    private val inboxProvider = MessagingInboxProvider(Surface("inbox"))

    val inboxUIState: StateFlow<InboxUIState> = inboxProvider.getInboxUI()
        .stateIn(
            scope = viewModelScope,
            started = SharingStarted.WhileSubscribed(5000),
            initialValue = InboxUIState.Loading
        )

    fun refresh() {
        viewModelScope.launch {
            inboxProvider.refresh()
        }
    }
}