Skip to content

Commit

Permalink
feat: Get and save clients mlsPublicKeys (WPB-2308) (#1932)
Browse files Browse the repository at this point in the history
* feat: receive and store composite messages [part-1] (#1888)

* receive composite messages

* map composite to proto

* detekt

* detekt

* db migration

* db migration

* sqm

* map to composite entity

* detekt

* remove is pending state from the DB

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* address PR comments

* detekt

* remove composite message preview mapping

* fix migration

* merge issues

* address PR comments

* address PR comments

* detekt

---------

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* feat: use case to send Message Button Action [part-2] (#1896)

* receive composite messages

* map composite to proto

* detekt

* detekt

* db migration

* db migration

* sqm

* map to composite entity

* detekt

* remove is pending state from the DB

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* address PR comments

* detekt

* remove composite message preview mapping

* fix migration

* feat: use case to execute composite message action

* expose use case to message scope

* missing param

* rename use case

* docs

* map to proto

* merge issues

* address PR comments

* address PR comments

* detekt

* sent the message only to the message original sender

* detekt

* Update logic/src/commonTest/kotlin/com/wire/kalium/logic/data/message/MessageMetaDataRepositoryTest.kt

Co-authored-by: Alexandre Ferris <[email protected]>

* PR comments

---------

Co-authored-by: Vitor Hugo Schwaab <[email protected]>
Co-authored-by: Alexandre Ferris <[email protected]>

* feat: handle composite action confermation message [part-3] (#1901)

* receive composite messages

* map composite to proto

* detekt

* detekt

* db migration

* db migration

* sqm

* map to composite entity

* detekt

* remove is pending state from the DB

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* address PR comments

* detekt

* remove composite message preview mapping

* fix migration

* feat: use case to execute composite message action

* expose use case to message scope

* missing param

* rename use case

* docs

* map to proto

* merge issues

* address PR comments

* address PR comments

* detekt

* handle ButtonActionConfirmation event

* add unit test

* detekt

* detekt

* sent the message only to the message original sender

* detekt

---------

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* feat: composite message preview [part-4] (#1908)

* receive composite messages

* map composite to proto

* detekt

* detekt

* db migration

* db migration

* sqm

* map to composite entity

* detekt

* remove is pending state from the DB

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt

Co-authored-by: Vitor Hugo Schwaab <[email protected]>

* address PR comments

* detekt

* remove composite message preview mapping

* fix migration

* feat: use case to execute composite message action

* expose use case to message scope

* missing param

* rename use case

* docs

* map to proto

* merge issues

* address PR comments

* address PR comments

* detekt

* handle ButtonActionConfirmation event

* add unit test

* detekt

* detekt

* sent the message only to the message original sender

* detekt

* feat: map composite messages preview

* Update persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt

Co-authored-by: Alexandre Ferris <[email protected]>

---------

Co-authored-by: Vitor Hugo Schwaab <[email protected]>
Co-authored-by: Alexandre Ferris <[email protected]>

* fix: composite messages are not included in the getLastMessages query [part-5] (#1909)

* include composite messages to message preview

* detekt

* feat: display composite message preview

* add test

* feat: composit messages backup [part-6] (#1914)

* fea: include message buttons into the backup

* import buttons

* merge issues

* unit test

* merge issues

* ignore Confirmation messages that are not fom the original message sender

* test

* cleanup

* detekt

* typo

* typo

* PR comments

* feat: Get and save clients mlsPublicKeys

* feat: Get and save clients mlsPublicKeys: code stly

* feat: Get and save clients mlsPublicKeys: tests fix

* feat: Get and save clients mlsPublicKeys: removed logs

---------

Co-authored-by: Mohamad Jaara <[email protected]>
Co-authored-by: Vitor Hugo Schwaab <[email protected]>
Co-authored-by: Alexandre Ferris <[email protected]>
  • Loading branch information
4 people authored Aug 3, 2023
1 parent e0f35c3 commit d2f94d3
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class ClientMapper(
label = client.label,
model = client.model,
isVerified = false,
isValid = true
isValid = true,
mlsPublicKeys = client.mlsPublicKeys
)

fun fromClientEntity(clientEntity: ClientEntity): Client = with(clientEntity) {
Expand All @@ -83,7 +84,8 @@ class ClientMapper(
label = label,
model = model,
isVerified = isVerified,
isValid = isValid
isValid = isValid,
mlsPublicKeys = mlsPublicKeys
)
}

Expand All @@ -97,7 +99,8 @@ class ClientMapper(
label = null,
model = model,
isVerified = false,
isValid = true
isValid = true,
mlsPublicKeys = null
)
}

Expand All @@ -112,7 +115,8 @@ class ClientMapper(
label = null,
model = null,
registrationDate = null,
lastActive = null
lastActive = null,
mlsPublicKeys = null
)
}
}
Expand All @@ -127,7 +131,8 @@ class ClientMapper(
label = label,
model = model,
registrationDate = Instant.parse(registrationTime),
lastActive = lastActive?.let { Instant.parse(it).coerceAtMost(Clock.System.now()) }
lastActive = lastActive?.let { Instant.parse(it).coerceAtMost(Clock.System.now()) },
mlsPublicKeys = mlsPublicKeys
)
}

Expand All @@ -141,7 +146,8 @@ class ClientMapper(
label = null,
model = null,
registrationDate = null,
lastActive = null
lastActive = null,
mlsPublicKeys = null
)
}

Expand All @@ -154,7 +160,8 @@ class ClientMapper(
label = event.client.label,
model = event.client.model,
registrationDate = event.client.registrationTime,
lastActive = event.client.lastActive
lastActive = event.client.lastActive,
mlsPublicKeys = null
)

private fun toClientTypeDTO(clientType: ClientType): ClientTypeDTO = when (clientType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ data class Client(
val isValid: Boolean,
val deviceType: DeviceType?,
val label: String?,
val model: String?
val model: String?,
val mlsPublicKeys: Map<String, String>?
)

enum class ClientType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ class ClientRepositoryTest {
label = null,
model = "Mac ox",
isVerified = false,
isValid = true
isValid = true,
mlsPublicKeys = null
),
Client(
id = PlainId(value = "client_id_2"),
Expand All @@ -297,7 +298,8 @@ class ClientRepositoryTest {
label = null,
model = "iphone 15",
isVerified = false,
isValid = true
isValid = true,
mlsPublicKeys = null
),
)

Expand Down Expand Up @@ -360,6 +362,7 @@ class ClientRepositoryTest {
isVerified = false,
isValid = true,
userId = userId,
mlsPublicKeys = null
)
)

Expand All @@ -373,7 +376,8 @@ class ClientRepositoryTest {
label = null,
model = null,
isVerified = false,
isValid = true
isValid = true,
mlsPublicKeys = null
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ class ConversationRepositoryTest {
null,
null,
null,
null,
null
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ object TestClient {
model = null,
label = "label",
isVerified = false,
isValid = true
isValid = true,
mlsPublicKeys = null
)

val SELF_USER_ID = UserId("self-user-id", "domain")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import com.wire.kalium.persistence.dao.QualifiedIDEntity;
import com.wire.kalium.persistence.dao.client.ClientTypeEntity;
import com.wire.kalium.persistence.dao.client.DeviceTypeEntity;
import kotlin.Boolean;
import kotlin.collections.Map;
import kotlinx.datetime.Instant;

CREATE TABLE Client (
Expand All @@ -15,6 +16,7 @@ CREATE TABLE Client (
label TEXT DEFAULT NULL,
model TEXT DEFAULT NULL,
last_active INTEGER AS Instant DEFAULT NULL,
mls_public_keys TEXT AS Map<String, String> DEFAULT NULL,
FOREIGN KEY (user_id) REFERENCES User(qualified_id) ON DELETE CASCADE,
PRIMARY KEY (user_id, id)
);
Expand All @@ -29,15 +31,16 @@ deleteClientsOfUser:
DELETE FROM Client WHERE user_id = ?;

insertClient:
INSERT INTO Client(user_id, id,device_type, client_type, is_valid, registration_date, label, model, last_active)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO Client(user_id, id, device_type, client_type, is_valid, registration_date, label, model, last_active, mls_public_keys)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id, user_id) DO UPDATE SET
device_type = coalesce(excluded.device_type, device_type),
registration_date = coalesce(excluded.registration_date, registration_date),
label = coalesce(excluded.label, label),
model = coalesce(excluded.model, model),
is_valid = is_valid,
last_active = coalesce(excluded.last_active, last_active);
last_active = coalesce(excluded.last_active, last_active),
mls_public_keys = excluded.mls_public_keys;

selectAllClients:
SELECT * FROM Client;
Expand Down
1 change: 1 addition & 0 deletions persistence/src/commonMain/db_user/migrations/52.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE Client ADD COLUMN mls_public_keys TEXT AS Map<String, String> DEFAULT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.persistence.adapter

import app.cash.sqldelight.ColumnAdapter

internal object MLSPublicKeysAdapter : ColumnAdapter<Map<String, String>, String> {
override fun decode(databaseValue: String): Map<String, String> =
if (databaseValue.isEmpty()) {
mapOf()
} else {
databaseValue.split(ITEMS_SEPARATOR).associate {
val components = it.split(KEY_VALUE_SEPARATOR)
components.first() to components.last()
}
}

override fun encode(value: Map<String, String>): String =
value.toList().joinToString(ITEMS_SEPARATOR) { "${it.first}$KEY_VALUE_SEPARATOR${it.second}" }

private const val ITEMS_SEPARATOR = ";"
private const val KEY_VALUE_SEPARATOR = ","
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data class Client(
val lastActive: Instant?,
val label: String?,
val model: String?,
val mlsPublicKeys: Map<String, String>?
)

data class InsertClientParam(
Expand All @@ -45,6 +46,7 @@ data class InsertClientParam(
val registrationDate: Instant?,
val lastActive: Instant?,
val model: String?,
val mlsPublicKeys: Map<String, String>?
)

enum class DeviceTypeEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ internal object ClientMapper {
registration_date: Instant?,
label: String?,
model: String?,
lastActive: Instant?
lastActive: Instant?,
mls_public_keys: Map<String, String>?
): Client = Client(
userId = user_id,
id = id,
Expand All @@ -53,7 +54,8 @@ internal object ClientMapper {
registrationDate = registration_date,
label = label,
model = model,
lastActive = lastActive
lastActive = lastActive,
mlsPublicKeys = mls_public_keys
)
}

Expand Down Expand Up @@ -83,7 +85,8 @@ internal class ClientDAOImpl internal constructor(
registration_date = registrationDate,
last_active = lastActive,
model = model,
label = label
label = label,
mls_public_keys = mlsPublicKeys
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.wire.kalium.persistence.adapter.ContentTypeAdapter
import com.wire.kalium.persistence.adapter.ConversationAccessListAdapter
import com.wire.kalium.persistence.adapter.ConversationAccessRoleListAdapter
import com.wire.kalium.persistence.adapter.InstantTypeAdapter
import com.wire.kalium.persistence.adapter.MLSPublicKeysAdapter
import com.wire.kalium.persistence.adapter.MemberRoleAdapter
import com.wire.kalium.persistence.adapter.QualifiedIDAdapter
import com.wire.kalium.persistence.adapter.QualifiedIDListAdapter
Expand All @@ -69,7 +70,8 @@ internal object TableMapper {
device_typeAdapter = EnumColumnAdapter(),
client_typeAdapter = EnumColumnAdapter(),
registration_dateAdapter = InstantTypeAdapter,
last_activeAdapter = InstantTypeAdapter
last_activeAdapter = InstantTypeAdapter,
mls_public_keysAdapter = MLSPublicKeysAdapter
)
val connectionAdapter = Connection.Adapter(
qualified_conversationAdapter = QualifiedIDAdapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class UserClientDAOIntegrationTest : BaseDatabaseTest() {
lastActive = null,
label = null,
clientType = null,
model = null
model = null,
mlsPublicKeys = null
)
val insertClientParam = InsertClientParam(
client.userId,
Expand All @@ -86,7 +87,8 @@ class UserClientDAOIntegrationTest : BaseDatabaseTest() {
client.label,
client.registrationDate,
client.lastActive,
client.model
client.model,
null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ class ClientDAOTest : BaseDatabaseTest() {
label = null,
model = null,
registrationDate = null,
lastActive = null
lastActive = null,
mlsPublicKeys = null
)
clientDAO.insertClient(insertedClient2)

Expand All @@ -338,7 +339,8 @@ class ClientDAOTest : BaseDatabaseTest() {
label = null,
model = null,
registrationDate = null,
lastActive = null
lastActive = null,
mlsPublicKeys = null
)
val client = insertedClient.toClient()

Expand Down Expand Up @@ -380,5 +382,6 @@ private fun InsertClientParam.toClient(): Client =
label = label,
model = model,
registrationDate = registrationDate,
lastActive = lastActive
lastActive = lastActive,
mlsPublicKeys = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class NewClientDAOTest: BaseDatabaseTest() {
label = null,
model = null,
registrationDate = null,
lastActive = null
lastActive = null,
mlsPublicKeys = null
)
val insertedClient1 = insertedClient.copy(user.id, "id1", deviceType = null)

Expand Down

0 comments on commit d2f94d3

Please sign in to comment.