fix: add some more contact syncing: nicknames, approved statuses, blocked statuses

This commit is contained in:
0x330a
2023-02-24 17:05:33 +11:00
parent b3ae2e967f
commit c36387175d
9 changed files with 52 additions and 37 deletions

View File

@@ -204,7 +204,7 @@ interface StorageProtocol {
fun removeReaction(emoji: String, messageTimestamp: Long, author: String, notifyUnread: Boolean)
fun updateReactionIfNeeded(message: Message, sender: String, openGroupSentTimestamp: Long)
fun deleteReactions(messageId: Long, mms: Boolean)
fun setBlocked(recipients: List<Recipient>, isBlocked: Boolean)
fun setBlocked(recipients: List<Recipient>, isBlocked: Boolean, fromConfigUpdate: Boolean = false)
fun blockedContacts(): List<Recipient>
// Shared configs

View File

@@ -21,18 +21,12 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
override var failureCount: Int = 0
override val maxFailureCount: Int = 1
val isRunning = AtomicBoolean(false)
val shouldRunAgain = AtomicBoolean(false)
suspend fun wrap(body: suspend ()->Unit) {
isRunning.set(true)
body()
isRunning.set(false)
}
override suspend fun execute(dispatcherName: String) = wrap {
override suspend fun execute(dispatcherName: String) {
val storage = MessagingModuleConfiguration.shared.storage
val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()
val userPublicKey = MessagingModuleConfiguration.shared.storage.getUserPublicKey()
val userPublicKey = storage.getUserPublicKey()
val delegate = delegate
if (destination is Destination.ClosedGroup // TODO: closed group configs will be handled in closed group feature
// if we haven't enabled the new configs don't run
@@ -47,7 +41,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
|| (destination is Destination.Contact && destination.publicKey != userPublicKey)
) {
Log.w(TAG, "No need to run config sync job, TODO")
return@wrap delegate?.handleJobSucceeded(this, dispatcherName) ?: Unit
return delegate?.handleJobSucceeded(this, dispatcherName) ?: Unit
}
// configFactory singleton instance will come in handy for modifying hashes and fetching configs for namespace etc
@@ -61,7 +55,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
).filter { config -> config.needsPush() }
// don't run anything if we don't need to push anything
if (configsRequiringPush.isEmpty()) return@wrap delegate.handleJobSucceeded(this, dispatcherName)
if (configsRequiringPush.isEmpty()) return delegate.handleJobSucceeded(this, dispatcherName)
// allow null results here so the list index matches configsRequiringPush
val batchObjects: List<Pair<SharedConfigurationMessage, SnodeAPI.SnodeBatchRequestInfo>?> = configsRequiringPush.map { config ->
@@ -88,7 +82,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
if (batchObjects.any { it == null }) {
// stop running here, something like a signing error occurred
return@wrap delegate.handleJobFailedPermanently(this, dispatcherName, NullPointerException("One or more requests had a null batch request info"))
return delegate.handleJobFailedPermanently(this, dispatcherName, NullPointerException("One or more requests had a null batch request info"))
}
val allRequests = mutableListOf<SnodeAPI.SnodeBatchRequestInfo>()
@@ -156,9 +150,13 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
}
} catch (e: Exception) {
Log.e(TAG, "Error performing batch request", e)
return@wrap delegate.handleJobFailedPermanently(this, dispatcherName, e)
return delegate.handleJobFailedPermanently(this, dispatcherName, e)
}
delegate.handleJobSucceeded(this, dispatcherName)
if (shouldRunAgain.get() && storage.getConfigSyncJob(destination) == null) {
// reschedule if something has updated since we started this job
JobQueue.shared.add(ConfigurationSyncJob(destination))
}
}
fun Destination.destinationPublicKey(): String = when (this) {

View File

@@ -43,7 +43,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
var isCaughtUp = false
var configPollingJob: Job? = null
val configDebouncer = WindowDebouncer(3000, debounceTimer)
private val configDebouncer = WindowDebouncer(3000, debounceTimer)
// region Settings
companion object {
@@ -144,9 +144,6 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
return
}
Log.d("Loki-DBG", "Received configs with hashes: ${messages.map { it.second }}")
Log.d("Loki-DBG", "Hashes we have for config: ${configFactory.getHashesFor(forConfigObject)}")
messages.forEach { (envelope, hash) ->
try {
val (message, _) = MessageReceiver.parse(data = envelope.toByteArray(), openGroupServerID = null)

View File

@@ -1,23 +1,24 @@
package org.session.libsession.utilities;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.session.libsignal.utilities.Base64;
import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsession.utilities.Util;
import java.io.IOException;
public class ProfileKeyUtil {
public static final int PROFILE_KEY_BYTES = 32;
public static synchronized @NonNull byte[] getProfileKey(@NonNull Context context) {
try {
String encodedProfileKey = TextSecurePreferences.getProfileKey(context);
if (encodedProfileKey == null) {
encodedProfileKey = Util.getSecret(32);
encodedProfileKey = Util.getSecret(PROFILE_KEY_BYTES);
TextSecurePreferences.setProfileKey(context, encodedProfileKey);
}
@@ -36,7 +37,7 @@ public class ProfileKeyUtil {
}
public static synchronized @NonNull String generateEncodedProfileKey(@NonNull Context context) {
return Util.getSecret(32);
return Util.getSecret(PROFILE_KEY_BYTES);
}
public static synchronized void setEncodedProfileKey(@NonNull Context context, @Nullable String key) {

View File

@@ -1,6 +1,7 @@
package org.session.libsession.utilities
import android.content.Context
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier
import org.session.libsession.utilities.recipients.Recipient
@@ -33,6 +34,7 @@ class SSKEnvironment(
fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String)
fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray?)
fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode)
fun contactUpdatedInternal(contact: Contact)
}
interface MessageExpirationManagerProtocol {