Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / rcs / RcsImdn.kt

RcsImdn.kt27 lines · 1.0 KiBRaw
1package com.vayunmathur.communicate.data.rcs
2
3import kotlinx.coroutines.flow.MutableStateFlow
4import kotlinx.coroutines.flow.StateFlow
5import kotlinx.coroutines.flow.asStateFlow
6
7/**
8 * IMDN delivery/display receipt tracker (RFC 5438).
9 *
10 * Outgoing CPIM carries `imdn.Message-ID`; the far end answers with
11 * `message/imdn+xml` reporting `positive-delivery` / `display` / `failed`.
12 * Reports arrive via [RcsSessionManager.onSipRequest] → [onReportReceived].
13 * Statuses feed the `SmsMessage.status` ticks through the repository layer.
14 */
15object RcsImdn {
16 /** message-id → latest disposition. */
17 private val _reports = MutableStateFlow<Map<String, ImdnDisposition>>(emptyMap())
18 val reports: StateFlow<Map<String, ImdnDisposition>> = _reports.asStateFlow()
19
20 fun onReportReceived(body: String) {
21 if (!RcsFeature.enabled) return
22 val (id, disposition) = parseImdnBody(body) ?: return
23 _reports.value = _reports.value + (id to disposition)
24 }
25
26 fun statusFor(messageId: String): ImdnDisposition? = _reports.value[messageId]
27}