mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-02 14:35:21 +00:00
Fix crash & friend request handling bug
This commit is contained in:
parent
7afb763576
commit
bc71bf50aa
@ -14,8 +14,6 @@ import org.whispersystems.signalservice.loki.api.Poller;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import network.loki.messenger.BuildConfig;
|
|
||||||
|
|
||||||
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,9 +40,6 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateNotification(@NonNull Context context) {
|
public void updateNotification(@NonNull Context context) {
|
||||||
if (BuildConfig.DEBUG && Looper.myLooper() != Looper.getMainLooper()) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
boolean isCaughtUp = false;
|
boolean isCaughtUp = false;
|
||||||
@ -53,17 +48,14 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCaughtUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context);
|
performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context));
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context));
|
debouncer.publish(() -> performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateNotification(@NonNull Context context, long threadId) {
|
public void updateNotification(@NonNull Context context, long threadId) {
|
||||||
if (BuildConfig.DEBUG && Looper.myLooper() != Looper.getMainLooper()) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
boolean isCaughtUp = false;
|
boolean isCaughtUp = false;
|
||||||
@ -72,17 +64,14 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCaughtUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context, threadId);
|
performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, threadId));
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context, threadId));
|
debouncer.publish(() -> performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, threadId)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateNotification(@NonNull Context context, long threadId, boolean signal) {
|
public void updateNotification(@NonNull Context context, long threadId, boolean signal) {
|
||||||
if (BuildConfig.DEBUG && Looper.myLooper() != Looper.getMainLooper()) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
boolean isCaughtUp = false;
|
boolean isCaughtUp = false;
|
||||||
@ -91,17 +80,14 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCaughtUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context, threadId, signal);
|
performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, threadId, signal));
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context, threadId, signal));
|
debouncer.publish(() -> performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, threadId, signal)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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) {
|
||||||
if (BuildConfig.DEBUG && Looper.myLooper() != Looper.getMainLooper()) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
Poller lokiPoller = ApplicationContext.getInstance(context).lokiPoller;
|
||||||
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
LokiPublicChatManager lokiPublicChatManager = ApplicationContext.getInstance(context).lokiPublicChatManager;
|
||||||
boolean isCaughtUp = false;
|
boolean isCaughtUp = false;
|
||||||
@ -110,12 +96,20 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCaughtUp) {
|
if (isCaughtUp) {
|
||||||
wrapped.updateNotification(context, signal, reminderCount);
|
performOnBackgroundThreadIfNeeded(() -> wrapped.updateNotification(context, signal, reminderCount));
|
||||||
} else {
|
} else {
|
||||||
debouncer.publish(() -> wrapped.updateNotification(context, signal, reminderCount));
|
debouncer.publish(() -> performOnBackgroundThreadIfNeeded(() -> 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); }
|
||||||
|
|
||||||
|
private void performOnBackgroundThreadIfNeeded(Runnable r) {
|
||||||
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
|
new Thread(r).start();
|
||||||
|
} else {
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user