new approach for batch notification

This commit is contained in:
Ryan ZHAO 2021-05-20 15:41:17 +10:00
parent b2827184a8
commit 6822bc461c
5 changed files with 7 additions and 19 deletions

View File

@ -207,7 +207,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
startPollingIfNeeded();
OpenGroupManager.INSTANCE.markAllAsNotCaughtUp();
OpenGroupManager.INSTANCE.setAllCaughtUp(false);
OpenGroupManager.INSTANCE.startPolling();
}

View File

@ -19,21 +19,7 @@ object OpenGroupManager {
private var pollers = mutableMapOf<String, OpenGroupPollerV2>() // One for each server
private var isPolling = false
val isAllCaughtUp: Boolean
get() {
pollers.values.forEach { poller ->
if (!poller.isCaughtUp) {
return false
}
}
return true
}
fun markAllAsNotCaughtUp() {
pollers.values.forEach { poller ->
poller.isCaughtUp = false
}
}
var isAllCaughtUp = false
fun startPolling() {
if (isPolling) { return }

View File

@ -56,6 +56,7 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
import org.thoughtcrime.securesms.loki.api.OpenGroupManager;
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
import org.thoughtcrime.securesms.loki.utilities.MentionUtilities;
import org.thoughtcrime.securesms.mms.SlideDeck;
@ -286,6 +287,9 @@ public class DefaultMessageNotifier implements MessageNotifier {
} finally {
if (telcoCursor != null) telcoCursor.close();
if (pushCursor != null) pushCursor.close();
if (!OpenGroupManager.INSTANCE.isAllCaughtUp()) {
OpenGroupManager.INSTANCE.setAllCaughtUp(true);
}
}
}

View File

@ -23,7 +23,7 @@ public class OptimizedMessageNotifier implements MessageNotifier {
@MainThread
public OptimizedMessageNotifier(@NonNull MessageNotifier wrapped) {
this.wrapped = wrapped;
this.debouncer = new Debouncer(TimeUnit.SECONDS.toMillis(2));
this.debouncer = new Debouncer(TimeUnit.SECONDS.toMillis(1));
}
@Override

View File

@ -18,7 +18,6 @@ import java.util.concurrent.TimeUnit
class OpenGroupPollerV2(private val server: String, private val executorService: ScheduledExecutorService?) {
var hasStarted = false
var isCaughtUp = false
private var future: ScheduledFuture<*>? = null
companion object {
@ -45,7 +44,6 @@ class OpenGroupPollerV2(private val server: String, private val executorService:
handleNewMessages(openGroupID, response.messages, isBackgroundPoll)
handleDeletedMessages(openGroupID, response.deletions)
}
isCaughtUp = true
}.always {
executorService?.schedule(this@OpenGroupPollerV2::poll, OpenGroupPollerV2.pollInterval, TimeUnit.MILLISECONDS)
}.map { }