mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 16:18:26 +00:00
feat: generate serializable Contact info for configuration messages and pass in appropriate list to get current
This commit is contained in:
parent
d1b41a8933
commit
9a33fe8883
@ -16,6 +16,7 @@ import org.session.libsignal.utilities.Hex
|
|||||||
import org.session.libsignal.utilities.logging.Log
|
import org.session.libsignal.utilities.logging.Log
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil
|
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil
|
||||||
|
import org.thoughtcrime.securesms.loki.utilities.ContactUtilities
|
||||||
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
|
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -28,7 +29,12 @@ object MultiDeviceProtocol {
|
|||||||
val lastSyncTime = TextSecurePreferences.getLastConfigurationSyncTime(context)
|
val lastSyncTime = TextSecurePreferences.getLastConfigurationSyncTime(context)
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
if (now - lastSyncTime < 2 * 24 * 60 * 60 * 1000) return
|
if (now - lastSyncTime < 2 * 24 * 60 * 60 * 1000) return
|
||||||
val configurationMessage = ConfigurationMessage.getCurrent()
|
val contacts = ContactUtilities.getAllContacts(context).filter { recipient ->
|
||||||
|
!recipient.isBlocked && !recipient.name.isNullOrEmpty() && !recipient.isLocalNumber && recipient.address.serialize().isNotEmpty()
|
||||||
|
}.map { recipient ->
|
||||||
|
ConfigurationMessage.Contact(recipient.address.serialize(), recipient.name!!, recipient.profileAvatar, recipient.profileKey)
|
||||||
|
}
|
||||||
|
val configurationMessage = ConfigurationMessage.getCurrent(contacts)
|
||||||
val serializedMessage = configurationMessage.toProto()!!.toByteArray()
|
val serializedMessage = configurationMessage.toProto()!!.toByteArray()
|
||||||
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
||||||
val address = SignalServiceAddress(userPublicKey)
|
val address = SignalServiceAddress(userPublicKey)
|
||||||
@ -47,7 +53,12 @@ object MultiDeviceProtocol {
|
|||||||
// TODO: refactor this to use new message sending job
|
// TODO: refactor this to use new message sending job
|
||||||
fun forceSyncConfigurationNowIfNeeded(context: Context) {
|
fun forceSyncConfigurationNowIfNeeded(context: Context) {
|
||||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return
|
||||||
val configurationMessage = ConfigurationMessage.getCurrent()
|
val contacts = ContactUtilities.getAllContacts(context).filter { recipient ->
|
||||||
|
!recipient.isBlocked && !recipient.name.isNullOrEmpty() && !recipient.isLocalNumber && recipient.address.serialize().isNotEmpty()
|
||||||
|
}.map { recipient ->
|
||||||
|
ConfigurationMessage.Contact(recipient.address.serialize(), recipient.name!!, recipient.profileAvatar, recipient.profileKey)
|
||||||
|
}
|
||||||
|
val configurationMessage = ConfigurationMessage.getCurrent(contacts)
|
||||||
val serializedMessage = configurationMessage.toProto()!!.toByteArray()
|
val serializedMessage = configurationMessage.toProto()!!.toByteArray()
|
||||||
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
||||||
val address = SignalServiceAddress(userPublicKey)
|
val address = SignalServiceAddress(userPublicKey)
|
||||||
|
@ -51,12 +51,39 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Contact(val publicKey: String, val name: String, val profilePicture: String?, val profileKey: ByteArray?) {
|
||||||
|
companion object {
|
||||||
|
fun fromProto(proto: SignalServiceProtos.ConfigurationMessage.Contact): Contact? {
|
||||||
|
if (!proto.hasName() || !proto.hasProfileKey()) return null
|
||||||
|
val publicKey = proto.publicKey.toByteArray().toHexString()
|
||||||
|
val name = proto.name
|
||||||
|
val profilePicture = if (proto.hasProfilePicture()) proto.profilePicture else null
|
||||||
|
val profileKey = if (proto.hasProfileKey()) proto.profileKey.toByteArray() else null
|
||||||
|
|
||||||
|
return Contact(publicKey,name,profilePicture,profileKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toProto(): SignalServiceProtos.ConfigurationMessage.Contact? {
|
||||||
|
val result = SignalServiceProtos.ConfigurationMessage.Contact.newBuilder()
|
||||||
|
result.name = this.name
|
||||||
|
result.publicKey = ByteString.copyFrom(Hex.fromStringCondensed(publicKey))
|
||||||
|
if (!this.profilePicture.isNullOrEmpty()) {
|
||||||
|
result.profilePicture = this.profilePicture
|
||||||
|
}
|
||||||
|
if (this.profileKey != null) {
|
||||||
|
result.profileKey = ByteString.copyFrom(this.profileKey)
|
||||||
|
}
|
||||||
|
return result.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val ttl: Long = 4 * 24 * 60 * 60 * 1000
|
override val ttl: Long = 4 * 24 * 60 * 60 * 1000
|
||||||
override val isSelfSendValid: Boolean = true
|
override val isSelfSendValid: Boolean = true
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun getCurrent(): ConfigurationMessage {
|
fun getCurrent(contacts: List<Contact>): ConfigurationMessage {
|
||||||
val closedGroups = mutableListOf<ClosedGroup>()
|
val closedGroups = mutableListOf<ClosedGroup>()
|
||||||
val openGroups = mutableListOf<String>()
|
val openGroups = mutableListOf<String>()
|
||||||
val sharedConfig = MessagingConfiguration.shared
|
val sharedConfig = MessagingConfiguration.shared
|
||||||
|
Loading…
x
Reference in New Issue
Block a user