From 64fa5e297cc495fbaee804a146cb886762e48b82 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:01:29 +1000 Subject: [PATCH] fix: fix the notifications and request at appropriate time --- app/src/main/AndroidManifest.xml | 1 + .../securesms/home/HomeActivity.kt | 33 +++++++++---------- .../notifications/DefaultMessageNotifier.java | 5 --- .../securesms/onboarding/PNModeActivity.kt | 1 + .../securesms/util/CallNotificationBuilder.kt | 12 +------ .../messaging/jobs/BatchMessageReceiveJob.kt | 1 + .../messaging/jobs/ConfigurationSyncJob.kt | 3 +- 7 files changed, 21 insertions(+), 35 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2d2b2123dd..ecf27a89ab 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,6 +29,7 @@ android:name="android.hardware.touchscreen" android:required="false" /> + diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index b520f7f7cb..d52e482794 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -1,5 +1,7 @@ package org.thoughtcrime.securesms.home +import android.Manifest +import android.app.NotificationManager import android.content.BroadcastReceiver import android.content.ClipData import android.content.ClipboardManager @@ -69,6 +71,7 @@ import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.onboarding.SeedActivity import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate +import org.thoughtcrime.securesms.permissions.Permissions import org.thoughtcrime.securesms.preferences.SettingsActivity import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import org.thoughtcrime.securesms.util.DateUtils @@ -87,6 +90,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), SeedReminderViewDelegate, GlobalSearchInputLayout.GlobalSearchInputLayoutListener { + companion object { + const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING" + } + + private lateinit var binding: ActivityHomeBinding private lateinit var glide: GlideRequests private var broadcastReceiver: BroadcastReceiver? = null @@ -242,23 +250,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), .onEach(globalSearchViewModel::postQuery) .collect() } -// launch(IO) { -// val publicKey = TextSecurePreferences.getLocalNumber(this@HomeActivity) ?: return@launch -// // do a expire -// try { -// val promise = SnodeAPI.alterTtl( -// listOf( -// "message hashes" -// ), -// some long in the future, -// publicKey -// ) -// val result = promise.get() -// Log.d("TTL", "ttl result: $result") -// } catch (e: Exception) { -// Log.e("TTL", "Expiry didn't work", e) -// } -// } // Get group results and display them launch { globalSearchViewModel.result.collect { result -> @@ -305,6 +296,14 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), } } EventBus.getDefault().register(this@HomeActivity) + if (intent.hasExtra(FROM_ONBOARDING) + && intent.getBooleanExtra(FROM_ONBOARDING, false) + && !(getSystemService(NOTIFICATION_SERVICE) as NotificationManager).areNotificationsEnabled() + ) { + Permissions.with(this) + .request(Manifest.permission.POST_NOTIFICATIONS) + .execute() + } } override fun onInputFocusChanged(hasFocus: Boolean) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java index 96593a1a53..a8f575d225 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java @@ -60,7 +60,6 @@ import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilit import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities; import org.thoughtcrime.securesms.crypto.KeyPairUtilities; import org.thoughtcrime.securesms.database.LokiThreadDatabase; -import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo; import org.thoughtcrime.securesms.database.MmsSmsDatabase; import org.thoughtcrime.securesms.database.RecipientDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase; @@ -240,10 +239,6 @@ public class DefaultMessageNotifier implements MessageNotifier { !(recipient.isApproved() || threads.getLastSeenAndHasSent(threadId).second())) { TextSecurePreferences.removeHasHiddenMessageRequests(context); } -// if (isVisible && recipient != null && threads.getMessageCount(threadId) > 0) { -// List messageIds = threads.setRead(threadId, false); -// if (SessionMetaProtocol.shouldSendReadReceipt(recipient)) { MarkReadReceiver.process(context, messageIds); } -// } if (!TextSecurePreferences.isNotificationsEnabled(context) || (recipient != null && recipient.isMuted())) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt index 9cf9c3d049..a1807c587e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt @@ -163,6 +163,7 @@ class PNModeActivity : BaseActionBarActivity() { application.registerForFCMIfNeeded(true) val intent = Intent(this, HomeActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + intent.putExtra(HomeActivity.FROM_ONBOARDING, true) show(intent) } // endregion diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt index 56c0a55dda..0ba63fc549 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt @@ -1,12 +1,10 @@ package org.thoughtcrime.securesms.util import android.app.Notification -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent import android.content.Intent.FLAG_ACTIVITY_NEW_TASK -import android.os.Build import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.core.app.NotificationCompat @@ -32,15 +30,7 @@ class CallNotificationBuilder { @JvmStatic fun areNotificationsEnabled(context: Context): Boolean { val notificationManager = NotificationManagerCompat.from(context) - return when { - !notificationManager.areNotificationsEnabled() -> false - Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> { - notificationManager.notificationChannels.firstOrNull { channel -> - channel.importance == NotificationManager.IMPORTANCE_NONE - } == null - } - else -> true - } + return notificationManager.areNotificationsEnabled() } @JvmStatic diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt index 32df93a72c..710a49812b 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt @@ -212,6 +212,7 @@ class BatchMessageReceiveJob( } } } + if (threadId == NO_THREAD_MAPPING) return@async // increment unreads, notify, and update thread // last seen will be the current last seen if not changed (re-computes the read counts for thread record) // might have been updated from a different thread at this point diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt index 51f281f7a7..fcd7dd8eac 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt @@ -2,7 +2,6 @@ package org.session.libsession.messaging.jobs import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.ConfigBase.Companion.protoKindFor -import network.loki.messenger.libsession_util.UserGroupsConfig import nl.komponents.kovenant.functional.bind import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.messages.Destination @@ -109,7 +108,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job { @Suppress("UNCHECKED_CAST") val responseList = (rawResponses["results"] as List) // we are always adding in deletions at the end - val deletionResponse = if (toDeleteRequest != null) responseList.last() else null + val deletionResponse = if (toDeleteRequest != null && responseList.isNotEmpty()) responseList.last() else null val deletedHashes = deletionResponse?.let { @Suppress("UNCHECKED_CAST") // get the sub-request body