mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-02 14:35:21 +00:00
new approach for batch notification
This commit is contained in:
parent
b2827184a8
commit
6822bc461c
@ -207,7 +207,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
}
|
}
|
||||||
startPollingIfNeeded();
|
startPollingIfNeeded();
|
||||||
|
|
||||||
OpenGroupManager.INSTANCE.markAllAsNotCaughtUp();
|
OpenGroupManager.INSTANCE.setAllCaughtUp(false);
|
||||||
OpenGroupManager.INSTANCE.startPolling();
|
OpenGroupManager.INSTANCE.startPolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,21 +19,7 @@ object OpenGroupManager {
|
|||||||
private var pollers = mutableMapOf<String, OpenGroupPollerV2>() // One for each server
|
private var pollers = mutableMapOf<String, OpenGroupPollerV2>() // One for each server
|
||||||
private var isPolling = false
|
private var isPolling = false
|
||||||
|
|
||||||
val isAllCaughtUp: Boolean
|
var isAllCaughtUp = false
|
||||||
get() {
|
|
||||||
pollers.values.forEach { poller ->
|
|
||||||
if (!poller.isCaughtUp) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun markAllAsNotCaughtUp() {
|
|
||||||
pollers.values.forEach { poller ->
|
|
||||||
poller.isCaughtUp = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startPolling() {
|
fun startPolling() {
|
||||||
if (isPolling) { return }
|
if (isPolling) { return }
|
||||||
|
@ -56,6 +56,7 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
|
|||||||
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
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.protocol.SessionMetaProtocol;
|
||||||
import org.thoughtcrime.securesms.loki.utilities.MentionUtilities;
|
import org.thoughtcrime.securesms.loki.utilities.MentionUtilities;
|
||||||
import org.thoughtcrime.securesms.mms.SlideDeck;
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||||
@ -286,6 +287,9 @@ public class DefaultMessageNotifier implements MessageNotifier {
|
|||||||
} finally {
|
} finally {
|
||||||
if (telcoCursor != null) telcoCursor.close();
|
if (telcoCursor != null) telcoCursor.close();
|
||||||
if (pushCursor != null) pushCursor.close();
|
if (pushCursor != null) pushCursor.close();
|
||||||
|
if (!OpenGroupManager.INSTANCE.isAllCaughtUp()) {
|
||||||
|
OpenGroupManager.INSTANCE.setAllCaughtUp(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
@MainThread
|
@MainThread
|
||||||
public OptimizedMessageNotifier(@NonNull MessageNotifier wrapped) {
|
public OptimizedMessageNotifier(@NonNull MessageNotifier wrapped) {
|
||||||
this.wrapped = wrapped;
|
this.wrapped = wrapped;
|
||||||
this.debouncer = new Debouncer(TimeUnit.SECONDS.toMillis(2));
|
this.debouncer = new Debouncer(TimeUnit.SECONDS.toMillis(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,7 +18,6 @@ import java.util.concurrent.TimeUnit
|
|||||||
|
|
||||||
class OpenGroupPollerV2(private val server: String, private val executorService: ScheduledExecutorService?) {
|
class OpenGroupPollerV2(private val server: String, private val executorService: ScheduledExecutorService?) {
|
||||||
var hasStarted = false
|
var hasStarted = false
|
||||||
var isCaughtUp = false
|
|
||||||
private var future: ScheduledFuture<*>? = null
|
private var future: ScheduledFuture<*>? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -45,7 +44,6 @@ class OpenGroupPollerV2(private val server: String, private val executorService:
|
|||||||
handleNewMessages(openGroupID, response.messages, isBackgroundPoll)
|
handleNewMessages(openGroupID, response.messages, isBackgroundPoll)
|
||||||
handleDeletedMessages(openGroupID, response.deletions)
|
handleDeletedMessages(openGroupID, response.deletions)
|
||||||
}
|
}
|
||||||
isCaughtUp = true
|
|
||||||
}.always {
|
}.always {
|
||||||
executorService?.schedule(this@OpenGroupPollerV2::poll, OpenGroupPollerV2.pollInterval, TimeUnit.MILLISECONDS)
|
executorService?.schedule(this@OpenGroupPollerV2::poll, OpenGroupPollerV2.pollInterval, TimeUnit.MILLISECONDS)
|
||||||
}.map { }
|
}.map { }
|
||||||
|
Loading…
Reference in New Issue
Block a user