From f13b5ab9d719244e10ee102072a1948f4cf0c170 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 19 May 2021 17:01:53 +1000 Subject: [PATCH 01/12] fix open group spam --- .../securesms/ApplicationContext.java | 6 ++-- .../securesms/loki/api/OpenGroupManager.kt | 16 +++++++++ .../OptimizedMessageNotifier.java | 33 +++---------------- .../pollers/OpenGroupPollerV2.kt | 2 ++ 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index afcfff4a21..9cc136153a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -206,10 +206,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc poller.setCaughtUp(false); } startPollingIfNeeded(); - // FIXME: Open group handling - /* - publicChatManager.markAllAsNotCaughtUp(); - */ + + OpenGroupManager.INSTANCE.markAllAsNotCaughtUp(); OpenGroupManager.INSTANCE.startPolling(); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/OpenGroupManager.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/OpenGroupManager.kt index 62aca11265..c682a89557 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/OpenGroupManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/OpenGroupManager.kt @@ -19,6 +19,22 @@ object OpenGroupManager { private var pollers = mutableMapOf() // One for each server private var isPolling = false + val isAllCaughtUp: Boolean + get() { + pollers.values.forEach { poller -> + if (!poller.isCaughtUp) { + return false + } + } + return true + } + + fun markAllAsNotCaughtUp() { + pollers.values.forEach { poller -> + poller.isCaughtUp = false + } + } + fun startPolling() { if (isPolling) { return } isPolling = true diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java index 46b4d836d7..448d977da9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java @@ -12,6 +12,7 @@ import org.session.libsession.utilities.recipients.Recipient; import org.session.libsession.utilities.Debouncer; import org.session.libsignal.utilities.ThreadUtils; import org.thoughtcrime.securesms.ApplicationContext; +import org.thoughtcrime.securesms.loki.api.OpenGroupManager; import java.util.concurrent.TimeUnit; @@ -42,18 +43,12 @@ public class OptimizedMessageNotifier implements MessageNotifier { @Override public void updateNotification(@NonNull Context context) { Poller poller = ApplicationContext.getInstance(context).poller; - // FIXME: Open group handling boolean isCaughtUp = true; if (poller != null) { isCaughtUp = isCaughtUp && poller.isCaughtUp(); } - // FIXME: Open group handling - /* - if (publicChatManager != null) { - isCaughtUp = isCaughtUp && publicChatManager.areAllCaughtUp(); - } - */ + isCaughtUp = isCaughtUp && OpenGroupManager.INSTANCE.isAllCaughtUp(); if (isCaughtUp) { performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context)); @@ -65,18 +60,12 @@ public class OptimizedMessageNotifier implements MessageNotifier { @Override public void updateNotification(@NonNull Context context, long threadId) { Poller lokiPoller = ApplicationContext.getInstance(context).poller; - // FIXME: Open group handling boolean isCaughtUp = true; if (lokiPoller != null) { isCaughtUp = isCaughtUp && lokiPoller.isCaughtUp(); } - // FIXME: Open group handling - /* - if (publicChatManager != null) { - isCaughtUp = isCaughtUp && publicChatManager.areAllCaughtUp(); - } - */ + isCaughtUp = isCaughtUp && OpenGroupManager.INSTANCE.isAllCaughtUp(); if (isCaughtUp) { performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, threadId)); @@ -88,18 +77,12 @@ public class OptimizedMessageNotifier implements MessageNotifier { @Override public void updateNotification(@NonNull Context context, long threadId, boolean signal) { Poller lokiPoller = ApplicationContext.getInstance(context).poller; - // FIXME: Open group handling boolean isCaughtUp = true; if (lokiPoller != null) { isCaughtUp = isCaughtUp && lokiPoller.isCaughtUp(); } - // FIXME: Open group handling - /* - if (publicChatManager != null) { - isCaughtUp = isCaughtUp && publicChatManager.areAllCaughtUp(); - } - */ + isCaughtUp = isCaughtUp && OpenGroupManager.INSTANCE.isAllCaughtUp(); if (isCaughtUp) { performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, threadId, signal)); @@ -111,18 +94,12 @@ public class OptimizedMessageNotifier implements MessageNotifier { @Override public void updateNotification(@androidx.annotation.NonNull Context context, boolean signal, int reminderCount) { Poller lokiPoller = ApplicationContext.getInstance(context).poller; - // FIXME: Open group handling boolean isCaughtUp = true; if (lokiPoller != null) { isCaughtUp = isCaughtUp && lokiPoller.isCaughtUp(); } - // FIXME: Open group handling - /* - if (publicChatManager != null) { - isCaughtUp = isCaughtUp && publicChatManager.areAllCaughtUp(); - } - */ + isCaughtUp = isCaughtUp && OpenGroupManager.INSTANCE.isAllCaughtUp(); if (isCaughtUp) { performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, signal, reminderCount)); diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt index 320c3afd97..70e1ea903e 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt @@ -18,6 +18,7 @@ import java.util.concurrent.TimeUnit class OpenGroupPollerV2(private val server: String, private val executorService: ScheduledExecutorService?) { var hasStarted = false + var isCaughtUp = false private var future: ScheduledFuture<*>? = null companion object { @@ -44,6 +45,7 @@ class OpenGroupPollerV2(private val server: String, private val executorService: handleNewMessages(openGroupID, response.messages, isBackgroundPoll) handleDeletedMessages(openGroupID, response.deletions) } + isCaughtUp = true }.always { executorService?.schedule(this@OpenGroupPollerV2::poll, OpenGroupPollerV2.pollInterval, TimeUnit.MILLISECONDS) }.map { } From c861b330ba2d3c09b445e456a9fdbb77a11944a9 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 19 May 2021 15:25:36 +1000 Subject: [PATCH 02/12] Add file server instability modal --- .../securesms/loki/activities/HomeActivity.kt | 23 +++------ .../loki/dialogs/FileServerDialog.kt | 33 +++++++++++++ .../securesms/loki/dialogs/SeedDialog.kt | 1 - .../main/res/layout/dialog_file_server.xml | 49 +++++++++++++++++++ .../utilities/TextSecurePreferences.kt | 8 +++ 5 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/FileServerDialog.kt create mode 100644 app/src/main/res/layout/dialog_file_server.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index b399d6e192..97011940e8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -172,8 +172,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), if (hasViewedSeed) { seedReminderView.visibility = View.GONE } - showKeyPairMigrationSheetIfNeeded() - showKeyPairMigrationSuccessSheetIfNeeded() + showFileServerInstabilityNotificationIfNeeded() if (TextSecurePreferences.getConfigurationMessageSynced(this)) { lifecycleScope.launch(Dispatchers.IO) { MultiDeviceProtocol.syncConfigurationIfNeeded(this@HomeActivity) @@ -181,21 +180,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), } } - private fun showKeyPairMigrationSheetIfNeeded() { - if (KeyPairUtilities.hasV2KeyPair(this)) { - return - } - val keyPairMigrationSheet = KeyPairMigrationBottomSheet() - keyPairMigrationSheet.show(supportFragmentManager, keyPairMigrationSheet.tag) - } - - private fun showKeyPairMigrationSuccessSheetIfNeeded() { - if (!KeyPairUtilities.hasV2KeyPair(this) || !TextSecurePreferences.getIsMigratingKeyPair(this)) { - return - } - val keyPairMigrationSuccessSheet = KeyPairMigrationSuccessBottomSheet() - keyPairMigrationSuccessSheet.show(supportFragmentManager, keyPairMigrationSuccessSheet.tag) - TextSecurePreferences.setIsMigratingKeyPair(this, false) + private fun showFileServerInstabilityNotificationIfNeeded() { + val hasSeenNotification = TextSecurePreferences.hasSeenFileServerInstabilityNotification(this) + if (hasSeenNotification) { return } + FileServerDialog().show(supportFragmentManager, "File Server Dialog") + TextSecurePreferences.setHasSeenFileServerInstabilityNotification(this) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/FileServerDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/FileServerDialog.kt new file mode 100644 index 0000000000..c3a0d7d7b1 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/FileServerDialog.kt @@ -0,0 +1,33 @@ +package org.thoughtcrime.securesms.loki.dialogs + +import android.app.Dialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.os.Bundle +import android.view.LayoutInflater +import android.widget.Toast +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import kotlinx.android.synthetic.main.dialog_file_server.view.* +import kotlinx.android.synthetic.main.dialog_seed.view.* +import network.loki.messenger.R +import org.session.libsession.utilities.IdentityKeyUtil +import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities +import org.session.libsignal.crypto.MnemonicCodec +import org.session.libsignal.utilities.hexEncodedPrivateKey + +class FileServerDialog : DialogFragment() { + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val builder = AlertDialog.Builder(requireContext()) + val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_file_server, null) + contentView.okButton.setOnClickListener { dismiss() } + builder.setView(contentView) + val result = builder.create() + result.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) + return result + } +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt index da19275464..2bd9595b22 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt @@ -18,7 +18,6 @@ import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities import org.session.libsignal.crypto.MnemonicCodec import org.session.libsignal.utilities.hexEncodedPrivateKey - class SeedDialog : DialogFragment() { private val seed by lazy { diff --git a/app/src/main/res/layout/dialog_file_server.xml b/app/src/main/res/layout/dialog_file_server.xml new file mode 100644 index 0000000000..8b4a4c12eb --- /dev/null +++ b/app/src/main/res/layout/dialog_file_server.xml @@ -0,0 +1,49 @@ + + + + + + + + + +