mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Clean
This commit is contained in:
parent
2a88de3f61
commit
d09171213d
@ -226,9 +226,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
executePendingContactSync();
|
executePendingContactSync();
|
||||||
KeyCachingService.onAppForegrounded(this);
|
KeyCachingService.onAppForegrounded(this);
|
||||||
// Loki
|
// Loki
|
||||||
if (lokiPoller != null) { lokiPoller.shouldCatchUp(); }
|
if (lokiPoller != null) { lokiPoller.setCaughtUp(false); }
|
||||||
startPollingIfNeeded();
|
startPollingIfNeeded();
|
||||||
lokiPublicChatManager.shouldAllCatchUp();
|
lokiPublicChatManager.markAllAsNotCaughtUp();
|
||||||
lokiPublicChatManager.startPollersIfNeeded();
|
lokiPublicChatManager.startPollersIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
private long messageId;
|
private long messageId;
|
||||||
private long smsMessageId;
|
private long smsMessageId;
|
||||||
|
|
||||||
//Loki
|
|
||||||
private MessageNotifier messageNotifier;
|
private MessageNotifier messageNotifier;
|
||||||
|
|
||||||
@Inject SignalServiceMessageSender messageSender;
|
@Inject SignalServiceMessageSender messageSender;
|
||||||
|
@ -20,21 +20,21 @@ class LokiPublicChatManager(private val context: Context) {
|
|||||||
private val observers = mutableMapOf<Long, ContentObserver>()
|
private val observers = mutableMapOf<Long, ContentObserver>()
|
||||||
private var isPolling = false
|
private var isPolling = false
|
||||||
|
|
||||||
public fun isAllCatchUp():Boolean {
|
public fun areAllCaughtUp():Boolean {
|
||||||
var isAllCatchUp = true
|
var areAllCaughtUp = true
|
||||||
refreshChatsAndPollers()
|
refreshChatsAndPollers()
|
||||||
for ((threadId, chat) in chats) {
|
for ((threadID, chat) in chats) {
|
||||||
val poller = pollers[threadId] ?: LokiPublicChatPoller(context, chat)
|
val poller = pollers[threadID] ?: LokiPublicChatPoller(context, chat)
|
||||||
isAllCatchUp = isAllCatchUp() && poller.isCatchUp()
|
areAllCaughtUp = areAllCaughtUp && poller.isCaughtUp
|
||||||
}
|
}
|
||||||
return isAllCatchUp
|
return areAllCaughtUp
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun shouldAllCatchUp() {
|
public fun markAllAsNotCaughtUp() {
|
||||||
refreshChatsAndPollers()
|
refreshChatsAndPollers()
|
||||||
for ((threadId, chat) in chats) {
|
for ((threadID, chat) in chats) {
|
||||||
val poller = pollers[threadId] ?: LokiPublicChatPoller(context, chat)
|
val poller = pollers[threadID] ?: LokiPublicChatPoller(context, chat)
|
||||||
poller.shouldCatchUp()
|
poller.isCaughtUp = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,7 @@ import java.util.*
|
|||||||
class LokiPublicChatPoller(private val context: Context, private val group: LokiPublicChat) {
|
class LokiPublicChatPoller(private val context: Context, private val group: LokiPublicChat) {
|
||||||
private val handler = Handler()
|
private val handler = Handler()
|
||||||
private var hasStarted = false
|
private var hasStarted = false
|
||||||
|
public var isCaughtUp = false
|
||||||
private var isCatchUp = false
|
|
||||||
|
|
||||||
// region Convenience
|
// region Convenience
|
||||||
private val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
private val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||||
@ -84,14 +83,6 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki
|
|||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
fun isCatchUp(): Boolean {
|
|
||||||
return isCatchUp
|
|
||||||
}
|
|
||||||
|
|
||||||
fun shouldCatchUp() {
|
|
||||||
isCatchUp = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// region Settings
|
// region Settings
|
||||||
companion object {
|
companion object {
|
||||||
private val pollForNewMessagesInterval: Long = 4 * 1000
|
private val pollForNewMessagesInterval: Long = 4 * 1000
|
||||||
@ -259,7 +250,7 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki
|
|||||||
processIncomingMessage(message)
|
processIncomingMessage(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isCatchUp = true
|
isCaughtUp = true
|
||||||
}.fail {
|
}.fail {
|
||||||
Log.d("Loki", "Failed to get messages for group chat with ID: ${group.channel} on server: ${group.server}.")
|
Log.d("Loki", "Failed to get messages for group chat with ID: ${group.channel} on server: ${group.server}.")
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,17 @@ package org.thoughtcrime.securesms.notifications;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.MainThread;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.ApplicationContext;
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
import org.thoughtcrime.securesms.loki.api.LokiPublicChatManager;
|
import org.thoughtcrime.securesms.loki.api.LokiPublicChatManager;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.util.Debouncer;
|
import org.thoughtcrime.securesms.util.Debouncer;
|
||||||
import org.thoughtcrime.securesms.util.Throttler;
|
|
||||||
import org.whispersystems.signalservice.loki.api.LokiPoller;
|
import org.whispersystems.signalservice.loki.api.LokiPoller;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import androidx.annotation.MainThread;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
public class OptimizedMessageNotifier implements MessageNotifier {
|
public class OptimizedMessageNotifier implements MessageNotifier {
|
||||||
private final MessageNotifier wrapped;
|
private final MessageNotifier wrapped;
|
||||||
private final Debouncer debouncer;
|
private final Debouncer debouncer;
|
||||||
@ -42,12 +41,12 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
public void updateNotification(@NonNull Context context) {
|
public void updateNotification(@NonNull Context context) {
|
||||||
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
Boolean isCatchUp = false;
|
Boolean isCaughtUp = false;
|
||||||
if (lokiPoller != null && lokiPublicChatManager != null) {
|
if (lokiPoller != null && lokiPublicChatManager != null) {
|
||||||
isCatchUp = lokiPoller.isCatchUp() && lokiPublicChatManager.isAllCatchUp();
|
isCaughtUp = lokiPoller.isCaughtUp() && lokiPublicChatManager.areAllCaughtUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCatchUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context);
|
wrapped.updateNotification(context);
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context));
|
debouncer.publish(() -> wrapped.updateNotification(context));
|
||||||
@ -58,12 +57,12 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
public void updateNotification(@NonNull Context context, long threadId) {
|
public void updateNotification(@NonNull Context context, long threadId) {
|
||||||
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
Boolean isCatchUp = false;
|
Boolean isCaughtUp = false;
|
||||||
if (lokiPoller != null && lokiPublicChatManager != null) {
|
if (lokiPoller != null && lokiPublicChatManager != null) {
|
||||||
isCatchUp = lokiPoller.isCatchUp() && lokiPublicChatManager.isAllCatchUp();
|
isCaughtUp = lokiPoller.isCaughtUp() && lokiPublicChatManager.areAllCaughtUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCatchUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context, threadId);
|
wrapped.updateNotification(context, threadId);
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context, threadId));
|
debouncer.publish(() -> wrapped.updateNotification(context, threadId));
|
||||||
@ -74,12 +73,12 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
public void updateNotification(@NonNull Context context, long threadId, boolean signal) {
|
public void updateNotification(@NonNull Context context, long threadId, boolean signal) {
|
||||||
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
Boolean isCatchUp = false;
|
Boolean isCaughtUp = false;
|
||||||
if (lokiPoller != null && lokiPublicChatManager != null) {
|
if (lokiPoller != null && lokiPublicChatManager != null) {
|
||||||
isCatchUp = lokiPoller.isCatchUp() && lokiPublicChatManager.isAllCatchUp();
|
isCaughtUp = lokiPoller.isCaughtUp() && lokiPublicChatManager.areAllCaughtUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCatchUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context, threadId, signal);
|
wrapped.updateNotification(context, threadId, signal);
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context, threadId, signal));
|
debouncer.publish(() -> wrapped.updateNotification(context, threadId, signal));
|
||||||
@ -90,19 +89,18 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
public void updateNotification(@android.support.annotation.NonNull Context context, boolean signal, int reminderCount) {
|
public void updateNotification(@android.support.annotation.NonNull Context context, boolean signal, int reminderCount) {
|
||||||
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
LokiPoller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
Boolean isCatchUp = false;
|
Boolean isCaughtUp = false;
|
||||||
if (lokiPoller != null && lokiPublicChatManager != null) {
|
if (lokiPoller != null && lokiPublicChatManager != null) {
|
||||||
isCatchUp = lokiPoller.isCatchUp() && lokiPublicChatManager.isAllCatchUp();
|
isCaughtUp = lokiPoller.isCaughtUp() && lokiPublicChatManager.areAllCaughtUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCatchUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context, signal, reminderCount);
|
wrapped.updateNotification(context, signal, reminderCount);
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context, signal, reminderCount));
|
debouncer.publish(() -> wrapped.updateNotification(context, signal, reminderCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearReminder(@NonNull Context context) { wrapped.clearReminder(context); }
|
public void clearReminder(@NonNull Context context) { wrapped.clearReminder(context); }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user