Skip to content

Commit 3f172f6

Browse files
authored
feat: protocol v12 support, asset upload parameters (WPB-20296) (#3656)
* feat: protocol v12 support, asset upload parameters (WPB-20296) * feat: protocol v12 support, add api 12 to dev mode (WPB-20296)
1 parent 83856b3 commit 3f172f6

37 files changed

+1095
-14
lines changed

network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/asset/AssetMetadataRequest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
package com.wire.kalium.network.api.authenticated.asset
2020

2121
import com.wire.kalium.network.api.model.AssetRetentionType
22+
import com.wire.kalium.network.api.model.ConversationId
2223

24+
@Suppress("LongParameterList")
2325
class AssetMetadataRequest(
2426
val mimeType: String,
2527
val public: Boolean,
2628
val retentionType: AssetRetentionType,
27-
val md5: String
29+
val md5: String,
30+
val conversationId: ConversationId? = null,
31+
val filename: String? = null,
32+
val filetype: String? = null,
2833
)

network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ val SupportedApiVersions: Set<Int> = setOf(0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11)
2828

2929
// They are not truly constants as set is not a primitive type, yet are treated as one in this context
3030
@Suppress("MagicNumber")
31-
val DevelopmentApiVersions: Set<Int> = setOf()
31+
val DevelopmentApiVersions: Set<Int> = setOf(12)
3232

3333
// You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to
3434
// bump API version and generate all needed classes

network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/AssetApiV0.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
package com.wire.kalium.network.api.v0.authenticated
2020

2121
import com.wire.kalium.network.AuthenticatedNetworkClient
22-
import com.wire.kalium.network.api.base.authenticated.asset.AssetApi
2322
import com.wire.kalium.network.api.authenticated.asset.AssetMetadataRequest
2423
import com.wire.kalium.network.api.authenticated.asset.AssetResponse
24+
import com.wire.kalium.network.api.base.authenticated.asset.AssetApi
2525
import com.wire.kalium.network.exceptions.KaliumException
2626
import com.wire.kalium.network.kaliumLogger
2727
import com.wire.kalium.network.utils.NetworkResponse
@@ -127,6 +127,11 @@ internal open class AssetApiV0 internal constructor(
127127
"$PATH_PUBLIC_ASSETS_V4/$assetDomain/$assetId"
128128
}
129129

130+
protected open fun buildUploadMetaData(metadata: AssetMetadataRequest) = "{" +
131+
"\"public\": ${metadata.public}, " +
132+
"\"retention\": \"${metadata.retentionType.name.lowercase()}\"" +
133+
"}"
134+
130135
override suspend fun uploadAsset(
131136
metadata: AssetMetadataRequest,
132137
encryptedDataSource: () -> Source,
@@ -135,7 +140,14 @@ internal open class AssetApiV0 internal constructor(
135140
wrapKaliumResponse {
136141
httpClient.post(PATH_PUBLIC_ASSETS_V3) {
137142
contentType(ContentType.MultiPart.Mixed)
138-
setBody(StreamAssetContent(metadata, encryptedDataSize, encryptedDataSource))
143+
setBody(
144+
StreamAssetContent(
145+
metadata = buildUploadMetaData(metadata),
146+
md5 = metadata.md5,
147+
encryptedDataSize = encryptedDataSize,
148+
fileContentStream = encryptedDataSource
149+
)
150+
)
139151
}
140152
}
141153

@@ -154,22 +166,20 @@ internal open class AssetApiV0 internal constructor(
154166
}
155167

156168
internal class StreamAssetContent internal constructor(
157-
private val metadata: AssetMetadataRequest,
169+
private val metadata: String,
170+
private val md5: String,
158171
private val encryptedDataSize: Long,
159172
private val fileContentStream: () -> Source,
160173
) : OutgoingContent.WriteChannelContent() {
161174
private val openingData: String by lazy {
162175
val body = StringBuilder()
163176

164-
// Part 1
165-
val strMetadata = "{\"public\": ${metadata.public}, \"retention\": \"${metadata.retentionType.name.lowercase()}\"}"
166-
167177
body.append("--frontier\r\n")
168178
body.append("Content-Type: application/json;charset=utf-8\r\n")
169179
body.append("Content-Length: ")
170-
.append(strMetadata.length)
180+
.append(metadata.length)
171181
.append("\r\n\r\n")
172-
body.append(strMetadata)
182+
body.append(metadata)
173183
.append("\r\n")
174184

175185
// Part 2
@@ -180,7 +190,7 @@ internal class StreamAssetContent internal constructor(
180190
.append(encryptedDataSize)
181191
.append("\r\n")
182192
body.append("Content-MD5: ")
183-
.append(metadata.md5)
193+
.append(md5)
184194
.append("\r\n\r\n")
185195

186196
body.toString()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
package com.wire.kalium.network.api.v12.authenticated
20+
21+
import com.wire.kalium.network.api.v11.authenticated.AccessTokenApiV11
22+
import io.ktor.client.HttpClient
23+
24+
internal open class AccessTokenApiV12 internal constructor(
25+
httpClient: HttpClient
26+
) : AccessTokenApiV11(httpClient)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
package com.wire.kalium.network.api.v12.authenticated
20+
21+
import com.wire.kalium.network.AuthenticatedNetworkClient
22+
import com.wire.kalium.network.api.authenticated.asset.AssetMetadataRequest
23+
import com.wire.kalium.network.api.model.UserId
24+
import com.wire.kalium.network.api.v11.authenticated.AssetApiV11
25+
26+
internal open class AssetApiV12 internal constructor(
27+
authenticatedNetworkClient: AuthenticatedNetworkClient,
28+
selfUserId: UserId
29+
) : AssetApiV11(authenticatedNetworkClient, selfUserId) {
30+
31+
override fun buildUploadMetaData(metadata: AssetMetadataRequest): String {
32+
33+
val params = buildList {
34+
add("\"public\": ${metadata.public}")
35+
add("\"retention\": \"${metadata.retentionType.name.lowercase()}\"")
36+
metadata.conversationId?.let {
37+
add("\"convId\": {\"id\": \"${it.value}\", \"domain\": \"${it.domain}\"}")
38+
}
39+
metadata.filename?.let {
40+
add("\"filename\": \"$it\"")
41+
}
42+
metadata.filetype?.let {
43+
add("\"filetype\": \"$it\"")
44+
}
45+
}
46+
47+
return "{${params.joinToString(",")}}"
48+
}
49+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
package com.wire.kalium.network.api.v12.authenticated
20+
21+
import com.wire.kalium.network.AuthenticatedNetworkClient
22+
import com.wire.kalium.network.api.v11.authenticated.CallApiV11
23+
24+
internal open class CallApiV12 internal constructor(
25+
authenticatedNetworkClient: AuthenticatedNetworkClient
26+
) : CallApiV11(authenticatedNetworkClient)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
package com.wire.kalium.network.api.v12.authenticated
20+
21+
import com.wire.kalium.network.AuthenticatedNetworkClient
22+
import com.wire.kalium.network.api.v11.authenticated.ClientApiV11
23+
24+
internal open class ClientApiV12 internal constructor(authenticatedNetworkClient: AuthenticatedNetworkClient) :
25+
ClientApiV11(authenticatedNetworkClient)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
package com.wire.kalium.network.api.v12.authenticated
20+
21+
import com.wire.kalium.network.AuthenticatedNetworkClient
22+
import com.wire.kalium.network.api.v11.authenticated.ConnectionApiV11
23+
24+
internal open class ConnectionApiV12 internal constructor(
25+
authenticatedNetworkClient: AuthenticatedNetworkClient
26+
) : ConnectionApiV11(authenticatedNetworkClient)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
package com.wire.kalium.network.api.v12.authenticated
20+
21+
import com.wire.kalium.network.AuthenticatedNetworkClient
22+
import com.wire.kalium.network.api.v11.authenticated.ConversationApiV11
23+
24+
internal open class ConversationApiV12 internal constructor(
25+
authenticatedNetworkClient: AuthenticatedNetworkClient
26+
) : ConversationApiV11(authenticatedNetworkClient)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
package com.wire.kalium.network.api.v12.authenticated
20+
21+
import com.wire.kalium.network.AuthenticatedNetworkClient
22+
import com.wire.kalium.network.api.v11.authenticated.ConversationHistoryApiV11
23+
24+
internal open class ConversationHistoryApiV12 internal constructor(networkClient: AuthenticatedNetworkClient) :
25+
ConversationHistoryApiV11(networkClient)

0 commit comments

Comments
 (0)