diff --git a/data/build.gradle.kts b/data/build.gradle.kts new file mode 100644 index 00000000000..11e58a18b0c --- /dev/null +++ b/data/build.gradle.kts @@ -0,0 +1,49 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +plugins { + id(libs.plugins.android.library.get().pluginId) + id(libs.plugins.kotlin.multiplatform.get().pluginId) + alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.ksp) + id(libs.plugins.kalium.library.get().pluginId) +} + +kaliumLibrary { + multiplatform { + enableJs.set(false) + } +} +kotlin { + sourceSets { + @Suppress("UnusedPrivateProperty") + val commonMain by getting { + dependencies { + implementation(project(":network-model")) + implementation(project(":util")) + + implementation(libs.ktor.utils) + implementation(libs.coroutines.core) + implementation(libs.ktxDateTime) + implementation(libs.ktxSerialization) + implementation(libs.ktor.serialization) + + implementation(libs.okio.core) + } + } + } +} diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMessage.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMessage.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMessage.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMessage.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Call.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Call.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Call.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Call.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallActiveSpeakers.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallActiveSpeakers.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallActiveSpeakers.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallActiveSpeakers.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallClient.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallClient.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallClient.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallClient.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallParticipants.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallParticipants.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallParticipants.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallParticipants.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallType.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallType.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallType.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallType.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/ConversationType.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/ConversationType.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/ConversationType.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/ConversationType.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/EpochInfo.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/EpochInfo.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/EpochInfo.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/EpochInfo.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Participant.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Participant.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Participant.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/Participant.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/TestVideoType.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/TestVideoType.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/TestVideoType.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/TestVideoType.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/VideoState.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/VideoState.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/VideoState.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/VideoState.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt similarity index 84% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt index aaff7500779..14e1bb132b0 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt @@ -18,26 +18,11 @@ package com.wire.kalium.logic.data.client -import com.wire.kalium.cryptography.PreKeyCrypto import com.wire.kalium.logic.data.conversation.ClientId import kotlinx.datetime.Clock import kotlinx.datetime.Instant import kotlin.time.Duration.Companion.days -data class RegisterClientParam( - val password: String?, - val preKeys: List, - val lastKey: PreKeyCrypto, - val deviceType: DeviceType?, - val label: String?, - val capabilities: List?, - val clientType: ClientType?, - val model: String?, - val cookieLabel: String?, - val secondFactorVerificationCode: String? = null, - val modelPostfix: String? = null -) - data class DeleteClientParam( val password: String?, val clientId: ClientId diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionDetails.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionDetails.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionDetails.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionDetails.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGuestLink.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGuestLink.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGuestLink.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGuestLink.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationOptions.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationOptions.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationOptions.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationOptions.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationStatus.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationStatus.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationStatus.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationStatus.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ProposalTimer.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ProposalTimer.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ProposalTimer.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ProposalTimer.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/MemberLeaveReason.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/event/MemberLeaveReason.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/MemberLeaveReason.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/event/MemberLeaveReason.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/featureConfig/FeatureConfigModel.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/featureConfig/FeatureConfigModel.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/featureConfig/FeatureConfigModel.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/featureConfig/FeatureConfigModel.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/id/PlainId.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/id/PlainId.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/id/PlainId.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/id/PlainId.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/id/QualifiedId.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/id/QualifiedId.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/id/QualifiedId.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/id/QualifiedId.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LegalHoldRequest.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LegalHoldRequest.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LegalHoldRequest.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LegalHoldRequest.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/ListUsersLegalHoldConsent.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/ListUsersLegalHoldConsent.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/ListUsersLegalHoldConsent.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/ListUsersLegalHoldConsent.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/AssetContent.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/AssetContent.kt similarity index 95% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/AssetContent.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/AssetContent.kt index f7ec360841d..1c77a460c34 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/AssetContent.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/AssetContent.kt @@ -18,8 +18,6 @@ package com.wire.kalium.logic.data.message -import com.wire.kalium.logic.sync.receiver.conversation.message.hasValidRemoteData - data class AssetContent( val sizeInBytes: Long, val name: String? = null, @@ -101,3 +99,7 @@ data class AssetContent( } } } + +fun AssetContent.hasValidRemoteData() = remoteData.hasValidData() + +fun AssetContent.RemoteData.hasValidData() = assetId.isNotEmpty() && sha256.isNotEmpty() && otrKey.isNotEmpty() diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageBlob.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageBlob.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageBlob.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageBlob.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContentLogging.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContentLogging.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContentLogging.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContentLogging.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEncryptionAlgorithm.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEncryptionAlgorithm.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEncryptionAlgorithm.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEncryptionAlgorithm.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEnvelope.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEnvelope.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEnvelope.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageEnvelope.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MigratedMessage.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MigratedMessage.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MigratedMessage.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MigratedMessage.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContent.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContent.kt similarity index 91% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContent.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContent.kt index 6e0c5c09bf3..4bba4435356 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContent.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContent.kt @@ -15,13 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ - package com.wire.kalium.logic.data.message import com.wire.kalium.logic.data.conversation.Conversation -import com.wire.kalium.logic.data.message.ProtoContent.ExternalMessageInstructions -import com.wire.kalium.persistence.dao.conversation.ConversationEntity.ProtocolInfo.Proteus -import com.wire.kalium.protobuf.messages.GenericMessage /** * The result of the [protobuf model](https://github.com/wireapp/generic-message-proto) parsing. diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/SelfDeletionTimer.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/SelfDeletionTimer.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/SelfDeletionTimer.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/SelfDeletionTimer.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/UserSummary.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/UserSummary.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/UserSummary.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/UserSummary.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/draft/MessageDraft.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/draft/MessageDraft.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/draft/MessageDraft.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/draft/MessageDraft.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewAsset.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewAsset.kt similarity index 86% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewAsset.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewAsset.kt index 23e36bba460..03caa229cc7 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewAsset.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewAsset.kt @@ -17,8 +17,6 @@ */ package com.wire.kalium.logic.data.message.linkpreview -import com.wire.kalium.cryptography.utils.AES256Key -import com.wire.kalium.cryptography.utils.SHA256Key import com.wire.kalium.logic.data.message.AssetContent.AssetMetadata import com.wire.kalium.logic.data.message.MessageEncryptionAlgorithm import okio.Path @@ -35,7 +33,7 @@ data class LinkPreviewAsset( var assetKey: String? = null, var assetToken: String? = null, var assetDomain: String? = null, - var otrKey: AES256Key = AES256Key(ByteArray(0)), - var sha256Key: SHA256Key = SHA256Key(ByteArray(0)), + var otrKey: ByteArray = ByteArray(0), + var sha256Key: ByteArray = ByteArray(0), var encryptionAlgorithm: MessageEncryptionAlgorithm = MessageEncryptionAlgorithm.AES_CBC, ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/MessageLinkPreview.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/MessageLinkPreview.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/MessageLinkPreview.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/MessageLinkPreview.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/mention/MessageMention.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/mention/MessageMention.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/mention/MessageMention.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/mention/MessageMention.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/reaction/MessageReaction.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/reaction/MessageReaction.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/reaction/MessageReaction.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/reaction/MessageReaction.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/receipt/DetailedReceipt.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/receipt/DetailedReceipt.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/receipt/DetailedReceipt.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/receipt/DetailedReceipt.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/notification/LocalNotification.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/notification/LocalNotification.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/notification/LocalNotification.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/notification/LocalNotification.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/service/ServiceDetails.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/service/ServiceDetails.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/service/ServiceDetails.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/service/ServiceDetails.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/Team.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/team/Team.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/Team.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/team/Team.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamPermission.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamPermission.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamPermission.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamPermission.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/LegalHoldStatus.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/LegalHoldStatus.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/LegalHoldStatus.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/LegalHoldStatus.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserModel.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserModel.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserModel.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserModel.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/type/UserType.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/type/UserType.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/type/UserType.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/type/UserType.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/KtxWebSerializer.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/KtxWebSerializer.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/KtxWebSerializer.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/KtxWebSerializer.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebContentSerialization.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebContentSerialization.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebContentSerialization.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebContentSerialization.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebEventContent.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebEventContent.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebEventContent.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebEventContent.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebMappers.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebMappers.kt similarity index 100% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebMappers.kt rename to data/src/commonMain/kotlin/com/wire/kalium/logic/data/web/WebMappers.kt diff --git a/logic/build.gradle.kts b/logic/build.gradle.kts index 7576a290740..fe669e73d84 100644 --- a/logic/build.gradle.kts +++ b/logic/build.gradle.kts @@ -38,6 +38,7 @@ kotlin { val commonMain by getting { dependencies { implementation(project(":network")) + api(project(":data")) api(project(":network-util")) implementation(project(":cryptography")) implementation(project(":persistence")) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMapper.kt index f109ec1081f..cc4314fa207 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/AssetMapper.kt @@ -206,22 +206,24 @@ class AssetMapperImpl( mimeType = mimeType, size = sizeInBytes, name = name, - metaData = when (metadata) { - is Image -> Asset.Original.MetaData.Image( - Asset.ImageMetaData( - width = metadata.width, - height = metadata.height, + metaData = metadata.let { + when (it) { + is Image -> Asset.Original.MetaData.Image( + Asset.ImageMetaData( + width = it.width, + height = it.height, + ) ) - ) - is Audio -> Asset.Original.MetaData.Audio( - audio = Asset.AudioMetaData( - durationInMillis = metadata.durationMs, - normalizedLoudness = metadata.normalizedLoudness?.let { ByteArr(it) } + is Audio -> Asset.Original.MetaData.Audio( + audio = Asset.AudioMetaData( + durationInMillis = it.durationMs, + normalizedLoudness = it.normalizedLoudness?.let { ByteArr(it) } + ) ) - ) - else -> null + else -> null + } } ), status = Asset.Status.Uploaded( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/RegisterClientParam.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/RegisterClientParam.kt new file mode 100644 index 00000000000..25b7bb734fa --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/RegisterClientParam.kt @@ -0,0 +1,34 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.data.client + +import com.wire.kalium.cryptography.PreKeyCrypto + +data class RegisterClientParam( + val password: String?, + val preKeys: List, + val lastKey: PreKeyCrypto, + val deviceType: DeviceType?, + val label: String?, + val capabilities: List?, + val clientType: ClientType?, + val model: String?, + val cookieLabel: String?, + val secondFactorVerificationCode: String? = null, + val modelPostfix: String? = null +) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt index f021586e19e..32044174038 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt @@ -88,15 +88,17 @@ class MessageMapperImpl( senderUserId = message.senderUserId.toDao(), senderClientId = message.senderClientId.value, status = message.status.toEntityStatus(), - readCount = if (message.status is Message.Status.Read) message.status.readCount else 0, - editStatus = when (message.editStatus) { - is Message.EditStatus.NotEdited -> MessageEntity.EditStatus.NotEdited - is Message.EditStatus.Edited -> MessageEntity.EditStatus.Edited(message.editStatus.lastEditInstant) + readCount = message.status.let { if (it is Message.Status.Read) it.readCount else 0 }, + editStatus = message.editStatus.let { + when (it) { + is Message.EditStatus.NotEdited -> MessageEntity.EditStatus.NotEdited + is Message.EditStatus.Edited -> MessageEntity.EditStatus.Edited(it.lastEditInstant) + } }, expireAfterMs = message.expirationData?.expireAfter?.inWholeMilliseconds, - selfDeletionEndDate = message.expirationData?.let { - when (it.selfDeletionStatus) { - is Message.ExpirationData.SelfDeletionStatus.Started -> it.selfDeletionStatus.selfDeletionEndDate + selfDeletionEndDate = message.expirationData?.selfDeletionStatus?.let { + when (it) { + is Message.ExpirationData.SelfDeletionStatus.Started -> it.selfDeletionEndDate is Message.ExpirationData.SelfDeletionStatus.NotStarted -> null } }, @@ -118,10 +120,10 @@ class MessageMapperImpl( visibility = message.visibility.toEntityVisibility(), senderName = message.senderUserName, expireAfterMs = message.expirationData?.expireAfter?.inWholeMilliseconds, - readCount = if (message.status is Message.Status.Read) message.status.readCount else 0, - selfDeletionEndDate = message.expirationData?.let { - when (it.selfDeletionStatus) { - is Message.ExpirationData.SelfDeletionStatus.Started -> it.selfDeletionStatus.selfDeletionEndDate + readCount = message.status.let { if (it is Message.Status.Read) it.readCount else 0 }, + selfDeletionEndDate = message.expirationData?.selfDeletionStatus?.let { + when (it) { + is Message.ExpirationData.SelfDeletionStatus.Started -> it.selfDeletionEndDate is Message.ExpirationData.SelfDeletionStatus.NotStarted -> null } } @@ -331,6 +333,7 @@ class MessageMapperImpl( is MessageContent.Text -> toTextEntity(regularMessage) is MessageContent.Asset -> with(regularMessage.value) { + val metadata = metadata val assetWidth = when (metadata) { is Image -> metadata.width is Video -> metadata.width @@ -421,10 +424,13 @@ fun MessageEntityContent.System.toMessageContent(): MessageContent.System = when MessageEntity.MemberChangeType.CREATION_ADDED -> MessageContent.MemberChange.CreationAdded(memberList) MessageEntity.MemberChangeType.FAILED_TO_ADD_FEDERATION -> MessageContent.MemberChange.FailedToAdd(memberList, MessageContent.MemberChange.FailedToAdd.Type.Federation) + MessageEntity.MemberChangeType.FAILED_TO_ADD_LEGAL_HOLD -> MessageContent.MemberChange.FailedToAdd(memberList, MessageContent.MemberChange.FailedToAdd.Type.LegalHold) + MessageEntity.MemberChangeType.FAILED_TO_ADD_UNKNOWN -> MessageContent.MemberChange.FailedToAdd(memberList, MessageContent.MemberChange.FailedToAdd.Type.Unknown) + MessageEntity.MemberChangeType.FEDERATION_REMOVED -> MessageContent.MemberChange.FederationRemoved(memberList) MessageEntity.MemberChangeType.REMOVED_FROM_TEAM -> MessageContent.MemberChange.RemovedFromTeam(memberList) } @@ -669,8 +675,10 @@ fun MessageContent.System.toMessageEntityContent(): MessageEntityContent.System when (this.type) { MessageContent.MemberChange.FailedToAdd.Type.Federation -> MessageEntityContent.MemberChange(memberUserIdList, MessageEntity.MemberChangeType.FAILED_TO_ADD_FEDERATION) + MessageContent.MemberChange.FailedToAdd.Type.LegalHold -> MessageEntityContent.MemberChange(memberUserIdList, MessageEntity.MemberChangeType.FAILED_TO_ADD_LEGAL_HOLD) + MessageContent.MemberChange.FailedToAdd.Type.Unknown -> MessageEntityContent.MemberChange(memberUserIdList, MessageEntity.MemberChangeType.FAILED_TO_ADD_UNKNOWN) } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContentMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContentMapper.kt index 26468f804c8..100937dddd0 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContentMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/ProtoContentMapper.kt @@ -86,10 +86,11 @@ class ProtoContentMapperImpl( @Suppress("ComplexMethod") private fun mapReadableContentToProtobuf(protoContent: ProtoContent.Readable): GenericMessage.Content { - return if (protoContent.expiresAfterMillis != null) { + val expiration = protoContent.expiresAfterMillis + return if (expiration != null) { mapEphemeralContent( protoContent.messageContent, - protoContent.expiresAfterMillis, + expiration, protoContent.expectsReadConfirmation, protoContent.legalHoldStatus ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewMapper.kt index 1637f4b6a17..173e39a43ba 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/linkpreview/LinkPreviewMapper.kt @@ -90,26 +90,26 @@ class LinkPreviewMapperImpl( permanentUrl = linkPreview.permanentUrl, title = linkPreview.title, summary = linkPreview.summary, - image = linkPreview.image?.let { + image = linkPreview.image?.let { image -> Asset( original = Asset.Original( - mimeType = linkPreview.image.mimeType, - size = linkPreview.image.assetDataSize, + mimeType = image.mimeType, + size = image.assetDataSize, metaData = Asset.Original.MetaData.Image( image = Asset.ImageMetaData( - height = linkPreview.image.assetHeight, - width = linkPreview.image.assetWidth + height = image.assetHeight, + width = image.assetWidth ) ) ), status = Asset.Status.Uploaded( uploaded = Asset.RemoteData( - otrKey = ByteArr(linkPreview.image.otrKey.data), - sha256 = ByteArr(linkPreview.image.sha256Key.data), - assetId = linkPreview.image.assetKey, - assetToken = linkPreview.image.assetToken, - assetDomain = linkPreview.image.assetDomain, - encryption = encryptionAlgorithmMapper.toProtoBufModel(linkPreview.image.encryptionAlgorithm) + otrKey = ByteArr(image.otrKey), + sha256 = ByteArr(image.sha256Key), + assetId = image.assetKey, + assetToken = image.assetToken, + assetDomain = image.assetDomain, + encryption = encryptionAlgorithmMapper.toProtoBufModel(image.encryptionAlgorithm) ) ) ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/RecoverMLSConversationsUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/RecoverMLSConversationsUseCase.kt index f6a1f07fb64..70ceab9e59b 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/RecoverMLSConversationsUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/RecoverMLSConversationsUseCase.kt @@ -73,8 +73,9 @@ internal class RecoverMLSConversationsUseCaseImpl( } private suspend fun recoverMLSGroup(conversation: Conversation): Either { - return if (conversation.protocol is Conversation.ProtocolInfo.MLS) { - mlsConversationRepository.isGroupOutOfSync(conversation.protocol.groupId, conversation.protocol.epoch) + val protocol = conversation.protocol + return if (protocol is Conversation.ProtocolInfo.MLS) { + mlsConversationRepository.isGroupOutOfSync(protocol.groupId, protocol.epoch) .fold({ checkEpochFailure -> Either.Left(checkEpochFailure) }, { isGroupOutOfSync -> diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/FetchConversationMLSVerificationStatusUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/FetchConversationMLSVerificationStatusUseCase.kt index 7583bd17014..5709f1381eb 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/FetchConversationMLSVerificationStatusUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/FetchConversationMLSVerificationStatusUseCase.kt @@ -36,8 +36,9 @@ internal class FetchConversationMLSVerificationStatusUseCaseImpl( override suspend fun invoke(conversationId: ConversationId) { conversationRepository.detailsById(conversationId).onSuccess { - if (it.protocol is Conversation.ProtocolInfo.MLSCapable) - fetchMLSVerificationStatusUseCase(it.protocol.groupId) + val protocol = it.protocol + if (protocol is Conversation.ProtocolInfo.MLSCapable) + fetchMLSVerificationStatusUseCase(protocol.groupId) } } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSendingInterceptor.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSendingInterceptor.kt index d60995998d0..4d82ae85d52 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSendingInterceptor.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageSendingInterceptor.kt @@ -39,14 +39,15 @@ internal class MessageSendingInterceptorImpl internal constructor( val replyMessageContent = originalMessage.content + val quotedReference = (replyMessageContent as? MessageContent.Text)?.quotedMessageReference if (replyMessageContent !is MessageContent.Text || originalMessage !is Message.Regular - || replyMessageContent.quotedMessageReference == null + || quotedReference == null ) { return Either.Right(originalMessage) } - return messageRepository.getMessageById(originalMessage.conversationId, replyMessageContent.quotedMessageReference.quotedMessageId) + return messageRepository.getMessageById(originalMessage.conversationId, quotedReference.quotedMessageId) .map { persistedMessage -> val encodedMessageContent = messageContentEncoder.encodeMessageContent( messageInstant = persistedMessage.date, @@ -55,7 +56,7 @@ internal class MessageSendingInterceptorImpl internal constructor( originalMessage.copy( content = replyMessageContent.copy( - quotedMessageReference = replyMessageContent.quotedMessageReference.copy( + quotedMessageReference = quotedReference.copy( quotedMessageSha256 = encodedMessageContent?.sha256Digest ) ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/PersistMigratedMessagesUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/PersistMigratedMessagesUseCase.kt index 45d51246e72..3c039c5acce 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/PersistMigratedMessagesUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/PersistMigratedMessagesUseCase.kt @@ -67,8 +67,9 @@ internal class PersistMigratedMessagesUseCaseImpl( messages.filter { it.encryptedProto != null || it.unencryptedProto != null }.map { migratedMessage -> coroutineScope.launch(coroutineContext) { - if (migratedMessage.unencryptedProto != null) { - protoMessages[migratedMessage] = migratedMessage.unencryptedProto + val unencryptedProto = migratedMessage.unencryptedProto + if (unencryptedProto != null) { + protoMessages[migratedMessage] = unencryptedProto } else { (try { protoContentMapper.decodeFromProtobuf( @@ -89,16 +90,18 @@ internal class PersistMigratedMessagesUseCaseImpl( } is ProtoContent.Readable -> { + val messageContent = proto.messageContent + val assetSize = migratedMessage.assetSize val updatedProto = - if (migratedMessage.assetSize != null && + if (assetSize != null && migratedMessage.assetName != null && - proto.messageContent is MessageContent.Asset + messageContent is MessageContent.Asset ) { proto.copy( - messageContent = proto.messageContent.copy( - value = proto.messageContent.value.copy( + messageContent = messageContent.copy( + value = messageContent.value.copy( name = migratedMessage.assetName, - sizeInBytes = migratedMessage.assetSize.toLong() + sizeInBytes = assetSize.toLong() ) ) ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt index 32a2f3f25b0..1d11875af16 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt @@ -88,9 +88,10 @@ class RetryFailedMessageUseCase internal constructor( messageUuid = message.id ) scope.launch(dispatcher.io) { + val content = message.content when { - message is Message.Regular && message.content is MessageContent.Asset -> - retrySendingAssetMessage(message, message.content.value) + message is Message.Regular && content is MessageContent.Asset -> + retrySendingAssetMessage(message, content.value) message is Message.Regular && message.editStatus is Message.EditStatus.Edited -> retrySendingEditMessage(message) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageUseCase.kt index 6aed93a89ce..e95265b66fe 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageUseCase.kt @@ -19,6 +19,7 @@ package com.wire.kalium.logic.feature.message import com.benasher44.uuid.uuid4 +import com.wire.kalium.cryptography.utils.AES256Key import com.wire.kalium.cryptography.utils.generateRandomAES256Key import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.data.asset.AssetRepository @@ -131,13 +132,13 @@ class SendTextMessageUseCase internal constructor( return linkPreviews.map { linkPreview -> val imageCopy = linkPreview.image?.let { // Generate the otr asymmetric key that will be used to encrypt the data - it.otrKey = generateRandomAES256Key() + it.otrKey = generateRandomAES256Key().data // The assetDataSource will encrypt the data with the provided otrKey and upload it if successful it.assetDataPath?.let { assetDataPath -> assetDataSource.uploadAndPersistPrivateAsset( it.mimeType, assetDataPath, - it.otrKey, + AES256Key(it.otrKey), null ).onFailure { failure -> // on upload failure we still want link previews being included without image @@ -146,7 +147,7 @@ class SendTextMessageUseCase internal constructor( it.assetToken = assetId.assetToken ?: "" it.assetKey = assetId.key it.assetDomain = assetId.domain - it.sha256Key = sha256Key + it.sha256Key = sha256Key.data it } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrationWorker.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrationWorker.kt index 3350536d6b9..bb3efcdb2c4 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrationWorker.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrationWorker.kt @@ -57,11 +57,14 @@ internal class MLSMigrationWorkerImpl( } } ?: Either.Right(Unit) } + private suspend fun syncMigrationConfigurations(): Either = featureConfigRepository.getFeatureConfigs().flatMap { configurations -> mlsConfigHandler.handle(configurations.mlsModel, duringSlowSync = false) - .flatMap { configurations.mlsMigrationModel?.let { - mlsMigrationConfigHandler.handle(configurations.mlsMigrationModel, duringSlowSync = false) - } ?: Either.Right(Unit) } + .flatMap { + configurations.mlsMigrationModel?.let { migrationModel -> + mlsMigrationConfigHandler.handle(migrationModel, duringSlowSync = false) + } ?: Either.Right(Unit) + } } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/selfDeletingMessages/ObserveSelfDeletionTimerSettingsForConversationUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/selfDeletingMessages/ObserveSelfDeletionTimerSettingsForConversationUseCase.kt index f7e6b1989c9..fb6eda03900 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/selfDeletingMessages/ObserveSelfDeletionTimerSettingsForConversationUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/selfDeletingMessages/ObserveSelfDeletionTimerSettingsForConversationUseCase.kt @@ -60,11 +60,11 @@ class ObserveSelfDeletionTimerSettingsForConversationUseCaseImpl internal constr teamSettings.fold({ onTeamEnabled(conversationDetailsEither, considerSelfUserSettings) }, { - when (it.enforcedSelfDeletionTimer) { + when (val deletionTimer = it.enforcedSelfDeletionTimer) { TeamSelfDeleteTimer.Disabled -> SelfDeletionTimer.Disabled TeamSelfDeleteTimer.Enabled -> onTeamEnabled(conversationDetailsEither, considerSelfUserSettings) is TeamSelfDeleteTimer.Enforced -> SelfDeletionTimer.Enforced.ByTeam( - it.enforcedSelfDeletionTimer.enforcedDuration + deletionTimer.enforcedDuration ) } }) @@ -75,8 +75,9 @@ class ObserveSelfDeletionTimerSettingsForConversationUseCaseImpl internal constr conversation.fold({ SelfDeletionTimer.Enabled(null) }, { + val messageTimer = it.messageTimer when { - it.messageTimer.isPositiveNotNull() -> SelfDeletionTimer.Enforced.ByGroup(it.messageTimer) + messageTimer.isPositiveNotNull() -> SelfDeletionTimer.Enforced.ByGroup(messageTimer) considerSelfUserSettings && it.userMessageTimer.isPositiveNotNull() -> SelfDeletionTimer.Enabled(it.userMessageTimer) else -> SelfDeletionTimer.Enabled(null) } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/GetUserInfoUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/GetUserInfoUseCase.kt index 9ce4951b162..a28983539e9 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/GetUserInfoUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/GetUserInfoUseCase.kt @@ -76,11 +76,12 @@ internal class GetUserInfoUseCaseImpl( * @see [UserType] */ private suspend fun getOtherUserTeam(otherUser: OtherUser): Either { - return if (otherUser.teamId != null && otherUser.userType in listOf(UserType.INTERNAL, UserType.OWNER)) { - val localTeam = teamRepository.getTeam(otherUser.teamId).firstOrNull() + val teamId = otherUser.teamId + return if (teamId != null && otherUser.userType in listOf(UserType.INTERNAL, UserType.OWNER)) { + val localTeam = teamRepository.getTeam(teamId).firstOrNull() if (localTeam == null) { - teamRepository.fetchTeamById(otherUser.teamId) + teamRepository.fetchTeamById(teamId) } else { Either.Right(localTeam) } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/ObserveUserInfoUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/ObserveUserInfoUseCase.kt index cfcb8a682e6..5688d266312 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/ObserveUserInfoUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/ObserveUserInfoUseCase.kt @@ -97,10 +97,11 @@ internal class ObserveUserInfoUseCaseImpl( * @see [UserType] */ private suspend fun observeOtherUserTeam(otherUser: OtherUser): Flow> { - return if (otherUser.teamId != null && otherUser.userType in listOf(UserType.INTERNAL, UserType.OWNER)) { - teamRepository.getTeam(otherUser.teamId).map { localTeam -> + val teamId = otherUser.teamId + return if (teamId != null && otherUser.userType in listOf(UserType.INTERNAL, UserType.OWNER)) { + teamRepository.getTeam(teamId).map { localTeam -> if (localTeam == null) { - teamRepository.fetchTeamById(otherUser.teamId) + teamRepository.fetchTeamById(teamId) } else { Either.Right(localTeam) } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt index a5fd1737a2f..57ac934a25b 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt @@ -24,11 +24,11 @@ import com.wire.kalium.logic.data.message.Message import com.wire.kalium.logic.data.message.MessageContent import com.wire.kalium.logic.data.message.MessageRepository import com.wire.kalium.logic.data.message.PersistMessageUseCase +import com.wire.kalium.logic.data.message.hasValidData import com.wire.kalium.logic.feature.asset.ValidateAssetMimeTypeUseCase import com.wire.kalium.logic.functional.onFailure import com.wire.kalium.logic.functional.onSuccess import com.wire.kalium.logic.kaliumLogger -import com.wire.kalium.logic.sync.receiver.conversation.message.hasValidData internal interface AssetMessageHandler { suspend fun handle(message: Message.Regular) @@ -42,11 +42,11 @@ internal class AssetMessageHandlerImpl( ) : AssetMessageHandler { override suspend fun handle(message: Message.Regular) { - if (message.content !is MessageContent.Asset) { + val messageContent = message.content + if (messageContent !is MessageContent.Asset) { kaliumLogger.e("The asset message trying to be processed has invalid content data") return } - val messageContent = message.content userConfigRepository.isFileSharingEnabled().onSuccess { val isThisAssetAllowed = when (it.state) { FileSharingStatus.Value.Disabled -> false diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ApplicationMessageHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ApplicationMessageHandler.kt index 32067b3ca3c..a77791afef7 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ApplicationMessageHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ApplicationMessageHandler.kt @@ -29,6 +29,8 @@ import com.wire.kalium.logic.data.message.PersistMessageUseCase import com.wire.kalium.logic.data.message.PersistReactionUseCase import com.wire.kalium.logic.data.message.ProtoContent import com.wire.kalium.logic.data.message.getType +import com.wire.kalium.logic.data.message.hasValidData +import com.wire.kalium.logic.data.message.hasValidRemoteData import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.data.user.UserRepository import com.wire.kalium.logic.feature.call.CallManager @@ -304,6 +306,14 @@ internal class ApplicationMessageHandlerImpl( } } -fun AssetContent.hasValidRemoteData() = this.remoteData.hasValidData() +@Deprecated( + "This will be moved to another package", + ReplaceWith("com.wire.kalium.logic.data.message.hasValidRemoteData") +) +fun AssetContent.hasValidRemoteData() = hasValidRemoteData() -fun AssetContent.RemoteData.hasValidData() = assetId.isNotEmpty() && sha256.isNotEmpty() && otrKey.isNotEmpty() +@Deprecated( + "This will be moved to another package", + ReplaceWith("com.wire.kalium.logic.data.message.hasValidData") +) +fun AssetContent.RemoteData.hasValidData() = hasValidData() diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/ButtonActionConfirmationhandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/ButtonActionConfirmationhandler.kt index ef98167ed7f..caa9b9c2949 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/ButtonActionConfirmationhandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/ButtonActionConfirmationhandler.kt @@ -53,11 +53,12 @@ internal class ButtonActionConfirmationHandlerImpl internal constructor( Either.Right(Unit) } }.flatMap { - if (messageContent.buttonId != null) { + val buttonId = messageContent.buttonId + if (buttonId != null) { compositeMessageRepository.markSelected( messageId = messageId, conversationId = conversationId, - buttonId = messageContent.buttonId + buttonId = buttonId ) } else { compositeMessageRepository.resetSelection( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/MessageTextEditHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/MessageTextEditHandler.kt index 689ace90bd7..61e01d5b796 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/MessageTextEditHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/handler/MessageTextEditHandler.kt @@ -56,21 +56,23 @@ internal class MessageTextEditHandlerImpl internal constructor( return@flatMap Either.Left(StorageFailure.DataNotFound) } + val editStatus = (currentMessage as? Message.Regular)?.editStatus + val content = currentMessage.content if (currentMessage is Message.Regular - && currentMessage.content is MessageContent.Text - && currentMessage.editStatus is Message.EditStatus.Edited + && content is MessageContent.Text + && editStatus is Message.EditStatus.Edited ) { // if the locally stored message is also already edited, we check which one is newer - if (currentMessage.editStatus.lastEditInstant < message.date) { + if (editStatus.lastEditInstant < message.date) { // our local pending or failed edit is newer than one we got from the backend so we update locally only message id and date messageRepository.updateTextMessage( conversationId = message.conversationId, messageContent = messageContent.copy( - newContent = currentMessage.content.value, - newMentions = currentMessage.content.mentions + newContent = content.value, + newMentions = content.mentions ), newMessageId = message.id, - editInstant = currentMessage.editStatus.lastEditInstant + editInstant = editStatus.lastEditInstant ) } else { notificationEventsManager.scheduleEditMessageNotification(message, messageContent) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageCaseTest.kt index beb4c8b4550..2186a05c05b 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/SendTextMessageCaseTest.kt @@ -18,7 +18,6 @@ package com.wire.kalium.logic.feature.message -import com.wire.kalium.cryptography.utils.AES256Key import com.wire.kalium.cryptography.utils.SHA256Key import com.wire.kalium.logic.NetworkFailure import com.wire.kalium.logic.data.asset.AssetRepository @@ -138,14 +137,16 @@ class SendTextMessageCaseTest { .withMessageTimer(SelfDeletionTimer.Disabled) .withSendMessageSuccess() .arrange() - val linkPreviews = listOf(MessageLinkPreview( - url = "", - urlOffset = 0, - permanentUrl = "", - summary = "", - title = "", - image = null - )) + val linkPreviews = listOf( + MessageLinkPreview( + url = "", + urlOffset = 0, + permanentUrl = "", + summary = "", + title = "", + image = null + ) + ) // When val result = sendTextMessage(TestConversation.ID, "some-text", linkPreviews) @@ -175,14 +176,16 @@ class SendTextMessageCaseTest { .withMessageTimer(SelfDeletionTimer.Disabled) .withSendMessageSuccess() .arrange() - val linkPreviews = listOf(MessageLinkPreview( - url = "", - urlOffset = 0, - permanentUrl = "", - summary = "", - title = "", - image = VALID_LINK_PREVIEW_ASSET - )) + val linkPreviews = listOf( + MessageLinkPreview( + url = "", + urlOffset = 0, + permanentUrl = "", + summary = "", + title = "", + image = VALID_LINK_PREVIEW_ASSET + ) + ) // When val result = sendTextMessage(TestConversation.ID, "some-text", linkPreviews) @@ -194,10 +197,12 @@ class SendTextMessageCaseTest { arrangement.assetRepository.uploadAndPersistPrivateAsset(any(), any(), any(), any()) }.wasInvoked(once) coVerify { - arrangement.persistMessage.invoke(matches { message -> - (message.content as MessageContent.Text).linkPreviews.get(0).image != null - && (message.content as MessageContent.Text).linkPreviews.get(0).image?.otrKey != AES256Key(ByteArray(0)) - }) + arrangement.persistMessage.invoke( + matches { message -> + (message.content as MessageContent.Text).linkPreviews[0].image != null + && !(message.content as MessageContent.Text).linkPreviews[0].image?.otrKey.contentEquals(ByteArray(0)) + } + ) }.wasInvoked(once) } @@ -213,14 +218,16 @@ class SendTextMessageCaseTest { .withMessageTimer(SelfDeletionTimer.Disabled) .withSendMessageSuccess() .arrange() - val linkPreviews = listOf(MessageLinkPreview( - url = "", - urlOffset = 0, - permanentUrl = "", - summary = "", - title = "", - image = INVALID_LINK_PREVIEW_ASSET - )) + val linkPreviews = listOf( + MessageLinkPreview( + url = "", + urlOffset = 0, + permanentUrl = "", + summary = "", + title = "", + image = INVALID_LINK_PREVIEW_ASSET + ) + ) // When val result = sendTextMessage(TestConversation.ID, "some-text", linkPreviews) @@ -250,14 +257,16 @@ class SendTextMessageCaseTest { .withMessageTimer(SelfDeletionTimer.Disabled) .withSendMessageSuccess() .arrange() - val linkPreviews = listOf(MessageLinkPreview( - url = "", - urlOffset = 0, - permanentUrl = "", - summary = "", - title = "", - image = VALID_LINK_PREVIEW_ASSET - )) + val linkPreviews = listOf( + MessageLinkPreview( + url = "", + urlOffset = 0, + permanentUrl = "", + summary = "", + title = "", + image = VALID_LINK_PREVIEW_ASSET + ) + ) // When val result = sendTextMessage(TestConversation.ID, "some-text", linkPreviews) diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt index 59b89e9bb9c..e68281d90de 100644 --- a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt @@ -28,11 +28,11 @@ import com.wire.kalium.logic.data.message.MessageContent import com.wire.kalium.logic.data.message.MessageEncryptionAlgorithm import com.wire.kalium.logic.data.message.MessageRepository import com.wire.kalium.logic.data.message.PersistMessageUseCase +import com.wire.kalium.logic.data.message.hasValidData +import com.wire.kalium.logic.data.message.hasValidRemoteData import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.asset.ValidateAssetMimeTypeUseCase import com.wire.kalium.logic.functional.Either -import com.wire.kalium.logic.sync.receiver.conversation.message.hasValidData -import com.wire.kalium.logic.sync.receiver.conversation.message.hasValidRemoteData import com.wire.kalium.util.time.UNIX_FIRST_DATE import io.mockative.Mock import io.mockative.any