mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-21 17:18:41 +00:00
feat: expand on the config sync job, finish basic implementation to test against
This commit is contained in:
@@ -8,11 +8,13 @@ import org.session.libsession.messaging.BlindedIdMapping
|
||||
import org.session.libsession.messaging.calls.CallMessageType
|
||||
import org.session.libsession.messaging.contacts.Contact
|
||||
import org.session.libsession.messaging.jobs.AttachmentUploadJob
|
||||
import org.session.libsession.messaging.jobs.ConfigurationSyncJob
|
||||
import org.session.libsession.messaging.jobs.GroupAvatarDownloadJob
|
||||
import org.session.libsession.messaging.jobs.Job
|
||||
import org.session.libsession.messaging.jobs.JobQueue
|
||||
import org.session.libsession.messaging.jobs.MessageReceiveJob
|
||||
import org.session.libsession.messaging.jobs.MessageSendJob
|
||||
import org.session.libsession.messaging.messages.Destination
|
||||
import org.session.libsession.messaging.messages.Message
|
||||
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
||||
import org.session.libsession.messaging.messages.control.MessageRequestResponse
|
||||
@@ -240,6 +242,12 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
return DatabaseComponent.get(context).sessionJobDatabase().getGroupAvatarDownloadJob(server, room)
|
||||
}
|
||||
|
||||
override fun getConfigSyncJob(destination: Destination): Job? {
|
||||
return DatabaseComponent.get(context).sessionJobDatabase().getAllPendingJobs(ConfigurationSyncJob.KEY).values.firstOrNull {
|
||||
(it as? ConfigurationSyncJob)?.destination == destination
|
||||
}
|
||||
}
|
||||
|
||||
override fun resumeMessageSendJobIfNeeded(messageSendJobID: String) {
|
||||
val job = DatabaseComponent.get(context).sessionJobDatabase().getMessageSendJob(messageSendJobID) ?: return
|
||||
JobQueue.shared.resumePendingSendMessage(job)
|
||||
|
@@ -135,6 +135,20 @@ class ConfigFactory(private val context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
override fun getHashesFor(forConfigObject: ConfigBase): List<String> =
|
||||
when (forConfigObject) {
|
||||
is UserProfile -> userHashes.toList()
|
||||
is Contacts -> contactsHashes.toList()
|
||||
is ConversationVolatileConfig -> convoHashes.toList()
|
||||
}
|
||||
|
||||
override fun removeHashesFor(forConfigObject: ConfigBase, deletedHashes: Set<String>) =
|
||||
when (forConfigObject) {
|
||||
is UserProfile -> userHashes.removeAll(deletedHashes)
|
||||
is Contacts -> contactsHashes.removeAll(deletedHashes)
|
||||
is ConversationVolatileConfig -> convoHashes.removeAll(deletedHashes)
|
||||
}
|
||||
|
||||
private fun updateUser(userProfile: UserProfile) {
|
||||
val (_, userPublicKey) = maybeGetUserInfo() ?: return
|
||||
// would love to get rid of recipient and context from this
|
||||
|
@@ -8,22 +8,31 @@ 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.jobs.ConfigurationSyncJob
|
||||
import org.session.libsession.messaging.jobs.JobQueue
|
||||
import org.session.libsession.messaging.messages.Destination
|
||||
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsignal.utilities.Log
|
||||
|
||||
object ConfigurationMessageUtilities {
|
||||
|
||||
@JvmStatic
|
||||
fun syncConfigurationIfNeeded(context: Context) {
|
||||
// add if check here to schedule new config job process and return early
|
||||
if (ConfigBase.isNewConfigEnabled) {
|
||||
// schedule job if none exist
|
||||
TODO()
|
||||
}
|
||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
if (ConfigBase.isNewConfigEnabled) {
|
||||
// don't schedule job if we already have one
|
||||
val ourDestination = Destination.Contact(userPublicKey)
|
||||
if (storage.getConfigSyncJob(ourDestination) != null) return
|
||||
val newConfigSync = ConfigurationSyncJob(ourDestination)
|
||||
Log.d("Loki", "Scheduling new ConfigurationSyncJob")
|
||||
JobQueue.shared.add(newConfigSync)
|
||||
return
|
||||
}
|
||||
val lastSyncTime = TextSecurePreferences.getLastConfigurationSyncTime(context)
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastSyncTime < 7 * 24 * 60 * 60 * 1000) return
|
||||
|
Reference in New Issue
Block a user