Skip to content

Commit

Permalink
Merge branch 'release/candidate' into fix/allow-skip-users-without-ke…
Browse files Browse the repository at this point in the history
…ypackages-during-mls-migration-cherry-pick
  • Loading branch information
mchenani authored Jul 2, 2024
2 parents 34549cb + e176d92 commit 1dd0bdd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,15 @@ AND Conversation.mls_group_state IS 'ESTABLISHED'
ORDER BY Conversation.type DESC LIMIT 1;

getMLSGroupIdByUserId:
SELECT Conversation.mls_group_id FROM Member
JOIN Conversation ON Conversation.qualified_id = Member.conversation
WHERE Conversation.mls_group_id IS NOT NULL AND mls_group_state IS 'ESTABLISHED' AND Member.user = :userId LIMIT 1;
SELECT mls_group_id FROM
(SELECT COUNT(Member.user) AS users_amout, Conversation.mls_group_id, Conversation.mls_group_state FROM Member
JOIN Conversation ON Conversation.qualified_id = Member.conversation
WHERE Member.user = :userId OR Member.user = (SELECT SelfUser.id FROM SelfUser LIMIT 1)
GROUP BY Conversation.qualified_id)
WHERE users_amout > 1 -- both (Self and Other users) belongs to that conversation
AND mls_group_id IS NOT NULL
AND mls_group_state IS 'ESTABLISHED'
LIMIT 1;

getMLSGroupIdByConversationId:
SELECT Conversation.mls_group_id FROM Conversation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,17 @@ class ConversationDAOTest : BaseDatabaseTest() {
ConversationEntity.GroupState.PENDING_WELCOME_MESSAGE,
ConversationEntity.CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521,
(conversationEntity2.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupId,

)
val result = conversationDAO.getConversationByQualifiedID(conversationEntity2.id)
assertEquals(
(result?.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupState, ConversationEntity.GroupState.PENDING_WELCOME_MESSAGE
)
assertEquals(
(result?.protocolInfo as ConversationEntity.ProtocolInfo.MLS).cipherSuite, ConversationEntity.CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521
(result?.protocolInfo as ConversationEntity.ProtocolInfo.MLS).cipherSuite,
ConversationEntity.CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521
)
}

@Test
fun givenExistingConversation_ThenConversationIsUpdatedOnInsert() = runTest {
conversationDAO.insertConversation(conversationEntity1)
Expand Down Expand Up @@ -1649,22 +1650,36 @@ class ConversationDAOTest : BaseDatabaseTest() {
fun givenEstablishedMLSConversationExists_whenGettingMLSGroupIdByUserId_thenReturnsMLSGroupId() = runTest {
// given
val expected = (conversationEntity4.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupId
userDAO.upsertUser(user1)
userDAO.upsertUser(user2)

conversationDAO.insertConversation(conversationEntity1.copy(id = user1.id, type = ConversationEntity.Type.SELF))
conversationDAO.insertConversation(conversationEntity4)
memberDAO.insertMembersWithQualifiedId(
listOf(
MemberEntity(user1.id, MemberEntity.Role.Admin),
MemberEntity(user2.id, MemberEntity.Role.Admin),
MemberEntity(selfUserId, MemberEntity.Role.Admin),
),
conversationEntity4.id
)
// then
assertEquals(expected, conversationDAO.getMLSGroupIdByUserId(user1.id))
}

@Test
fun givenEstablishedMLSConversationExistsButSelfUserIsNotMember_whenGettingMLSGroupIdByUserId_thenNull() = runTest {
// given
conversationDAO.insertConversation(conversationEntity1.copy(id = user1.id, type = ConversationEntity.Type.SELF))
conversationDAO.insertConversation(conversationEntity4)
memberDAO.insertMembersWithQualifiedId(
listOf(
MemberEntity(user1.id, MemberEntity.Role.Admin),
MemberEntity(user2.id, MemberEntity.Role.Admin),
),
conversationEntity4.id
)
// then
assertEquals(null, conversationDAO.getMLSGroupIdByUserId(user1.id))
}

@Test
fun givenMLSSelfConversationDoesNotExists_whenGettingE2EIClientInfoByClientId_thenShouldReturnNull() = runTest {
Expand Down

0 comments on commit 1dd0bdd

Please sign in to comment.