Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / rcs / RcsImdn.kt
RcsImdn.kt27 lines · 1.0 KiBRaw
| 1 | package com.vayunmathur.communicate.data.rcs |
| 2 | |
| 3 | import kotlinx.coroutines.flow.MutableStateFlow |
| 4 | import kotlinx.coroutines.flow.StateFlow |
| 5 | import 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 | */ |
| 15 | object 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 | } |