Skip to content

Commit

Permalink
fix: update group state when fetching conversation during slow sync W…
Browse files Browse the repository at this point in the history
…PB-11247 (#3029)

* fix: update  group state when fetching conversation during slow sync

* test: verify that group state is updated on re-insertion
  • Loading branch information
typfel committed Sep 25, 2024
1 parent 112b901 commit 2083360
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type = excluded.type,
team_id = excluded.team_id,
mls_group_id = excluded.mls_group_id,
mls_epoch = excluded.mls_epoch,
mls_group_state = excluded.mls_group_state,
protocol = excluded.protocol,
muted_status = excluded.muted_status,
muted_time = excluded.muted_time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ class ConversationDAOTest : BaseDatabaseTest() {
assertNull(result)
}

@Test
fun givenExistingConversation_WhenReinserting_ThenGroupStateIsUpdated() = runTest {
conversationDAO.insertConversation(conversationEntity2)
conversationDAO.insertConversation(conversationEntity2.copy(
protocolInfo = mlsProtocolInfo1.copy(
groupState = ConversationEntity.GroupState.PENDING_JOIN
)
))
val result = conversationDAO.getConversationByQualifiedID(conversationEntity2.id)
assertEquals(ConversationEntity.GroupState.PENDING_JOIN, (result?.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupState)
}

@Test
fun givenExistingConversation_ThenConversationCanBeUpdated() = runTest {
conversationDAO.insertConversation(conversationEntity1)
Expand Down Expand Up @@ -2043,6 +2055,21 @@ class ConversationDAOTest : BaseDatabaseTest() {
isMLSCapable = false
)

val mlsProtocolInfo1 = ConversationEntity.ProtocolInfo.MLS(
"group2",
ConversationEntity.GroupState.ESTABLISHED,
0UL,
Instant.parse("2021-03-30T15:36:00.000Z"),
cipherSuite = ConversationEntity.CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
)
val mlsProtocolInfo2 = ConversationEntity.ProtocolInfo.MLS(
"group3",
ConversationEntity.GroupState.PENDING_JOIN,
0UL,
Instant.parse("2021-03-30T15:36:00.000Z"),
cipherSuite = ConversationEntity.CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
)

val team = TeamEntity(teamId, "teamName", "")

val conversationEntity1 = ConversationEntity(
Expand Down Expand Up @@ -2072,13 +2099,7 @@ class ConversationDAOTest : BaseDatabaseTest() {
"conversation2",
ConversationEntity.Type.ONE_ON_ONE,
null,
ConversationEntity.ProtocolInfo.MLS(
"group2",
ConversationEntity.GroupState.ESTABLISHED,
0UL,
Instant.parse("2021-03-30T15:36:00.000Z"),
cipherSuite = ConversationEntity.CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
),
protocolInfo = mlsProtocolInfo1,
creatorId = "someValue",
lastNotificationDate = null,
lastModifiedDate = "2021-03-30T15:36:00.000Z".toInstant(),
Expand All @@ -2101,13 +2122,7 @@ class ConversationDAOTest : BaseDatabaseTest() {
"conversation3",
ConversationEntity.Type.GROUP,
null,
ConversationEntity.ProtocolInfo.MLS(
"group3",
ConversationEntity.GroupState.PENDING_JOIN,
0UL,
Instant.parse("2021-03-30T15:36:00.000Z"),
cipherSuite = ConversationEntity.CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
),
protocolInfo = mlsProtocolInfo2,
creatorId = "someValue",
// This conversation was modified after the last time the user was notified about it
lastNotificationDate = "2021-03-30T15:30:00.000Z".toInstant(),
Expand Down

0 comments on commit 2083360

Please sign in to comment.