Skip to content

Commit 300bf84

Browse files
feat: Add Conversation Type to Database #WPB-18243 (#140)
* feat: Add Conversation Type to Database #WPB-18243 * Add type field as string to Conversation.sq * Adjusted mappers and database to accommodate new field * Adjusted tests * Remove toString(type) as it was not being used * Change conversation.type.toString() to `.name` as its default from Enums
1 parent 446cf0c commit 300bf84

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

lib/src/main/kotlin/com/wire/integrations/jvm/model/ConversationData.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,36 @@
1616
package com.wire.integrations.jvm.model
1717

1818
import com.wire.crypto.MLSGroupId
19+
import com.wire.integrations.jvm.model.http.conversation.ConversationResponse
1920

2021
@JvmRecord
2122
data class ConversationData(
2223
val id: QualifiedId,
2324
val name: String?,
2425
val teamId: TeamId?,
25-
val mlsGroupId: MLSGroupId
26-
)
26+
val mlsGroupId: MLSGroupId,
27+
val type: Type
28+
) {
29+
enum class Type {
30+
GROUP,
31+
SELF,
32+
ONE_TO_ONE;
33+
34+
companion object {
35+
fun fromString(value: String): Type =
36+
when (value) {
37+
SELF.name -> SELF
38+
ONE_TO_ONE.name -> ONE_TO_ONE
39+
GROUP.name -> GROUP
40+
else -> GROUP
41+
}
42+
43+
fun fromApi(value: ConversationResponse.Type): Type =
44+
when (value) {
45+
ConversationResponse.Type.GROUP -> GROUP
46+
ConversationResponse.Type.SELF -> SELF
47+
ConversationResponse.Type.ONE_TO_ONE -> ONE_TO_ONE
48+
}
49+
}
50+
}
51+
}

lib/src/main/kotlin/com/wire/integrations/jvm/persistence/ConversationSqlLiteStorage.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ internal class ConversationSqlLiteStorage(db: AppsSdkDatabase) : ConversationSto
3939
domain = conversation.id.domain,
4040
name = conversation.name,
4141
mls_group_id = Base64.getEncoder().encodeToString(conversation.mlsGroupId.value),
42-
team_id = conversation.teamId?.value?.toString()
42+
team_id = conversation.teamId?.value?.toString(),
43+
type = conversation.type.name
4344
)
4445
}
4546

@@ -113,7 +114,8 @@ internal class ConversationSqlLiteStorage(db: AppsSdkDatabase) : ConversationSto
113114
id = QualifiedId(UUID.fromString(conv.id), conv.domain),
114115
name = conv.name,
115116
teamId = conv.team_id?.let { TeamId(UUID.fromString(it)) },
116-
mlsGroupId = MLSGroupId(Base64.getDecoder().decode(conv.mls_group_id))
117+
mlsGroupId = MLSGroupId(Base64.getDecoder().decode(conv.mls_group_id)),
118+
type = ConversationData.Type.fromString(value = conv.type)
117119
)
118120

119121
private fun conversationMemberMapper(member: Conversation_member) =

lib/src/main/kotlin/com/wire/integrations/jvm/service/EventsRouter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ internal class EventsRouter internal constructor(
201201
id = qualifiedConversation,
202202
name = conversationName,
203203
mlsGroupId = mlsGroupId,
204-
teamId = conversation.teamId?.let { TeamId(it) }
204+
teamId = conversation.teamId?.let { TeamId(it) },
205+
type = ConversationData.Type.fromApi(value = conversation.type)
205206
)
206207
val members = conversation.members.others.map {
207208
ConversationMember(

lib/src/main/sqldelight/com/wire/integrations/jvm/Conversation.sq

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS conversation (
55
team_id TEXT,
66
mls_group_id TEXT NOT NULL,
77
creation_date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
type TEXT NOT NULL,
89
PRIMARY KEY (id, domain)
910
);
1011

@@ -18,9 +19,9 @@ FROM conversation
1819
WHERE id = ? AND domain = ?;
1920

2021
insert:
21-
INSERT INTO conversation(id, domain, name, team_id, mls_group_id)
22-
VALUES (?, ?, ?, ?, ?)
23-
ON CONFLICT(id, domain) DO UPDATE SET name=excluded.name, team_id=excluded.team_id, mls_group_id=excluded.mls_group_id;
22+
INSERT INTO conversation(id, domain, name, team_id, mls_group_id, type)
23+
VALUES (?, ?, ?, ?, ?, ?)
24+
ON CONFLICT(id, domain) DO UPDATE SET name=excluded.name, team_id=excluded.team_id, mls_group_id=excluded.mls_group_id, type=excluded.type;
2425

2526
delete:
2627
DELETE FROM conversation

lib/src/test/kotlin/com/wire/integrations/jvm/service/WireEventsTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class WireEventsTest {
5252
id = CONVERSATION_ID,
5353
name = "Test conversation",
5454
teamId = null,
55-
mlsGroupId = MLSGroupId(ByteArray(32) { 1 })
55+
mlsGroupId = MLSGroupId(ByteArray(32) { 1 }),
56+
type = ConversationData.Type.GROUP
5657
),
5758
members = emptyList()
5859
)

0 commit comments

Comments
 (0)