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

refactor(backup): visibility modifier [WPB-10575] #3153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ kaliumLibrary {

@Suppress("UnusedPrivateProperty")
kotlin {
// Makes visibility modifiers mandatory
// Useful for a library that will be called by other clients
// This way we need to think before putting "public" in things, and we can be reminded by the compiler to use "internal" more often
explicitApi()
val xcf = XCFramework()
val appleTargets = listOf(iosX64(), iosArm64(), iosSimulatorArm64(), macosArm64(), macosX64())
appleTargets.forEach {
Expand Down
4 changes: 2 additions & 2 deletions backup/src/commonMain/kotlin/com/wire/backup/MPBackup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ package com.wire.backup
import kotlin.js.JsExport

@JsExport
object MPBackup {
const val ZIP_ENTRY_DATA = "data.wmbu"
public object MPBackup {
public const val ZIP_ENTRY_DATA: String = "data.wmbu"
}
56 changes: 28 additions & 28 deletions backup/src/commonMain/kotlin/com/wire/backup/data/BackupData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,39 @@ import kotlin.native.ObjCName
import kotlin.native.ShouldRefineInSwift

@JsExport
class BackupData(
val metadata: BackupMetadata,
public class BackupData(
public val metadata: BackupMetadata,
@ShouldRefineInSwift
val users: Array<BackupUser>,
public val users: Array<BackupUser>,
@ShouldRefineInSwift
val conversations: Array<BackupConversation>,
public val conversations: Array<BackupConversation>,
@ShouldRefineInSwift
val messages: Array<BackupMessage>
public val messages: Array<BackupMessage>
) {
@ObjCName("users")
val userList: List<BackupUser> get() = users.toList()
public val userList: List<BackupUser> get() = users.toList()

@ObjCName("conversations")
val conversationList: List<BackupConversation> get() = conversations.toList()
public val conversationList: List<BackupConversation> get() = conversations.toList()

@ObjCName("messages")
val messageList: List<BackupMessage> get() = messages.toList()
public val messageList: List<BackupMessage> get() = messages.toList()
}

@JsExport
@Serializable
data class BackupQualifiedId(
public data class BackupQualifiedId(
@SerialName("id")
val id: String,
@SerialName("domain")
val domain: String,
) {
override fun toString() = "$id@$domain"
override fun toString(): String = "$id@$domain"

companion object {
public companion object {
private const val QUALIFIED_ID_COMPONENT_COUNT = 2

fun fromEncodedString(id: String): BackupQualifiedId? {
public fun fromEncodedString(id: String): BackupQualifiedId? {
val components = id.split("@")
if (components.size != QUALIFIED_ID_COMPONENT_COUNT) return null
return BackupQualifiedId(components[0], components[1])
Expand All @@ -69,20 +69,20 @@ data class BackupQualifiedId(
}

@JsExport
data class BackupUser(
public data class BackupUser(
val id: BackupQualifiedId,
val name: String,
val handle: String,
)

@JsExport
data class BackupConversation(
public data class BackupConversation(
val id: BackupQualifiedId,
val name: String,
)

@JsExport
data class BackupMessage(
public data class BackupMessage(
val id: String,
val conversationId: BackupQualifiedId,
val senderUserId: BackupQualifiedId,
Expand All @@ -93,16 +93,16 @@ data class BackupMessage(
val webPrimaryKey: Int? = null,
)

expect class BackupDateTime
public expect class BackupDateTime

expect fun BackupDateTime(timestampMillis: Long): BackupDateTime
expect fun BackupDateTime.toLongMilliseconds(): Long
public expect fun BackupDateTime(timestampMillis: Long): BackupDateTime
public expect fun BackupDateTime.toLongMilliseconds(): Long

@JsExport
sealed class BackupMessageContent {
data class Text(val text: String) : BackupMessageContent()
public sealed class BackupMessageContent {
public data class Text(val text: String) : BackupMessageContent()

data class Asset(
public data class Asset(
val mimeType: String,
val size: Int,
val name: String?,
Expand All @@ -114,29 +114,29 @@ sealed class BackupMessageContent {
val encryption: EncryptionAlgorithm?,
val metaData: AssetMetadata?,
) : BackupMessageContent() {
enum class EncryptionAlgorithm {
public enum class EncryptionAlgorithm {
AES_GCM, AES_CBC
}

sealed class AssetMetadata {
data class Image(
public sealed class AssetMetadata {
public data class Image(
val width: Int,
val height: Int,
val tag: String?
) : AssetMetadata()

data class Video(
public data class Video(
val width: Int?,
val height: Int?,
val duration: Long?,
) : AssetMetadata()

data class Audio(
public data class Audio(
val normalization: ByteArray?,
val duration: Long?,
) : AssetMetadata()

data class Generic(
public data class Generic(
val name: String?,
) : AssetMetadata()
}
Expand Down Expand Up @@ -170,7 +170,7 @@ sealed class BackupMessageContent {
}
}

data class Location(
public data class Location(
val longitude: Float,
val latitude: Float,
val name: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package com.wire.backup.data
import kotlin.js.JsExport

@JsExport
data class BackupMetadata(
public data class BackupMetadata(
val version: String,
val userId: BackupQualifiedId,
val creationTime: BackupDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import kotlin.native.ShouldRefineInSwift
*/
@OptIn(ExperimentalObjCName::class, ExperimentalObjCRefinement::class)
@JsExport
abstract class CommonMPBackupExporter(
public abstract class CommonMPBackupExporter(
private val selfUserId: BackupQualifiedId
) {
private val mapper = MPBackupMapper()
Expand All @@ -51,23 +51,23 @@ abstract class CommonMPBackupExporter(
// Unfortunately the IDE doesn't understand this right now and
// keeps complaining if making the other way around
@ObjCName("add")
fun addUser(user: BackupUser) {
public fun addUser(user: BackupUser) {
allUsers.add(user)
}

@ObjCName("add")
fun addConversation(conversation: BackupConversation) {
public fun addConversation(conversation: BackupConversation) {
allConversations.add(conversation)
}

@ObjCName("add")
fun addMessage(message: BackupMessage) {
public fun addMessage(message: BackupMessage) {
allMessages.add(message)
}

@OptIn(ExperimentalStdlibApi::class)
@ShouldRefineInSwift // Hidden in Swift
fun serialize(): ByteArray {
public fun serialize(): ByteArray {
val backupData = BackupData(
BackupInfo(
platform = "Common",
Expand All @@ -92,4 +92,4 @@ abstract class CommonMPBackupExporter(
}
}

expect class MPBackupExporter : CommonMPBackupExporter
public expect class MPBackupExporter : CommonMPBackupExporter
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.wire.backup.data.BackupData
import kotlin.js.JsExport

@JsExport
sealed class BackupImportResult {
data object ParsingFailure : BackupImportResult()
data class Success(val backupData: BackupData) : BackupImportResult()
public sealed class BackupImportResult {
public data object ParsingFailure : BackupImportResult()
public data class Success(val backupData: BackupData) : BackupImportResult()
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import kotlin.native.ShouldRefineInSwift
*/
@OptIn(ExperimentalObjCRefinement::class)
@JsExport
abstract class CommonMPBackupImporter {
public abstract class CommonMPBackupImporter {
private val mapper = MPBackupMapper()

/**
Expand All @@ -39,7 +39,7 @@ abstract class CommonMPBackupImporter {
@OptIn(ExperimentalStdlibApi::class)
@ShouldRefineInSwift // Function not visible in Swift
@Suppress("TooGenericExceptionCaught")
fun importBackup(data: ByteArray): BackupImportResult = try {
public fun importBackup(data: ByteArray): BackupImportResult = try {
println("XPlatform Backup POC. Imported data bytes: ${data.toHexString()}")
BackupImportResult.Success(
mapper.fromProtoToBackupModel(ProtoBackupData.decodeFromByteArray(data))
Expand All @@ -51,4 +51,4 @@ abstract class CommonMPBackupImporter {
}
}

expect class MPBackupImporter : CommonMPBackupImporter
public expect class MPBackupImporter : CommonMPBackupImporter
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package com.wire.backup.data
import kotlin.js.Date

@JsExport
actual data class BackupDateTime(val date: Date) {
public actual data class BackupDateTime(val date: Date) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class.js != other::class.js) return false
Expand All @@ -35,10 +35,10 @@ actual data class BackupDateTime(val date: Date) {
}
}

actual fun BackupDateTime(timestampMillis: Long): BackupDateTime {
public actual fun BackupDateTime(timestampMillis: Long): BackupDateTime {
return BackupDateTime(Date(timestampMillis))
}

actual fun BackupDateTime.toLongMilliseconds(): Long {
public actual fun BackupDateTime.toLongMilliseconds(): Long {
return date.getTime().toLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ import com.wire.backup.data.BackupQualifiedId

// JS uses the common one. Only handles Bytes / ByteArrays.
@JsExport
actual class MPBackupExporter(selfUserId: BackupQualifiedId) : CommonMPBackupExporter(selfUserId)
public actual class MPBackupExporter(selfUserId: BackupQualifiedId) : CommonMPBackupExporter(selfUserId)
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
package com.wire.backup.ingest

@JsExport
actual class MPBackupImporter : CommonMPBackupImporter()
public actual class MPBackupImporter : CommonMPBackupImporter()
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package com.wire.backup.data

import kotlinx.datetime.Instant

actual data class BackupDateTime(val instant: Instant)
public actual data class BackupDateTime(val instant: Instant)

actual fun BackupDateTime(timestampMillis: Long): BackupDateTime {
public actual fun BackupDateTime(timestampMillis: Long): BackupDateTime {
return BackupDateTime(Instant.fromEpochMilliseconds(timestampMillis))
}

actual fun BackupDateTime.toLongMilliseconds(): Long {
public actual fun BackupDateTime.toLongMilliseconds(): Long {
return this.instant.toEpochMilliseconds()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ package com.wire.backup.dump

import com.wire.backup.data.BackupQualifiedId

actual class MPBackupExporter(selfUserId: BackupQualifiedId) : CommonMPBackupExporter(selfUserId)
public actual class MPBackupExporter(selfUserId: BackupQualifiedId) : CommonMPBackupExporter(selfUserId)
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import kotlin.experimental.ExperimentalObjCName
import kotlin.native.ObjCName

@OptIn(ExperimentalObjCName::class)
actual class MPBackupImporter : CommonMPBackupImporter() {
public actual class MPBackupImporter : CommonMPBackupImporter() {

/**
* Imports a backup from the specified root path.
*
* @param multiplatformBackupFilePath the path to the decrypted, unzipped backup data file
*/
@ObjCName("importFile")
fun importFromFile(multiplatformBackupFilePath: String): BackupImportResult {
public fun importFromFile(multiplatformBackupFilePath: String): BackupImportResult {
return FileSystem.SYSTEM.read(multiplatformBackupFilePath.toPath()) {
importBackup(readByteArray())
}
Expand Down
Loading