diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt index 9f07f843c7..60d1085d01 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt @@ -263,7 +263,7 @@ class DefaultMessageNotifier : MessageNotifier { val builder = SingleRecipientNotificationBuilder(context, getNotificationPrivacy(context)) val notifications = notificationState.notifications - val recipient = notifications[0].recipient + val messageOriginator = notifications[0].recipient val notificationId = (SUMMARY_NOTIFICATION_ID + (if (bundled) notifications[0].threadId else 0)).toInt() val messageIdTag = notifications[0].timestamp.toString() @@ -283,10 +283,6 @@ class DefaultMessageNotifier : MessageNotifier { val notificationText = notifications[0].text - // TODO: We get missed call notifications whenever we get a call - I have no idea why, and it would be better to strip them out - // TODO: at the source - but I'll stop them here if we recognise the notification text and the home screen is visible - - // For some reason, even when we're starting a call we get a missed call notification - so we'll bail before that happens. // TODO: Probably better to fix this at the source so that this never gets called rather then here - do this. val missedCallString = Phrase.from(context, R.string.callsMissedCallFrom).put(NAME_KEY, notifications[0].recipient.name).format() @@ -306,7 +302,7 @@ class DefaultMessageNotifier : MessageNotifier { ) builder.setPrimaryMessageBody( - recipient, + messageOriginator, notifications[0].individualRecipient, ss, notifications[0].slideDeck @@ -318,12 +314,12 @@ class DefaultMessageNotifier : MessageNotifier { builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) builder.setAutoCancel(true) - val replyMethod = ReplyMethod.forRecipient(context, recipient) + val replyMethod = ReplyMethod.forRecipient(context, messageOriginator) - val canReply = canUserReplyToNotification(recipient) + val canReply = canUserReplyToNotification(messageOriginator) - val quickReplyIntent = if (canReply) notificationState.getQuickReplyIntent(context, recipient) else null - val remoteReplyIntent = if (canReply) notificationState.getRemoteReplyIntent(context, recipient, replyMethod) else null + val quickReplyIntent = if (canReply) notificationState.getQuickReplyIntent(context, messageOriginator) else null + val remoteReplyIntent = if (canReply) notificationState.getRemoteReplyIntent(context, messageOriginator, replyMethod) else null builder.addActions( notificationState.getMarkAsReadIntent(context, notificationId), @@ -334,7 +330,7 @@ class DefaultMessageNotifier : MessageNotifier { if (canReply) { builder.addAndroidAutoAction( - notificationState.getAndroidAutoReplyIntent(context, recipient), + notificationState.getAndroidAutoReplyIntent(context, messageOriginator), notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications[0].timestamp ) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushManager.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushManager.kt deleted file mode 100644 index d094644c07..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushManager.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.thoughtcrime.securesms.notifications - -interface PushManager { - fun refresh(force: Boolean) -} \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt index c983251ee3..510ab78a90 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt @@ -2,6 +2,9 @@ package org.session.libsession.messaging.sending_receiving.pollers import android.util.SparseArray import androidx.core.util.valueIterator +import java.util.Timer +import java.util.TimerTask +import kotlin.time.Duration.Companion.days import kotlinx.coroutines.GlobalScope import nl.komponents.kovenant.Deferred import nl.komponents.kovenant.Promise @@ -27,9 +30,6 @@ import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Namespace import org.session.libsignal.utilities.Snode import org.session.libsignal.utilities.Util.SECURE_RANDOM -import java.util.Timer -import java.util.TimerTask -import kotlin.time.Duration.Companion.days private const val TAG = "Poller" @@ -49,8 +49,9 @@ class Poller( // region Settings companion object { - private const val retryInterval: Long = 2 * 1000 - private const val maxInterval: Long = 15 * 1000 + private const val RETRY_INTERVAL_MS: Long = 2 * 1000 + private const val MAX_RETRY_INTERVAL_MS: Long = 15 * 1000 + private const val NEXT_RETRY_MULTIPLIER: Float = 1.2f // If we fail to poll we multiply our current retry interval by this (up to the above max) then try again } // endregion @@ -59,7 +60,7 @@ class Poller( if (hasStarted) { return } Log.d(TAG, "Started polling.") hasStarted = true - setUpPolling(retryInterval) + setUpPolling(RETRY_INTERVAL_MS) } fun stopIfNeeded() { @@ -72,11 +73,11 @@ class Poller( Log.d(TAG, "Retrieving user profile. for key = $userPublicKey") SnodeAPI.getSwarm(userPublicKey).bind { usedSnodes.clear() - deferred().also { - pollNextSnode(userProfileOnly = true, it) + deferred().also { exception -> + pollNextSnode(userProfileOnly = true, exception) }.promise - }.fail { - Log.e(TAG, "Failed to retrieve user profile.", it) + }.fail { exception -> + Log.e(TAG, "Failed to retrieve user profile.", exception) } } // endregion @@ -91,14 +92,14 @@ class Poller( pollNextSnode(deferred = deferred) deferred.promise }.success { - val nextDelay = if (isCaughtUp) retryInterval else 0 + val nextDelay = if (isCaughtUp) RETRY_INTERVAL_MS else 0 Timer().schedule(object : TimerTask() { override fun run() { - thread.run { setUpPolling(retryInterval) } + thread.run { setUpPolling(RETRY_INTERVAL_MS) } } }, nextDelay) }.fail { - val nextDelay = minOf(maxInterval, (delay * 1.2).toLong()) + val nextDelay = minOf(MAX_RETRY_INTERVAL_MS, (delay * NEXT_RETRY_MULTIPLIER).toLong()) Timer().schedule(object : TimerTask() { override fun run() { thread.run { setUpPolling(nextDelay) } @@ -231,8 +232,7 @@ class Poller( } } } - - + private fun poll(snode: Snode, deferred: Deferred): Promise { if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) } return GlobalScope.asyncPromise {