Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / rcs / e2e / RcsE2EGroups.kt
RcsE2EGroups.kt27 lines · 1.1 KiBRaw
| 1 | package com.vayunmathur.communicate.data.rcs.e2e |
| 2 | |
| 3 | /** |
| 4 | * Group-query helpers for [RcsE2E] (split for file length). |
| 5 | * Extension functions on [RcsE2E]; behavior identical, call sites unchanged. |
| 6 | */ |
| 7 | |
| 8 | fun RcsE2E.parseMembers(csv: String): Map<String, Int> { |
| 9 | if (csv.isBlank()) return emptyMap() |
| 10 | return csv.split(",").mapNotNull { entry -> |
| 11 | val (member, idx) = entry.split("=", limit = 2).takeIf { it.size == 2 } ?: return@mapNotNull null |
| 12 | val index = idx.trim().toIntOrNull() ?: return@mapNotNull null |
| 13 | member.trim().takeIf { it.isNotEmpty() }?.to(index) |
| 14 | }.toMap() |
| 15 | } |
| 16 | |
| 17 | /** Drop [droppedIdx] leaves from a member map, re-encoding the CSV. */ |
| 18 | fun RcsE2E.pruneMembers(csv: String, droppedIdx: Set<Int>): String = |
| 19 | parseMembers(csv).filterValues { it !in droppedIdx } |
| 20 | .entries.joinToString(",") { "${it.key}=${it.value}" } |
| 21 | |
| 22 | internal fun ByteArray.hex(): String = joinToString("") { "%02x".format(it) } |
| 23 | |
| 24 | fun RcsE2E.commitLockFor(conversationId: String): kotlinx.coroutines.sync.Mutex = |
| 25 | commitLocks.getOrPut(conversationId) { kotlinx.coroutines.sync.Mutex() } |
| 26 | |
| 27 | internal fun e2eThreadFor(e164: String): String = "e2e:$e164" |