Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adopt v7 API #WPB-11975 #3099

Merged
merged 10 commits into from
Nov 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,16 @@ sealed class Event(open val id: String) {
val uri: String?,
val isPasswordProtected: Boolean,
) : Conversation(id, conversationId) {
override fun toLogMap(): Map<String, Any?> = mapOf(typeKey to "Conversation.CodeUpdated")
override fun toLogMap(): Map<String, Any?> =
mapOf(typeKey to "Conversation.CodeUpdated")
}

data class CodeDeleted(
override val id: String,
override val conversationId: ConversationId,
) : Conversation(id, conversationId) {
override fun toLogMap(): Map<String, Any?> = mapOf(typeKey to "Conversation.CodeDeleted")
override fun toLogMap(): Map<String, Any?> =
mapOf(typeKey to "Conversation.CodeDeleted")
}

data class TypingIndicator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ internal class NewConversationEventHandlerImpl(
.flatMap { isNewUnhandledConversation ->
resolveConversationIfOneOnOne(selfUserTeamId, event)
.flatMap {
conversationRepository.updateConversationModifiedDate(event.conversationId, DateTimeUtil.currentInstant())
conversationRepository.updateConversationModifiedDate(
event.conversationId,
DateTimeUtil.currentInstant()
)
}
.flatMap {
userRepository.fetchUsersIfUnknownByIds(event.conversation.members.otherMembers.map { it.id.toModel() }.toSet())
userRepository.fetchUsersIfUnknownByIds(
event.conversation.members.otherMembers.map {
it.id.toModel()
}.toSet()
)
}
.map { isNewUnhandledConversation }
}.onSuccess { isNewUnhandledConversation ->
Expand All @@ -73,9 +80,13 @@ internal class NewConversationEventHandlerImpl(
}
}

private suspend fun resolveConversationIfOneOnOne(selfUserTeamId: TeamId?, event: Event.Conversation.NewConversation) =
private suspend fun resolveConversationIfOneOnOne(
selfUserTeamId: TeamId?,
event: Event.Conversation.NewConversation
) =
if (event.conversation.toConversationType(selfUserTeamId) == ConversationEntity.Type.ONE_ON_ONE) {
val otherUserId = event.conversation.members.otherMembers.first().id.toModel()
val otherUserId =
event.conversation.members.otherMembers.first().id.toModel()
oneOnOneResolver.resolveOneOnOneConversationWithUserId(
userId = otherUserId,
invalidateCurrentKnownProtocols = true
Expand All @@ -94,13 +105,20 @@ internal class NewConversationEventHandlerImpl(
event: Event.Conversation.NewConversation
) {
if (isNewUnhandledConversation) {
newGroupConversationSystemMessagesCreator.conversationStarted(event.senderUserId, event.conversation, event.dateTime)
newGroupConversationSystemMessagesCreator.conversationStarted(
event.senderUserId,
event.conversation,
event.dateTime
)
newGroupConversationSystemMessagesCreator.conversationResolvedMembersAdded(
event.conversationId.toDao(),
event.conversation.members.otherMembers.map { it.id.toModel() },
event.dateTime
)
newGroupConversationSystemMessagesCreator.conversationReadReceiptStatus(event.conversation, event.dateTime)
newGroupConversationSystemMessagesCreator.conversationReadReceiptStatus(
event.conversation,
event.dateTime
)
newGroupConversationSystemMessagesCreator.conversationStartedUnverifiedWarning(
event.conversation.id.toModel(),
event.dateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import com.wire.kalium.logic.framework.TestEvent
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.util.shouldFail
import com.wire.kalium.logic.util.shouldSucceed
import com.wire.kalium.network.api.base.authenticated.client.ClientApi
import com.wire.kalium.network.api.authenticated.client.ClientDTO
import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO
import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO
import com.wire.kalium.network.api.authenticated.client.SimpleClientResponse
import com.wire.kalium.network.api.base.authenticated.client.ClientApi
import com.wire.kalium.network.api.model.ErrorResponse
import com.wire.kalium.network.exceptions.KaliumException
import com.wire.kalium.network.utils.NetworkResponse
Expand Down Expand Up @@ -257,7 +257,7 @@ class ClientRepositoryTest {
deviceType = DeviceTypeDTO.Desktop,
label = null,
model = "Mac ox",
capabilities = null,
capabilities = listOf(),
mlsPublicKeys = null,
cookie = null
),
Expand All @@ -269,7 +269,7 @@ class ClientRepositoryTest {
deviceType = DeviceTypeDTO.Phone,
label = null,
model = "iphone 15",
capabilities = null,
capabilities = listOf(),
mlsPublicKeys = null,
cookie = null
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,33 @@

package com.wire.kalium.mocks.responses

import com.wire.kalium.network.api.authenticated.client.Capabilities
import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO
import com.wire.kalium.network.api.authenticated.client.ClientDTO
import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO
import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO

object ClientResponseJson {
private val jsonProvider = { serializable: ClientDTO ->
"""
|{
| "id": "${serializable.clientId}",
| "type": "${serializable.type}",
| "time": "${serializable.registrationTime}",
| "last_active": "${serializable.lastActive}",
| "class": "${serializable.deviceType}",
| "label": "${serializable.label}",
| "cookie": "${serializable.cookie}",
| "model": "${serializable.model}",
| "capabilities": [
| "${serializable.capabilities[0]}"
| ],
| "mls_public_keys": ${serializable.mlsPublicKeys}
|}
""".trimMargin()
}

// This is backwards compatible with the old format till v5 API get deprecated
private val jsonProviderCapabilitiesObject = { serializable: ClientDTO ->
"""
|{
| "id": "${serializable.clientId}",
Expand All @@ -38,13 +57,30 @@ object ClientResponseJson {
| "model": "${serializable.model}",
| "capabilities": {
| "capabilities": [
| "${serializable.capabilities!!.capabilities[0]}"
| "${serializable.capabilities[0]}"
| ]
| }
| "mls_public_keys": ${serializable.mlsPublicKeys}
|}
""".trimMargin()
}

val validCapabilitiesObject = ValidJsonProvider(
ClientDTO(
clientId = "defkrr8e7grgsoufhg8",
type = ClientTypeDTO.Permanent,
deviceType = DeviceTypeDTO.Phone,
registrationTime = "2021-05-12T10:52:02.671Z",
lastActive = "2021-05-12T10:52:02.671Z",
label = "label",
cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd",
capabilities = listOf(ClientCapabilityDTO.LegalHoldImplicitConsent),
model = "model",
mlsPublicKeys = null
),
jsonProviderCapabilitiesObject
)

val valid = ValidJsonProvider(
ClientDTO(
clientId = "defkrr8e7grgsoufhg8",
Expand All @@ -54,7 +90,7 @@ object ClientResponseJson {
lastActive = "2021-05-12T10:52:02.671Z",
label = "label",
cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd",
capabilities = Capabilities(listOf(ClientCapabilityDTO.LegalHoldImplicitConsent)),
capabilities = listOf(ClientCapabilityDTO.LegalHoldImplicitConsent),
model = "model",
mlsPublicKeys = null
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.wire.kalium.mocks.responses

import com.wire.kalium.network.api.authenticated.client.Capabilities
import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO
import com.wire.kalium.network.api.authenticated.client.ClientDTO
import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO
Expand All @@ -38,7 +37,7 @@ object ListOfClientsResponseJson {
| "model": "${serializable.model}",
| "capabilities": {
| "capabilities": [
| "${serializable.capabilities!!.capabilities[0]}"
| "${serializable.capabilities[0]}"
| ]
| }
|}]
Expand All @@ -54,7 +53,7 @@ object ListOfClientsResponseJson {
lastActive = "2023-05-12T10:52:02.671Z",
label = "label",
cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd",
capabilities = Capabilities(listOf(ClientCapabilityDTO.LegalHoldImplicitConsent)),
capabilities = listOf(ClientCapabilityDTO.LegalHoldImplicitConsent),
model = "model",
mlsPublicKeys = null
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object NotificationEventsResponseJson {
type = ClientTypeDTO.Permanent,
deviceType = DeviceTypeDTO.Desktop,
label = "OS X 10.15 10.15",
capabilities = null,
capabilities = listOf(),
mlsPublicKeys = mapOf(Pair("key_variant", "public_key")),
)
),
Expand Down Expand Up @@ -157,7 +157,7 @@ object NotificationEventsResponseJson {
| "id" : "${eventData.qualifiedFrom.value}",
| "domain" : "${eventData.qualifiedFrom.domain}"
| },
| "data" : ${ConversationResponseJson.conversationResponseSerializer(eventData.data)},
| "data" : ${ConversationResponseJson.conversationResponseSerializerV3(eventData.data)},
| "time" : "2022-04-12T13:57:02.414Z",
| "type" : "conversation.create"
|}
Expand Down
Loading
Loading