Minor cleanup

pull/1706/head
Al Lansley 5 months ago
parent c4644e52bd
commit 6b3fd2ad97

@ -263,7 +263,7 @@ class DefaultMessageNotifier : MessageNotifier {
val builder = SingleRecipientNotificationBuilder(context, getNotificationPrivacy(context)) val builder = SingleRecipientNotificationBuilder(context, getNotificationPrivacy(context))
val notifications = notificationState.notifications 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 notificationId = (SUMMARY_NOTIFICATION_ID + (if (bundled) notifications[0].threadId else 0)).toInt()
val messageIdTag = notifications[0].timestamp.toString() val messageIdTag = notifications[0].timestamp.toString()
@ -283,10 +283,6 @@ class DefaultMessageNotifier : MessageNotifier {
val notificationText = notifications[0].text 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. // 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. // 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() 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( builder.setPrimaryMessageBody(
recipient, messageOriginator,
notifications[0].individualRecipient, notifications[0].individualRecipient,
ss, ss,
notifications[0].slideDeck notifications[0].slideDeck
@ -318,12 +314,12 @@ class DefaultMessageNotifier : MessageNotifier {
builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
builder.setAutoCancel(true) 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 quickReplyIntent = if (canReply) notificationState.getQuickReplyIntent(context, messageOriginator) else null
val remoteReplyIntent = if (canReply) notificationState.getRemoteReplyIntent(context, recipient, replyMethod) else null val remoteReplyIntent = if (canReply) notificationState.getRemoteReplyIntent(context, messageOriginator, replyMethod) else null
builder.addActions( builder.addActions(
notificationState.getMarkAsReadIntent(context, notificationId), notificationState.getMarkAsReadIntent(context, notificationId),
@ -334,7 +330,7 @@ class DefaultMessageNotifier : MessageNotifier {
if (canReply) { if (canReply) {
builder.addAndroidAutoAction( builder.addAndroidAutoAction(
notificationState.getAndroidAutoReplyIntent(context, recipient), notificationState.getAndroidAutoReplyIntent(context, messageOriginator),
notificationState.getAndroidAutoHeardIntent(context, notificationId), notificationState.getAndroidAutoHeardIntent(context, notificationId),
notifications[0].timestamp notifications[0].timestamp
) )

@ -1,5 +0,0 @@
package org.thoughtcrime.securesms.notifications
interface PushManager {
fun refresh(force: Boolean)
}

@ -2,6 +2,9 @@ package org.session.libsession.messaging.sending_receiving.pollers
import android.util.SparseArray import android.util.SparseArray
import androidx.core.util.valueIterator import androidx.core.util.valueIterator
import java.util.Timer
import java.util.TimerTask
import kotlin.time.Duration.Companion.days
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import nl.komponents.kovenant.Deferred import nl.komponents.kovenant.Deferred
import nl.komponents.kovenant.Promise 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.Namespace
import org.session.libsignal.utilities.Snode import org.session.libsignal.utilities.Snode
import org.session.libsignal.utilities.Util.SECURE_RANDOM 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" private const val TAG = "Poller"
@ -49,8 +49,9 @@ class Poller(
// region Settings // region Settings
companion object { companion object {
private const val retryInterval: Long = 2 * 1000 private const val RETRY_INTERVAL_MS: Long = 2 * 1000
private const val maxInterval: Long = 15 * 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 // endregion
@ -59,7 +60,7 @@ class Poller(
if (hasStarted) { return } if (hasStarted) { return }
Log.d(TAG, "Started polling.") Log.d(TAG, "Started polling.")
hasStarted = true hasStarted = true
setUpPolling(retryInterval) setUpPolling(RETRY_INTERVAL_MS)
} }
fun stopIfNeeded() { fun stopIfNeeded() {
@ -72,11 +73,11 @@ class Poller(
Log.d(TAG, "Retrieving user profile. for key = $userPublicKey") Log.d(TAG, "Retrieving user profile. for key = $userPublicKey")
SnodeAPI.getSwarm(userPublicKey).bind { SnodeAPI.getSwarm(userPublicKey).bind {
usedSnodes.clear() usedSnodes.clear()
deferred<Unit, Exception>().also { deferred<Unit, Exception>().also { exception ->
pollNextSnode(userProfileOnly = true, it) pollNextSnode(userProfileOnly = true, exception)
}.promise }.promise
}.fail { }.fail { exception ->
Log.e(TAG, "Failed to retrieve user profile.", it) Log.e(TAG, "Failed to retrieve user profile.", exception)
} }
} }
// endregion // endregion
@ -91,14 +92,14 @@ class Poller(
pollNextSnode(deferred = deferred) pollNextSnode(deferred = deferred)
deferred.promise deferred.promise
}.success { }.success {
val nextDelay = if (isCaughtUp) retryInterval else 0 val nextDelay = if (isCaughtUp) RETRY_INTERVAL_MS else 0
Timer().schedule(object : TimerTask() { Timer().schedule(object : TimerTask() {
override fun run() { override fun run() {
thread.run { setUpPolling(retryInterval) } thread.run { setUpPolling(RETRY_INTERVAL_MS) }
} }
}, nextDelay) }, nextDelay)
}.fail { }.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() { Timer().schedule(object : TimerTask() {
override fun run() { override fun run() {
thread.run { setUpPolling(nextDelay) } thread.run { setUpPolling(nextDelay) }
@ -232,7 +233,6 @@ class Poller(
} }
} }
private fun poll(snode: Snode, deferred: Deferred<Unit, Exception>): Promise<Unit, Exception> { private fun poll(snode: Snode, deferred: Deferred<Unit, Exception>): Promise<Unit, Exception> {
if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) } if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) }
return GlobalScope.asyncPromise { return GlobalScope.asyncPromise {

Loading…
Cancel
Save