kopia lustrzana https://github.com/ryukoposting/Signal-Android
Dynamically respond to notificationsV2 feature flag.
We were only reading it once, possibly before the flags were initialized. This lets us be more responsive to the flag changing within an application cycle.fork-5.53.8
rodzic
2547db2a8e
commit
cdddfd37d2
|
@ -142,6 +142,7 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
|
|||
}
|
||||
})
|
||||
.addBlocking("blob-provider", this::initializeBlobProvider)
|
||||
.addBlocking("feature-flags", FeatureFlags::init)
|
||||
.addNonBlocking(this::initializeRevealableMessageManager)
|
||||
.addNonBlocking(this::initializeGcmCheck)
|
||||
.addNonBlocking(this::initializeSignedPreKeyCheck)
|
||||
|
@ -150,7 +151,6 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
|
|||
.addNonBlocking(this::initializePendingMessages)
|
||||
.addNonBlocking(this::initializeCleanup)
|
||||
.addNonBlocking(this::initializeGlideCodecs)
|
||||
.addNonBlocking(FeatureFlags::init)
|
||||
.addNonBlocking(RefreshPreKeysJob::scheduleIfNecessary)
|
||||
.addNonBlocking(StorageSyncHelper::scheduleRoutineSync)
|
||||
.addNonBlocking(() -> ApplicationDependencies.getJobManager().beginJobLoop())
|
||||
|
|
|
@ -186,14 +186,7 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
|
|||
|
||||
@Override
|
||||
public @NonNull MessageNotifier provideMessageNotifier() {
|
||||
MessageNotifier inner;
|
||||
if (FeatureFlags.useNewNotificationSystem()) {
|
||||
inner = new MessageNotifierV2();
|
||||
} else {
|
||||
inner = new DefaultMessageNotifier();
|
||||
}
|
||||
|
||||
return new OptimizedMessageNotifier(inner);
|
||||
return new OptimizedMessageNotifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,8 +7,10 @@ import androidx.annotation.MainThread;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.thoughtcrime.securesms.notifications.v2.MessageNotifierV2;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.BubbleUtil;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.LeakyBucketLimiter;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
|
@ -17,73 +19,76 @@ import org.thoughtcrime.securesms.util.Util;
|
|||
*/
|
||||
public class OptimizedMessageNotifier implements MessageNotifier {
|
||||
|
||||
private final MessageNotifier wrapped;
|
||||
private final LeakyBucketLimiter limiter;
|
||||
|
||||
private final DefaultMessageNotifier messageNotifierV1;
|
||||
private final MessageNotifierV2 messageNotifierV2;
|
||||
|
||||
@MainThread
|
||||
public OptimizedMessageNotifier(@NonNull MessageNotifier wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
this.limiter = new LeakyBucketLimiter(5, 1000, new Handler(SignalExecutors.getAndStartHandlerThread("signal-notifier").getLooper()));
|
||||
public OptimizedMessageNotifier() {
|
||||
this.limiter = new LeakyBucketLimiter(5, 1000, new Handler(SignalExecutors.getAndStartHandlerThread("signal-notifier").getLooper()));
|
||||
this.messageNotifierV1 = new DefaultMessageNotifier();
|
||||
this.messageNotifierV2 = new MessageNotifierV2();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleThread(long threadId) {
|
||||
wrapped.setVisibleThread(threadId);
|
||||
getNotifier().setVisibleThread(threadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVisibleThread() {
|
||||
return wrapped.getVisibleThread();
|
||||
return getNotifier().getVisibleThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearVisibleThread() {
|
||||
wrapped.clearVisibleThread();
|
||||
getNotifier().clearVisibleThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastDesktopActivityTimestamp(long timestamp) {
|
||||
wrapped.setLastDesktopActivityTimestamp(timestamp);
|
||||
getNotifier().setLastDesktopActivityTimestamp(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyMessageDeliveryFailed(Context context, Recipient recipient, long threadId) {
|
||||
wrapped.notifyMessageDeliveryFailed(context, recipient, threadId);
|
||||
getNotifier().notifyMessageDeliveryFailed(context, recipient, threadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelDelayedNotifications() {
|
||||
wrapped.cancelDelayedNotifications();
|
||||
getNotifier().cancelDelayedNotifications();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotification(@NonNull Context context) {
|
||||
runOnLimiter(() -> wrapped.updateNotification(context));
|
||||
runOnLimiter(() -> getNotifier().updateNotification(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotification(@NonNull Context context, long threadId) {
|
||||
runOnLimiter(() -> wrapped.updateNotification(context, threadId));
|
||||
runOnLimiter(() -> getNotifier().updateNotification(context, threadId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotification(@NonNull Context context, long threadId, @NonNull BubbleUtil.BubbleState defaultBubbleState) {
|
||||
runOnLimiter(() -> wrapped.updateNotification(context, threadId, defaultBubbleState));
|
||||
runOnLimiter(() -> getNotifier().updateNotification(context, threadId, defaultBubbleState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotification(@NonNull Context context, long threadId, boolean signal) {
|
||||
runOnLimiter(() -> wrapped.updateNotification(context, threadId, signal));
|
||||
runOnLimiter(() -> getNotifier().updateNotification(context, threadId, signal));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotification(@NonNull Context context, long threadId, boolean signal, int reminderCount, @NonNull BubbleUtil.BubbleState defaultBubbleState) {
|
||||
runOnLimiter(() -> wrapped.updateNotification(context, threadId, signal, reminderCount, defaultBubbleState));
|
||||
runOnLimiter(() -> getNotifier().updateNotification(context, threadId, signal, reminderCount, defaultBubbleState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearReminder(@NonNull Context context) {
|
||||
wrapped.clearReminder(context);
|
||||
getNotifier().clearReminder(context);
|
||||
}
|
||||
|
||||
private void runOnLimiter(@NonNull Runnable runnable) {
|
||||
|
@ -96,4 +101,12 @@ public class OptimizedMessageNotifier implements MessageNotifier {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private MessageNotifier getNotifier() {
|
||||
if (FeatureFlags.useNewNotificationSystem()) {
|
||||
return messageNotifierV2;
|
||||
} else {
|
||||
return messageNotifierV1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue