Fix request sync duplicate public messages (#707)

Co-authored-by: CC <cc@ggg.local>
This commit is contained in:
callebtc
2026-06-08 15:41:11 -05:00
committed by GitHub
co-authored by CC
parent f7ce1f4be6
commit 054887bad8
4 changed files with 80 additions and 5 deletions
@@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.asStateFlow
object AppStateStore {
// Global de-dup set by message id to avoid duplicate keys in Compose lists
private val seenMessageIds = mutableSetOf<String>()
private val seenPublicMessageKeys = mutableSetOf<String>()
// Connected peer IDs (mesh ephemeral IDs)
private val _peers = MutableStateFlow<List<String>>(emptyList())
val peers: StateFlow<List<String>> = _peers.asStateFlow()
@@ -35,8 +36,10 @@ object AppStateStore {
fun addPublicMessage(msg: BitchatMessage) {
synchronized(this) {
if (seenMessageIds.contains(msg.id)) return
val publicKey = publicMessageKey(msg)
if (seenMessageIds.contains(msg.id) || seenPublicMessageKeys.contains(publicKey)) return
seenMessageIds.add(msg.id)
seenPublicMessageKeys.add(publicKey)
_publicMessages.value = _publicMessages.value + msg
}
}
@@ -100,10 +103,22 @@ object AppStateStore {
fun clear() {
synchronized(this) {
seenMessageIds.clear()
seenPublicMessageKeys.clear()
_peers.value = emptyList()
_publicMessages.value = emptyList()
_privateMessages.value = emptyMap()
_channelMessages.value = emptyMap()
}
}
private fun publicMessageKey(msg: BitchatMessage): String {
val sender = msg.senderPeerID ?: msg.sender
return listOf(
sender,
msg.timestamp.time.toString(),
msg.type.name,
msg.channel ?: "",
msg.content
).joinToString("\u001F")
}
}