mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
feat: add some base config migration logic, start implementing wrappers for conversation and expiry types
This commit is contained in:
parent
d01e27c671
commit
7733aec6fc
@ -1,7 +1,14 @@
|
||||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.content.Context
|
||||
import network.loki.messenger.libsession_util.Contacts
|
||||
import network.loki.messenger.libsession_util.UserProfile
|
||||
import network.loki.messenger.libsession_util.util.Contact
|
||||
import network.loki.messenger.libsession_util.util.UserPic
|
||||
import nl.komponents.kovenant.Promise
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
||||
import org.session.libsession.utilities.Address
|
||||
|
||||
object ConfigurationMessageUtilities {
|
||||
|
||||
@ -52,4 +59,59 @@ object ConfigurationMessageUtilities {
|
||||
// return promise
|
||||
}
|
||||
|
||||
private fun maybeUserSecretKey() = MessagingModuleConfiguration.shared.getUserED25519KeyPair()?.secretKey?.asBytes
|
||||
|
||||
fun generateUserProfileConfigDump(): ByteArray? {
|
||||
val config = ConfigurationMessage.getCurrent(listOf()) ?: return null
|
||||
val secretKey = maybeUserSecretKey() ?: return null
|
||||
val profile = UserProfile.newInstance(secretKey)
|
||||
profile.setName(config.displayName)
|
||||
val picUrl = config.profilePicture
|
||||
val picKey = config.profileKey
|
||||
if (!picUrl.isNullOrEmpty() && picKey.isNotEmpty()) {
|
||||
profile.setPic(UserPic(picUrl, picKey))
|
||||
}
|
||||
val dump = profile.dump()
|
||||
profile.free()
|
||||
return dump
|
||||
}
|
||||
|
||||
fun generateContactConfigDump(context: Context): ByteArray? {
|
||||
val secretKey = maybeUserSecretKey() ?: return null
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
val localUserKey = storage.getUserPublicKey() ?: return null
|
||||
val contactsWithSettings = storage.getAllContacts().filter { recipient ->
|
||||
recipient.sessionID != localUserKey
|
||||
}.map { contact ->
|
||||
contact to storage.getRecipientSettings(Address.fromSerialized(contact.sessionID))!!
|
||||
}
|
||||
val contactConfig = Contacts.newInstance(secretKey)
|
||||
for ((contact, settings) in contactsWithSettings) {
|
||||
val url = contact.profilePictureURL
|
||||
val key = contact.profilePictureEncryptionKey
|
||||
val userPic = if (url.isNullOrEmpty() || key?.isNotEmpty() != true) {
|
||||
null
|
||||
} else {
|
||||
UserPic(url, key)
|
||||
}
|
||||
val contactInfo = Contact(
|
||||
id = contact.sessionID,
|
||||
name = contact.name,
|
||||
nickname = contact.nickname,
|
||||
blocked = settings.isBlocked,
|
||||
approved = settings.isApproved,
|
||||
approvedMe = settings.hasApprovedMe(),
|
||||
profilePicture = userPic
|
||||
)
|
||||
contactConfig.set(contactInfo)
|
||||
}
|
||||
val dump = contactConfig.dump()
|
||||
contactConfig.free()
|
||||
return dump
|
||||
}
|
||||
|
||||
fun generateConversationDump(context: Context): ByteArray? {
|
||||
TODO()
|
||||
}
|
||||
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit 65cc4d6b0afaa6d12a9887c8814b16da5dc45863
|
||||
Subproject commit 349d0b7d0daf5fd612a47809e0ce88829d75d06f
|
@ -65,4 +65,20 @@ class UserProfile(pointer: Long) : ConfigBase(pointer) {
|
||||
external fun getName(): String?
|
||||
external fun getPic(): UserPic?
|
||||
external fun setPic(userPic: UserPic)
|
||||
}
|
||||
|
||||
class ConversationConfig(pointer: Long): ConfigBase(pointer) {
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("session_util")
|
||||
}
|
||||
|
||||
external fun newInstance(ed25519SecretKey: ByteArray): ConversationConfig
|
||||
|
||||
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): ConversationConfig
|
||||
|
||||
}
|
||||
|
||||
external fun todo()
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package network.loki.messenger.libsession_util.util
|
||||
|
||||
sealed class Conversation {
|
||||
data class OneToOne(
|
||||
val sessionId: String,
|
||||
val lastRead: Long,
|
||||
val expiryMode: ExpiryMode,
|
||||
): Conversation()
|
||||
|
||||
data class OpenGroup(
|
||||
val baseUrl: String,
|
||||
val room: String,
|
||||
val pubKey: ByteArray,
|
||||
val lastRead: Long,
|
||||
) : Conversation() {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as OpenGroup
|
||||
|
||||
if (baseUrl != other.baseUrl) return false
|
||||
if (room != other.room) return false
|
||||
if (!pubKey.contentEquals(other.pubKey)) return false
|
||||
if (lastRead != other.lastRead) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = baseUrl.hashCode()
|
||||
result = 31 * result + room.hashCode()
|
||||
result = 31 * result + pubKey.contentHashCode()
|
||||
result = 31 * result + lastRead.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
data class LegacyClosedGroup(
|
||||
val groupId: String,
|
||||
val lastRead: Long,
|
||||
val expiryMode: ExpiryMode
|
||||
): Conversation()
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package network.loki.messenger.libsession_util.util
|
||||
|
||||
sealed class ExpiryMode(val expiryMinutes: Long) {
|
||||
object NONE: ExpiryMode(0)
|
||||
class AfterSend(minutes: Long): ExpiryMode(minutes)
|
||||
class AfterRead(minutes: Long): ExpiryMode(minutes)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user