mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-26 00:05:22 +00:00
Fix request sync duplicate public messages (#707)
Co-authored-by: CC <cc@ggg.local>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.bitchat.android.services
|
||||
|
||||
import com.bitchat.android.model.BitchatMessage
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.util.Date
|
||||
|
||||
class AppStateStoreTest {
|
||||
@Before
|
||||
fun setUp() {
|
||||
AppStateStore.clear()
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
AppStateStore.clear()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `public timeline collapses request sync replay even when android message ids differ`() {
|
||||
val timestamp = Date(1_700_000_000_000L)
|
||||
val originalDelivery = BitchatMessage(
|
||||
id = "random-id-from-first-delivery",
|
||||
sender = "alice",
|
||||
content = "hello from sync",
|
||||
timestamp = timestamp,
|
||||
senderPeerID = "1122334455667788"
|
||||
)
|
||||
val requestSyncReplay = originalDelivery.copy(id = "different-random-id-from-replay")
|
||||
|
||||
AppStateStore.addPublicMessage(originalDelivery)
|
||||
AppStateStore.addPublicMessage(requestSyncReplay)
|
||||
|
||||
assertEquals(listOf(originalDelivery), AppStateStore.publicMessages.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `public timeline still keeps same content sent at different packet timestamps`() {
|
||||
val first = BitchatMessage(
|
||||
id = "first-packet-id",
|
||||
sender = "alice",
|
||||
content = "same text",
|
||||
timestamp = Date(1_700_000_000_000L),
|
||||
senderPeerID = "1122334455667788"
|
||||
)
|
||||
val second = first.copy(
|
||||
id = "second-packet-id",
|
||||
timestamp = Date(first.timestamp.time + 1_000L)
|
||||
)
|
||||
|
||||
AppStateStore.addPublicMessage(first)
|
||||
AppStateStore.addPublicMessage(second)
|
||||
|
||||
assertEquals(listOf(first, second), AppStateStore.publicMessages.value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user