fix: fix the notifications and request at appropriate time

This commit is contained in:
0x330a 2023-06-22 11:01:29 +10:00
parent 461669b7c2
commit 64fa5e297c
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
7 changed files with 21 additions and 35 deletions

View File

@ -29,6 +29,7 @@
android:name="android.hardware.touchscreen" android:name="android.hardware.touchscreen"
android:required="false" /> android:required="false" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

View File

@ -1,5 +1,7 @@
package org.thoughtcrime.securesms.home package org.thoughtcrime.securesms.home
import android.Manifest
import android.app.NotificationManager
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
@ -69,6 +71,7 @@ import org.thoughtcrime.securesms.mms.GlideApp
import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.onboarding.SeedActivity import org.thoughtcrime.securesms.onboarding.SeedActivity
import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate
import org.thoughtcrime.securesms.permissions.Permissions
import org.thoughtcrime.securesms.preferences.SettingsActivity import org.thoughtcrime.securesms.preferences.SettingsActivity
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.DateUtils import org.thoughtcrime.securesms.util.DateUtils
@ -87,6 +90,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
SeedReminderViewDelegate, SeedReminderViewDelegate,
GlobalSearchInputLayout.GlobalSearchInputLayoutListener { GlobalSearchInputLayout.GlobalSearchInputLayoutListener {
companion object {
const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING"
}
private lateinit var binding: ActivityHomeBinding private lateinit var binding: ActivityHomeBinding
private lateinit var glide: GlideRequests private lateinit var glide: GlideRequests
private var broadcastReceiver: BroadcastReceiver? = null private var broadcastReceiver: BroadcastReceiver? = null
@ -242,23 +250,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
.onEach(globalSearchViewModel::postQuery) .onEach(globalSearchViewModel::postQuery)
.collect() .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 // Get group results and display them
launch { launch {
globalSearchViewModel.result.collect { result -> globalSearchViewModel.result.collect { result ->
@ -305,6 +296,14 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
} }
} }
EventBus.getDefault().register(this@HomeActivity) 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) { override fun onInputFocusChanged(hasFocus: Boolean) {

View File

@ -60,7 +60,6 @@ import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilit
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities; import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities;
import org.thoughtcrime.securesms.crypto.KeyPairUtilities; import org.thoughtcrime.securesms.crypto.KeyPairUtilities;
import org.thoughtcrime.securesms.database.LokiThreadDatabase; import org.thoughtcrime.securesms.database.LokiThreadDatabase;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
import org.thoughtcrime.securesms.database.MmsSmsDatabase; import org.thoughtcrime.securesms.database.MmsSmsDatabase;
import org.thoughtcrime.securesms.database.RecipientDatabase; import org.thoughtcrime.securesms.database.RecipientDatabase;
import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase;
@ -240,10 +239,6 @@ public class DefaultMessageNotifier implements MessageNotifier {
!(recipient.isApproved() || threads.getLastSeenAndHasSent(threadId).second())) { !(recipient.isApproved() || threads.getLastSeenAndHasSent(threadId).second())) {
TextSecurePreferences.removeHasHiddenMessageRequests(context); TextSecurePreferences.removeHasHiddenMessageRequests(context);
} }
// if (isVisible && recipient != null && threads.getMessageCount(threadId) > 0) {
// List<MarkedMessageInfo> messageIds = threads.setRead(threadId, false);
// if (SessionMetaProtocol.shouldSendReadReceipt(recipient)) { MarkReadReceiver.process(context, messageIds); }
// }
if (!TextSecurePreferences.isNotificationsEnabled(context) || if (!TextSecurePreferences.isNotificationsEnabled(context) ||
(recipient != null && recipient.isMuted())) (recipient != null && recipient.isMuted()))

View File

@ -163,6 +163,7 @@ class PNModeActivity : BaseActionBarActivity() {
application.registerForFCMIfNeeded(true) application.registerForFCMIfNeeded(true)
val intent = Intent(this, HomeActivity::class.java) val intent = Intent(this, HomeActivity::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
intent.putExtra(HomeActivity.FROM_ONBOARDING, true)
show(intent) show(intent)
} }
// endregion // endregion

View File

@ -1,12 +1,10 @@
package org.thoughtcrime.securesms.util package org.thoughtcrime.securesms.util
import android.app.Notification import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.os.Build
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
@ -32,15 +30,7 @@ class CallNotificationBuilder {
@JvmStatic @JvmStatic
fun areNotificationsEnabled(context: Context): Boolean { fun areNotificationsEnabled(context: Context): Boolean {
val notificationManager = NotificationManagerCompat.from(context) val notificationManager = NotificationManagerCompat.from(context)
return when { return notificationManager.areNotificationsEnabled()
!notificationManager.areNotificationsEnabled() -> false
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
notificationManager.notificationChannels.firstOrNull { channel ->
channel.importance == NotificationManager.IMPORTANCE_NONE
} == null
}
else -> true
}
} }
@JvmStatic @JvmStatic

View File

@ -212,6 +212,7 @@ class BatchMessageReceiveJob(
} }
} }
} }
if (threadId == NO_THREAD_MAPPING) return@async
// increment unreads, notify, and update thread // 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) // 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 // might have been updated from a different thread at this point

View File

@ -2,7 +2,6 @@ package org.session.libsession.messaging.jobs
import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.ConfigBase
import network.loki.messenger.libsession_util.ConfigBase.Companion.protoKindFor import network.loki.messenger.libsession_util.ConfigBase.Companion.protoKindFor
import network.loki.messenger.libsession_util.UserGroupsConfig
import nl.komponents.kovenant.functional.bind import nl.komponents.kovenant.functional.bind
import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.Destination import org.session.libsession.messaging.messages.Destination
@ -109,7 +108,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
val responseList = (rawResponses["results"] as List<RawResponse>) val responseList = (rawResponses["results"] as List<RawResponse>)
// we are always adding in deletions at the end // 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 { val deletedHashes = deletionResponse?.let {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
// get the sub-request body // get the sub-request body