Skip to content

Commit

Permalink
Merge branch 'develop' into feat/epic-federation-offline-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina committed Apr 3, 2023
2 parents cea803a + 596b40b commit eac76fd
Show file tree
Hide file tree
Showing 114 changed files with 3,923 additions and 842 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ktor = "2.2.2"
okio = "3.2.0"
ok-http = "4.9.3"
mockative = "1.2.6"
android-work = "2.7.1"
android-work = "2.8.0"
android-test-runner = "1.5.0"
android-test-rules = "1.4.0"
android-test-core = "1.4.0"
Expand All @@ -32,7 +32,7 @@ sqldelight = "2.0.0-alpha04"
sqlcipher-android = "4.5.3"
pbandk = "0.14.2"
turbine = "0.12.1"
avs = "9.1.13"
avs = "9.1.20"
jna = "5.6.0"
core-crypto = "0.6.3"
core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ internal class AssetDataSource(
val tempFileSink = kaliumFileSystem.sink(tempFile)
wrapApiRequest {
// Backend sends asset messages with empty asset tokens
assetApi.downloadAsset(assetId, assetDomain, assetToken?.ifEmpty { null }, tempFileSink)
assetApi.downloadAsset(assetId, assetDomain, assetToken?.ifEmpty { null }, tempFileSink).also {
tempFileSink.close()
}
}.flatMap {
try {
if (encryptionKey != null && assetSHA256 == null) return@flatMap Either.Left(EncryptionFailure.WrongAssetHash)
Expand All @@ -244,6 +246,7 @@ internal class AssetDataSource(

// Delete temp path now that the decoded asset has been persisted correctly
kaliumFileSystem.delete(tempFile)
decodedAssetSink.close()

when {
// Either a decryption error or a hash error occurred
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ class ClientDataSource(
}

override suspend fun deleteClient(param: DeleteClientParam): Either<NetworkFailure, Unit> {
return clientRemoteRepository.deleteClient(param)
return clientRemoteRepository.deleteClient(param).onSuccess {
wrapStorageRequest { clientDAO.deleteClient(selfUserID.toDao(), param.clientId.value) }
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ package com.wire.kalium.logic.data.conversation
import com.wire.kalium.logic.data.id.IdMapper
import com.wire.kalium.logic.data.id.toDao
import com.wire.kalium.logic.data.id.toModel
import com.wire.kalium.network.api.base.model.UserId
import com.wire.kalium.network.api.base.authenticated.client.SimpleClientResponse
import com.wire.kalium.network.api.base.authenticated.conversation.ConversationMemberDTO
import com.wire.kalium.network.api.base.authenticated.conversation.ConversationMembersResponse
import com.wire.kalium.network.api.base.model.UserId
import com.wire.kalium.persistence.dao.QualifiedIDEntity
import com.wire.kalium.persistence.dao.client.Client
import com.wire.kalium.logic.data.user.UserId as LogicUserId
import com.wire.kalium.persistence.dao.Member as PersistedMember

interface MemberMapper {
fun fromApiModel(conversationMember: ConversationMemberDTO.Other): Conversation.Member
fun fromApiModel(conversationMembersResponse: ConversationMembersResponse): MembersInfo
fun fromMapOfClientsResponseToRecipients(qualifiedMap: Map<UserId, List<SimpleClientResponse>>): List<Recipient>
fun fromMapOfClientsEntityToRecipients(qualifiedMap: Map<QualifiedIDEntity, List<Client>>): List<Recipient>
fun fromMapOfClientsToRecipients(qualifiedMap: Map<LogicUserId, List<Client>>): List<Recipient>
fun fromApiModelToDaoModel(conversationMembersResponse: ConversationMembersResponse): List<PersistedMember>
fun fromDaoModel(entity: PersistedMember): Conversation.Member
fun toDaoModel(member: Conversation.Member): PersistedMember
Expand Down Expand Up @@ -84,13 +82,6 @@ internal class MemberMapperImpl(private val idMapper: IdMapper, private val role
Recipient(id, clients)
}

override fun fromMapOfClientsToRecipients(qualifiedMap: Map<LogicUserId, List<Client>>): List<Recipient> =
qualifiedMap.entries.map { entry ->
val id = entry.key
val clients = entry.value.map(idMapper::fromClient)
Recipient(id, clients)
}

override fun fromDaoModel(entity: PersistedMember): Conversation.Member = with(entity) {
Conversation.Member(user.toModel(), roleMapper.fromDAO(role))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Wire
* Copyright (C) 2023 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.message

import com.wire.kalium.logger.obfuscateId
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.util.serialization.toJsonElement

data class BroadcastMessage(
val id: String,
val content: MessageContent.Signaling,
val date: String,
val senderUserId: UserId,
val status: Message.Status,
val isSelfMessage: Boolean,
val senderClientId: ClientId,
) {

@Suppress("LongMethod")
fun toLogString(): String {
val typeKey = "type"

val properties: MutableMap<String, Any> = when (content) {
is MessageContent.TextEdited -> mutableMapOf(
typeKey to "textEdit"
)

is MessageContent.Calling -> mutableMapOf(
typeKey to "calling"
)

is MessageContent.ClientAction -> mutableMapOf(
typeKey to "clientAction"
)

is MessageContent.DeleteMessage -> mutableMapOf(
typeKey to "delete"
)

is MessageContent.DeleteForMe -> mutableMapOf(
typeKey to "deleteForMe",
"messageId" to content.messageId.obfuscateId(),
)

is MessageContent.LastRead -> mutableMapOf(
typeKey to "lastRead",
"time" to "${content.time}",
)

is MessageContent.Availability -> mutableMapOf(
typeKey to "availability",
"content" to "$content",
)

is MessageContent.Cleared -> mutableMapOf(
typeKey to "cleared",
"content" to "$content",
)

is MessageContent.Reaction -> mutableMapOf(
typeKey to "reaction",
"content" to "$content",
)

is MessageContent.Receipt -> mutableMapOf(
typeKey to "receipt",
"content" to content.toLogMap(),
)

MessageContent.Ignored -> mutableMapOf(
typeKey to "ignored",
"content" to "$content",
)
}

val standardProperties = mapOf(
"id" to id.obfuscateId(),
"date" to date,
"senderUserId" to senderUserId.value.obfuscateId(),
"status" to "$status",
"senderClientId" to senderClientId.value.obfuscateId(),
)

properties.putAll(standardProperties)

return "${properties.toMap().toJsonElement()}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ package com.wire.kalium.logic.data.message

import com.wire.kalium.logger.obfuscateDomain
import com.wire.kalium.logger.obfuscateId
import com.wire.kalium.util.serialization.toJsonElement
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.util.serialization.toJsonElement
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlin.time.Duration

@Suppress("LongParameterList")
sealed interface Message {
Expand Down Expand Up @@ -75,10 +78,12 @@ sealed interface Message {
override val isSelfMessage: Boolean,
override val senderClientId: ClientId,
val editStatus: EditStatus,
val expirationData: ExpirationData? = null,
val reactions: Reactions = Reactions.EMPTY,
val expectsReadConfirmation: Boolean = false,
val deliveryStatus: DeliveryStatus = DeliveryStatus.CompleteDelivery
) : Sendable, Standalone {

@Suppress("LongMethod")
override fun toLogString(): String {
val typeKey = "type"
Expand Down Expand Up @@ -318,6 +323,33 @@ sealed interface Message {
}
}

data class ExpirationData(val expireAfter: Duration, val selfDeletionStatus: SelfDeletionStatus = SelfDeletionStatus.NotStarted) {

sealed class SelfDeletionStatus {
object NotStarted : SelfDeletionStatus()

data class Started(val selfDeletionStartDate: Instant) : SelfDeletionStatus()
}

fun timeLeftForDeletion(): Duration {
return if (selfDeletionStatus is SelfDeletionStatus.Started) {
val timeElapsedSinceSelfDeletionStartDate = Clock.System.now() - selfDeletionStatus.selfDeletionStartDate

// time left for deletion it can be a negative value if the time difference between the self deletion start date and
// now is greater then expire after millis, we normalize it to 0 seconds
val timeLeft = expireAfter - timeElapsedSinceSelfDeletionStartDate

if (timeLeft.isNegative()) {
Duration.ZERO
} else {
timeLeft
}
} else {
expireAfter
}
}
}

enum class UploadStatus {
/**
* There was no attempt done to upload the asset's data to remote (server) storage.
Expand Down Expand Up @@ -410,8 +442,7 @@ enum class AssetType {
IMAGE,
VIDEO,
AUDIO,
ASSET,
FILE
GENERIC_ASSET
}

typealias ReactionsCount = Map<String, Int>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ sealed class MessageContent {
* @see ProtoContentMapper
*/
sealed class FromProto : MessageContent()

/**
* Main content of messages created by users/bot,
* It's expected that this content will form the
Expand Down
Loading

0 comments on commit eac76fd

Please sign in to comment.