Skip to content

Commit

Permalink
Cleanup field from db
Browse files Browse the repository at this point in the history
  • Loading branch information
m-zagorski committed Nov 28, 2024
1 parent 8e4780d commit 4520416
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ object TestConversation {
userDeleted = false,
connectionStatus = null,
otherUserId = null,
isCreator = 0L,
lastNotificationDate = null,
protocolInfo = protocolInfo,
creatorId = "someValue",
Expand Down Expand Up @@ -315,7 +314,6 @@ object TestConversation {
userDeleted = false,
connectionStatus = null,
otherUserId = null,
isCreator = 0L,
lastNotificationDate = null,
protocolInfo = ConversationEntity.ProtocolInfo.Proteus,
creatorId = "someValue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.active_one_on_one_conversation_id
WHEN 'CONNECTION_PENDING' THEN connection_user.active_one_on_one_conversation_id
END AS otherUserActiveConversationId,
CASE
WHEN (SelfUser.id LIKE (Conversation.creator_id || '@%')) THEN 1
ELSE 0
END AS isCreator,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN coalesce(User.active_one_on_one_conversation_id = Conversation.qualified_id, 0)
ELSE 1
Expand Down
127 changes: 127 additions & 0 deletions persistence/src/commonMain/db_user/migrations/93.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
DROP VIEW IF EXISTS ConversationDetails;

CREATE VIEW IF NOT EXISTS ConversationDetails AS
SELECT
Conversation.qualified_id AS qualifiedId,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.name
WHEN 'CONNECTION_PENDING' THEN connection_user.name
ELSE Conversation.name
END AS name,
Conversation.type,
Call.status AS callStatus,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.preview_asset_id
WHEN 'CONNECTION_PENDING' THEN connection_user.preview_asset_id
END AS previewAssetId,
Conversation.muted_status AS mutedStatus,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.team
ELSE Conversation.team_id
END AS teamId,
CASE (Conversation.type)
WHEN 'CONNECTION_PENDING' THEN Connection.last_update_date
ELSE Conversation.last_modified_date
END AS lastModifiedDate,
Conversation.last_read_date AS lastReadDate,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.user_availability_status
WHEN 'CONNECTION_PENDING' THEN connection_user.user_availability_status
END AS userAvailabilityStatus,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.user_type
WHEN 'CONNECTION_PENDING' THEN connection_user.user_type
END AS userType,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.bot_service
WHEN 'CONNECTION_PENDING' THEN connection_user.bot_service
END AS botService,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.deleted
WHEN 'CONNECTION_PENDING' THEN connection_user.deleted
END AS userDeleted,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.defederated
WHEN 'CONNECTION_PENDING' THEN connection_user.defederated
END AS userDefederated,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.supported_protocols
WHEN 'CONNECTION_PENDING' THEN connection_user.supported_protocols
END AS userSupportedProtocols,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.connection_status
WHEN 'CONNECTION_PENDING' THEN connection_user.connection_status
END AS connectionStatus,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.qualified_id
WHEN 'CONNECTION_PENDING' THEN connection_user.qualified_id
END AS otherUserId,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.active_one_on_one_conversation_id
WHEN 'CONNECTION_PENDING' THEN connection_user.active_one_on_one_conversation_id
END AS otherUserActiveConversationId,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN coalesce(User.active_one_on_one_conversation_id = Conversation.qualified_id, 0)
ELSE 1
END AS isActive,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.accent_id
ELSE 0
END AS accentId,
Conversation.last_notified_date AS lastNotifiedMessageDate,
memberRole. role AS selfRole,
Conversation.protocol,
Conversation.mls_cipher_suite,
Conversation.mls_epoch,
Conversation.mls_group_id,
Conversation.mls_last_keying_material_update_date,
Conversation.mls_group_state,
Conversation.access_list,
Conversation.access_role_list,
Conversation.mls_proposal_timer,
Conversation.muted_time,
Conversation.creator_id,
Conversation.receipt_mode,
Conversation.message_timer,
Conversation.user_message_timer,
Conversation.incomplete_metadata,
Conversation.archived,
Conversation.archived_date_time,
Conversation.verification_status AS mls_verification_status,
Conversation.proteus_verification_status,
Conversation.legal_hold_status,
SelfUser.id AS selfUserId,
CASE
WHEN Conversation.type = 'GROUP' THEN
CASE
WHEN memberRole.role IS NOT NULL THEN 1
ELSE 0
END
WHEN Conversation.type = 'ONE_ON_ONE' THEN
CASE
WHEN User.defederated = 1 THEN 0
WHEN User.deleted = 1 THEN 0
WHEN User.connection_status = 'BLOCKED' THEN 0
WHEN Conversation.legal_hold_status = 'DEGRADED' THEN 0
ELSE 1
END
ELSE 0
END AS interactionEnabled,
LabeledConversation.folder_id IS NOT NULL AS isFavorite
FROM Conversation
LEFT JOIN SelfUser
LEFT JOIN Member ON Conversation.qualified_id = Member.conversation
AND Conversation.type IS 'ONE_ON_ONE'
AND Member.user IS NOT SelfUser.id
LEFT JOIN Member AS memberRole ON Conversation.qualified_id = memberRole.conversation
AND memberRole.user IS SelfUser.id
LEFT JOIN User ON User.qualified_id = Member.user
LEFT JOIN Connection ON Connection.qualified_conversation = Conversation.qualified_id
AND (Connection.status = 'SENT'
OR Connection.status = 'PENDING'
OR Connection.status = 'NOT_CONNECTED'
AND Conversation.type IS 'CONNECTION_PENDING')
LEFT JOIN User AS connection_user ON Connection.qualified_to = connection_user.qualified_id
LEFT JOIN Call ON Call.id IS (SELECT id FROM Call WHERE Call.conversation_id = Conversation.qualified_id AND Call.status IS 'STILL_ONGOING' ORDER BY created_at DESC LIMIT 1)
LEFT JOIN ConversationFolder AS FavoriteFolder ON FavoriteFolder.folder_type = 'FAVORITE'
LEFT JOIN LabeledConversation ON LabeledConversation.conversation_id = Conversation.qualified_id AND LabeledConversation.folder_id = FavoriteFolder.id;
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ data object ConversationDetailsWithEventsMapper {
connectionStatus: ConnectionEntity.State?,
otherUserId: QualifiedIDEntity?,
otherUserActiveConversationId: QualifiedIDEntity?,
isCreator: Long,
isActive: Long,
accentId: Int?,
lastNotifiedMessageDate: Instant?,
Expand Down Expand Up @@ -128,7 +127,6 @@ data object ConversationDetailsWithEventsMapper {
connectionStatus = connectionStatus,
otherUserId = otherUserId,
otherUserActiveConversationId = otherUserActiveConversationId,
isCreator = isCreator,
isActive = isActive,
accentId = accentId,
lastNotifiedMessageDate = lastNotifiedMessageDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ data object ConversationMapper {
connectionStatus: ConnectionEntity.State?,
otherUserId: QualifiedIDEntity?,
otherUserActiveConversationId: QualifiedIDEntity?,
isCreator: Long,
isActive: Long,
accentId: Int?,
lastNotifiedMessageDate: Instant?,
Expand Down Expand Up @@ -90,7 +89,6 @@ data object ConversationMapper {
mlsLastKeyingMaterialUpdateDate,
mlsCipherSuite
),
isCreator = isCreator,
mutedStatus = mutedStatus,
mutedTime = mutedTime,
creatorId = creatorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ data class ConversationViewEntity(
val userDefederated: Boolean?,
val connectionStatus: ConnectionEntity.State? = ConnectionEntity.State.NOT_CONNECTED,
val otherUserId: QualifiedIDEntity?,
val isCreator: Long,
val lastNotificationDate: Instant?,
val selfRole: MemberEntity.Role?,
val protocolInfo: ConversationEntity.ProtocolInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,21 +886,6 @@ class ConversationDAOTest : BaseDatabaseTest() {
assertEquals(messageTimer, result?.messageTimer)
}

@Test
fun givenSelfUserIsCreatorOfConversation_whenGettingConversationDetails_itReturnsCorrectDetails() = runTest(dispatcher) {
// given
conversationDAO.insertConversation(conversationEntity3.copy(creatorId = selfUserId.value))
teamDAO.insertTeam(team)
userDAO.upsertUser(user2)
insertTeamUserAndMember(team, user2, conversationEntity3.id)

// when
val result = conversationDAO.getConversationDetailsById(conversationEntity3.id)

// then
assertEquals(1L, result?.isCreator)
}

@Test
fun givenMixedConversation_whenGettingConversationProtocolInfo_itReturnsCorrectInfo() = runTest {
// given
Expand Down Expand Up @@ -2358,7 +2343,6 @@ class ConversationDAOTest : BaseDatabaseTest() {
userDeleted = if (type == ConversationEntity.Type.ONE_ON_ONE) userEntity?.deleted else null,
connectionStatus = if (type == ConversationEntity.Type.ONE_ON_ONE) userEntity?.connectionStatus else null,
otherUserId = if (type == ConversationEntity.Type.ONE_ON_ONE) userEntity?.id else null,
isCreator = 0L,
lastNotificationDate = lastNotificationDate,
protocolInfo = protocolInfo,
accessList = access,
Expand Down

0 comments on commit 4520416

Please sign in to comment.