mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-03 06:05:41 +00:00
fix: sync timing for multi device partial restore
This commit is contained in:
parent
cf373f3a93
commit
6c81580d93
@ -17,6 +17,7 @@ import kotlinx.android.synthetic.main.activity_create_private_chat.*
|
|||||||
import kotlinx.android.synthetic.main.activity_create_private_chat.tabLayout
|
import kotlinx.android.synthetic.main.activity_create_private_chat.tabLayout
|
||||||
import kotlinx.android.synthetic.main.activity_create_private_chat.viewPager
|
import kotlinx.android.synthetic.main.activity_create_private_chat.viewPager
|
||||||
import kotlinx.android.synthetic.main.activity_link_device.*
|
import kotlinx.android.synthetic.main.activity_link_device.*
|
||||||
|
import kotlinx.android.synthetic.main.conversation_activity.*
|
||||||
import kotlinx.android.synthetic.main.fragment_recovery_phrase.*
|
import kotlinx.android.synthetic.main.fragment_recovery_phrase.*
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
@ -42,6 +43,11 @@ class LinkDeviceActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDel
|
|||||||
private val adapter = LinkDeviceActivityAdapter(this)
|
private val adapter = LinkDeviceActivityAdapter(this)
|
||||||
private var restoreJob: Job? = null
|
private var restoreJob: Job? = null
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
if (restoreJob?.isActive == true) return // don't allow going back with pending job
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -84,8 +90,10 @@ class LinkDeviceActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDel
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun continueWithSeed(seed: ByteArray) {
|
private fun continueWithSeed(seed: ByteArray) {
|
||||||
viewPager.currentItem = 0 // reset view to the main one
|
|
||||||
restoreJob?.cancel()
|
// only have one sync job running at a time (prevent QR from trying to spawn a new job)
|
||||||
|
if (restoreJob?.isActive == true) return
|
||||||
|
|
||||||
restoreJob = lifecycleScope.launch {
|
restoreJob = lifecycleScope.launch {
|
||||||
// RestoreActivity handles seed this way
|
// RestoreActivity handles seed this way
|
||||||
val keyPairGenerationResult = KeyPairUtilities.generate(seed)
|
val keyPairGenerationResult = KeyPairUtilities.generate(seed)
|
||||||
@ -123,7 +131,7 @@ class LinkDeviceActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDel
|
|||||||
private fun register(skipped: Boolean) {
|
private fun register(skipped: Boolean) {
|
||||||
restoreJob?.cancel()
|
restoreJob?.cancel()
|
||||||
loader.isVisible = false
|
loader.isVisible = false
|
||||||
ApplicationContext.getInstance(this).stopPolling()
|
TextSecurePreferences.setLastConfigurationSyncTime(this, System.currentTimeMillis())
|
||||||
val intent = Intent(this@LinkDeviceActivity, if (skipped) DisplayNameActivity::class.java else PNModeActivity::class.java)
|
val intent = Intent(this@LinkDeviceActivity, if (skipped) DisplayNameActivity::class.java else PNModeActivity::class.java)
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
push(intent)
|
push(intent)
|
||||||
|
@ -73,6 +73,7 @@ object MultiDeviceProtocol {
|
|||||||
messageSender.sendMessage(0, address, udAccess,
|
messageSender.sendMessage(0, address, udAccess,
|
||||||
Date().time, serializedMessage, false, configurationMessage.ttl.toInt(),
|
Date().time, serializedMessage, false, configurationMessage.ttl.toInt(),
|
||||||
true, false, false, Optional.absent())
|
true, false, false, Optional.absent())
|
||||||
|
TextSecurePreferences.setLastConfigurationSyncTime(context, System.currentTimeMillis())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.d("Loki", "Failed to send configuration message due to error: $e.")
|
Log.d("Loki", "Failed to send configuration message due to error: $e.")
|
||||||
}
|
}
|
||||||
@ -81,10 +82,16 @@ object MultiDeviceProtocol {
|
|||||||
// TODO: remove this after we migrate to new message receiving pipeline
|
// TODO: remove this after we migrate to new message receiving pipeline
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun handleConfigurationMessage(context: Context, content: SignalServiceProtos.Content, senderPublicKey: String, timestamp: Long) {
|
fun handleConfigurationMessage(context: Context, content: SignalServiceProtos.Content, senderPublicKey: String, timestamp: Long) {
|
||||||
if (TextSecurePreferences.getConfigurationMessageSynced(context) && !TextSecurePreferences.shouldUpdateProfile(context, timestamp)) return
|
|
||||||
val configurationMessage = ConfigurationMessage.fromProto(content) ?: return
|
|
||||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return
|
||||||
if (senderPublicKey != userPublicKey) return
|
synchronized(this) {
|
||||||
|
if (TextSecurePreferences.getConfigurationMessageSynced(context) && !TextSecurePreferences.shouldUpdateProfile(context, timestamp)) return
|
||||||
|
if (senderPublicKey != userPublicKey) return
|
||||||
|
TextSecurePreferences.setConfigurationMessageSynced(context, true)
|
||||||
|
TextSecurePreferences.setLastProfileUpdateTime(context, timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
val configurationMessage = ConfigurationMessage.fromProto(content) ?: return
|
||||||
|
|
||||||
val storage = MessagingConfiguration.shared.storage
|
val storage = MessagingConfiguration.shared.storage
|
||||||
val allClosedGroupPublicKeys = storage.getAllClosedGroupPublicKeys()
|
val allClosedGroupPublicKeys = storage.getAllClosedGroupPublicKeys()
|
||||||
|
|
||||||
@ -149,7 +156,5 @@ object MultiDeviceProtocol {
|
|||||||
threadDatabase.notifyUpdatedFromConfig()
|
threadDatabase.notifyUpdatedFromConfig()
|
||||||
}
|
}
|
||||||
// TODO: handle new configuration message fields or handle in new pipeline
|
// TODO: handle new configuration message fields or handle in new pipeline
|
||||||
TextSecurePreferences.setConfigurationMessageSynced(context, true)
|
|
||||||
TextSecurePreferences.setLastProfileUpdateTime(context, timestamp)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,14 +33,20 @@ import android.net.Uri;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier;
|
import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier;
|
||||||
import org.thoughtcrime.securesms.ApplicationContext;
|
|
||||||
import org.session.libsession.messaging.sending_receiving.sharecontacts.Contact;
|
import org.session.libsession.messaging.sending_receiving.sharecontacts.Contact;
|
||||||
|
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||||
|
import org.session.libsession.utilities.ServiceUtil;
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences;
|
||||||
|
import org.session.libsignal.service.internal.util.Util;
|
||||||
|
import org.session.libsignal.utilities.logging.Log;
|
||||||
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||||
import org.thoughtcrime.securesms.conversation.ConversationActivity;
|
import org.thoughtcrime.securesms.conversation.ConversationActivity;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
@ -50,16 +56,11 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
|
|||||||
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||||
import org.session.libsignal.utilities.logging.Log;
|
|
||||||
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
|
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
|
||||||
import org.thoughtcrime.securesms.loki.utilities.MentionUtilities;
|
import org.thoughtcrime.securesms.loki.utilities.MentionUtilities;
|
||||||
import org.thoughtcrime.securesms.mms.SlideDeck;
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
|
||||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||||
import org.session.libsession.utilities.ServiceUtil;
|
|
||||||
import org.thoughtcrime.securesms.util.SpanUtil;
|
import org.thoughtcrime.securesms.util.SpanUtil;
|
||||||
import org.session.libsession.utilities.TextSecurePreferences;
|
|
||||||
import org.session.libsignal.service.internal.util.Util;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -247,8 +248,8 @@ public class DefaultMessageNotifier implements MessageNotifier {
|
|||||||
telcoCursor = DatabaseFactory.getMmsSmsDatabase(context).getUnread();
|
telcoCursor = DatabaseFactory.getMmsSmsDatabase(context).getUnread();
|
||||||
pushCursor = DatabaseFactory.getPushDatabase(context).getPending();
|
pushCursor = DatabaseFactory.getPushDatabase(context).getPending();
|
||||||
|
|
||||||
if ((telcoCursor == null || telcoCursor.isAfterLast()) &&
|
if (((telcoCursor == null || telcoCursor.isAfterLast()) &&
|
||||||
(pushCursor == null || pushCursor.isAfterLast()))
|
(pushCursor == null || pushCursor.isAfterLast())) || !TextSecurePreferences.hasSeenWelcomeScreen(context))
|
||||||
{
|
{
|
||||||
cancelActiveNotifications(context);
|
cancelActiveNotifications(context);
|
||||||
updateBadge(context, 0);
|
updateBadge(context, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user