mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 16:44:10 +00:00
Unify background pollers and reduce polling interval
We were getting rate limited
This commit is contained in:
@@ -673,11 +673,6 @@
|
|||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver android:name="org.thoughtcrime.securesms.loki.api.BackgroundOpenGroupPollWorker">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
<!-- Session -->
|
<!-- Session -->
|
||||||
<service
|
<service
|
||||||
android:name="org.thoughtcrime.securesms.jobmanager.JobSchedulerScheduler$SystemService"
|
android:name="org.thoughtcrime.securesms.jobmanager.JobSchedulerScheduler$SystemService"
|
||||||
|
@@ -59,7 +59,6 @@ import org.thoughtcrime.securesms.logging.Log;
|
|||||||
import org.thoughtcrime.securesms.logging.PersistentLogger;
|
import org.thoughtcrime.securesms.logging.PersistentLogger;
|
||||||
import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger;
|
import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger;
|
||||||
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
||||||
import org.thoughtcrime.securesms.loki.api.BackgroundOpenGroupPollWorker;
|
|
||||||
import org.thoughtcrime.securesms.loki.api.BackgroundPollWorker;
|
import org.thoughtcrime.securesms.loki.api.BackgroundPollWorker;
|
||||||
import org.thoughtcrime.securesms.loki.api.LokiPublicChatManager;
|
import org.thoughtcrime.securesms.loki.api.LokiPublicChatManager;
|
||||||
import org.thoughtcrime.securesms.loki.api.LokiPushNotificationManager;
|
import org.thoughtcrime.securesms.loki.api.LokiPushNotificationManager;
|
||||||
@@ -366,7 +365,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
LocalBackupListener.schedule(this);
|
LocalBackupListener.schedule(this);
|
||||||
RotateSenderCertificateListener.schedule(this);
|
RotateSenderCertificateListener.schedule(this);
|
||||||
BackgroundPollWorker.schedule(this); // Loki
|
BackgroundPollWorker.schedule(this); // Loki
|
||||||
BackgroundOpenGroupPollWorker.schedule(this); // Loki
|
|
||||||
|
|
||||||
if (BuildConfig.PLAY_STORE_DISABLED) {
|
if (BuildConfig.PLAY_STORE_DISABLED) {
|
||||||
UpdateApkRefreshListener.schedule(this);
|
UpdateApkRefreshListener.schedule(this);
|
||||||
|
@@ -1,38 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.loki.api
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
|
||||||
import org.thoughtcrime.securesms.service.PersistentAlarmManagerListener
|
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class BackgroundOpenGroupPollWorker : PersistentAlarmManagerListener() {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val pollInterval = TimeUnit.MINUTES.toMillis(4)
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun schedule(context: Context) {
|
|
||||||
BackgroundOpenGroupPollWorker().onReceive(context, Intent())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getNextScheduledExecutionTime(context: Context): Long {
|
|
||||||
return TextSecurePreferences.getOpenGroupBackgroundPollTime(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAlarm(context: Context, scheduledTime: Long): Long {
|
|
||||||
if (scheduledTime != 0L) {
|
|
||||||
val openGroups = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChats().map { it.value }
|
|
||||||
for (openGroup in openGroups) {
|
|
||||||
val poller = LokiPublicChatPoller(context, openGroup)
|
|
||||||
poller.stop()
|
|
||||||
poller.pollForNewMessages()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val nextTime = System.currentTimeMillis() + pollInterval
|
|
||||||
TextSecurePreferences.setOpenGroupBackgroundPollTime(context, nextTime)
|
|
||||||
return nextTime
|
|
||||||
}
|
|
||||||
}
|
|
@@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit
|
|||||||
class BackgroundPollWorker : PersistentAlarmManagerListener() {
|
class BackgroundPollWorker : PersistentAlarmManagerListener() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val pollInterval = TimeUnit.MINUTES.toMillis(2)
|
private val pollInterval = TimeUnit.MINUTES.toMillis(10)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun schedule(context: Context) {
|
fun schedule(context: Context) {
|
||||||
@@ -28,14 +28,14 @@ class BackgroundPollWorker : PersistentAlarmManagerListener() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onAlarm(context: Context, scheduledTime: Long): Long {
|
override fun onAlarm(context: Context, scheduledTime: Long): Long {
|
||||||
if (TextSecurePreferences.isUsingFCM(context)) { return 0L }
|
|
||||||
if (scheduledTime != 0L) {
|
if (scheduledTime != 0L) {
|
||||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
if (TextSecurePreferences.isUsingFCM(context)) {
|
||||||
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||||
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||||
try {
|
try {
|
||||||
val applicationContext = context.applicationContext as ApplicationContext
|
val applicationContext = context.applicationContext as ApplicationContext
|
||||||
val broadcaster = applicationContext.broadcaster
|
val broadcaster = applicationContext.broadcaster
|
||||||
LokiAPI.configureIfNeeded(userHexEncodedPublicKey, lokiAPIDatabase, broadcaster)
|
LokiAPI.configureIfNeeded(userPublicKey, lokiAPIDatabase, broadcaster)
|
||||||
LokiAPI.shared.getMessages().map { messages ->
|
LokiAPI.shared.getMessages().map { messages ->
|
||||||
messages.forEach {
|
messages.forEach {
|
||||||
PushContentReceiveJob(context).processEnvelope(SignalServiceEnvelope(it), false)
|
PushContentReceiveJob(context).processEnvelope(SignalServiceEnvelope(it), false)
|
||||||
@@ -45,6 +45,13 @@ class BackgroundPollWorker : PersistentAlarmManagerListener() {
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val openGroups = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChats().map { it.value }
|
||||||
|
for (openGroup in openGroups) {
|
||||||
|
val poller = LokiPublicChatPoller(context, openGroup)
|
||||||
|
poller.stop()
|
||||||
|
poller.pollForNewMessages()
|
||||||
|
}
|
||||||
|
}
|
||||||
val nextTime = System.currentTimeMillis() + pollInterval
|
val nextTime = System.currentTimeMillis() + pollInterval
|
||||||
TextSecurePreferences.setBackgroundPollTime(context, nextTime)
|
TextSecurePreferences.setBackgroundPollTime(context, nextTime)
|
||||||
return nextTime
|
return nextTime
|
||||||
|
Reference in New Issue
Block a user