Fix improper notifications when delaying for linked device activity.

This commit is contained in:
Cody Henthorne
2024-01-03 11:10:16 -05:00
committed by Clark Chen
parent 549ef9dabc
commit 3fa3b93c85
8 changed files with 16 additions and 61 deletions

View File

@@ -206,7 +206,7 @@ object ContactDiscovery {
.forEach { result ->
val hour = Calendar.getInstance()[Calendar.HOUR_OF_DAY]
if (hour in 9..22) {
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.forConversation(result.threadId), true)
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.forConversation(result.threadId))
} else {
Log.i(TAG, "Not notifying of a new user due to the time of day. (Hour: $hour)")
}

View File

@@ -522,7 +522,7 @@ object DataMessageProcessor {
} else {
val reactionRecord = ReactionRecord(emoji!!, senderRecipientId, message.timestamp!!, System.currentTimeMillis())
SignalDatabase.reactions.addReaction(targetMessageId, reactionRecord)
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.fromMessageRecord(targetMessage), false)
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.fromMessageRecord(targetMessage))
}
return targetMessageId
@@ -542,7 +542,7 @@ object DataMessageProcessor {
SignalDatabase.messages.deleteRemotelyDeletedStory(targetMessage.id)
}
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.fromMessageRecord(targetMessage), false)
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.fromMessageRecord(targetMessage))
MessageId(targetMessage.id)
} else if (targetMessage == null) {

View File

@@ -24,7 +24,6 @@ public class DeleteNotificationReceiver extends BroadcastReceiver {
public void onReceive(final Context context, Intent intent) {
if (DELETE_NOTIFICATION_ACTION.equals(intent.getAction())) {
MessageNotifier notifier = ApplicationDependencies.getMessageNotifier();
notifier.clearReminder(context);
final long[] ids = intent.getLongArrayExtra(EXTRA_IDS);
final boolean[] mms = intent.getBooleanArrayExtra(EXTRA_MMS);

View File

@@ -26,21 +26,15 @@ public interface MessageNotifier {
void cancelDelayedNotifications();
void updateNotification(@NonNull Context context);
void updateNotification(@NonNull Context context, @NonNull ConversationId conversationId);
void updateNotification(@NonNull Context context, @NonNull ConversationId conversationId, @NonNull BubbleUtil.BubbleState defaultBubbleState);
void updateNotification(@NonNull Context context, @NonNull ConversationId conversationId, boolean signal);
void updateNotification(@NonNull Context context, @Nullable ConversationId conversationId, boolean signal, int reminderCount, @NonNull BubbleUtil.BubbleState defaultBubbleState);
void clearReminder(@NonNull Context context);
void forceBubbleNotification(@NonNull Context context, @NonNull ConversationId conversationId);
void addStickyThread(@NonNull ConversationId conversationId, long earliestTimestamp);
void removeStickyThread(@NonNull ConversationId conversationId);
class ReminderReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
SignalExecutors.BOUNDED.execute(() -> {
int reminderCount = intent.getIntExtra("reminder_count", 0);
ApplicationDependencies.getMessageNotifier().updateNotification(context, null, true, reminderCount + 1, BubbleUtil.BubbleState.HIDDEN);
ApplicationDependencies.getMessageNotifier().updateNotification(context);
});
}
}

View File

@@ -30,7 +30,6 @@ public class OptimizedMessageNotifier implements MessageNotifier {
private static final String DEDUPE_KEY_GENERAL = "MESSAGE_NOTIFIER_DEFAULT";
private static final String DEDUPE_KEY_CHAT = "MESSAGE_NOTIFIER_CHAT_";
private static final String DEDUPE_KEY_CANCEL_DELAYED = "MESSAGE_NOTIFIER_CANCEL_DELAYED";
@MainThread
public OptimizedMessageNotifier(@NonNull Application context) {
@@ -81,9 +80,7 @@ public class OptimizedMessageNotifier implements MessageNotifier {
@Override
public void cancelDelayedNotifications() {
SignalDatabase.runPostSuccessfulTransaction(DEDUPE_KEY_CANCEL_DELAYED, () -> {
getNotifier().cancelDelayedNotifications();
});
getNotifier().cancelDelayedNotifications();
}
@Override
@@ -101,30 +98,9 @@ public class OptimizedMessageNotifier implements MessageNotifier {
}
@Override
public void updateNotification(@NonNull Context context, @NonNull ConversationId conversationId, @NonNull BubbleUtil.BubbleState defaultBubbleState) {
public void forceBubbleNotification(@NonNull Context context, @NonNull ConversationId conversationId) {
SignalDatabase.runPostSuccessfulTransaction(() -> {
runOnLimiter(() -> getNotifier().updateNotification(context, conversationId, defaultBubbleState));
});
}
@Override
public void updateNotification(@NonNull Context context, @NonNull ConversationId conversationId, boolean signal) {
SignalDatabase.runPostSuccessfulTransaction(() -> {
runOnLimiter(() -> getNotifier().updateNotification(context, conversationId, signal));
});
}
@Override
public void updateNotification(@NonNull Context context, @Nullable ConversationId conversationId, boolean signal, int reminderCount, @NonNull BubbleUtil.BubbleState defaultBubbleState) {
SignalDatabase.runPostSuccessfulTransaction(() -> {
runOnLimiter(() -> getNotifier().updateNotification(context, conversationId, signal, reminderCount, defaultBubbleState));
});
}
@Override
public void clearReminder(@NonNull Context context) {
SignalDatabase.runPostSuccessfulTransaction(() -> {
getNotifier().clearReminder(context);
runOnLimiter(() -> getNotifier().forceBubbleNotification(context, conversationId));
});
}

View File

@@ -102,7 +102,7 @@ class DefaultMessageNotifier(context: Application) : MessageNotifier {
}
override fun updateNotification(context: Context) {
updateNotification(context, null, false, 0, BubbleState.HIDDEN)
updateNotification(context, null, BubbleState.HIDDEN)
}
override fun updateNotification(context: Context, conversationId: ConversationId) {
@@ -110,27 +110,17 @@ class DefaultMessageNotifier(context: Application) : MessageNotifier {
Log.i(TAG, "Scheduling delayed notification...")
executor.enqueue(context, conversationId)
} else {
updateNotification(context, conversationId, true)
updateNotification(context, conversationId, BubbleState.HIDDEN)
}
}
override fun updateNotification(context: Context, conversationId: ConversationId, defaultBubbleState: BubbleState) {
updateNotification(context, conversationId, false, 0, defaultBubbleState)
override fun forceBubbleNotification(context: Context, conversationId: ConversationId) {
updateNotification(context, conversationId, BubbleState.SHOWN)
}
override fun updateNotification(context: Context, conversationId: ConversationId, signal: Boolean) {
updateNotification(context, conversationId, signal, 0, BubbleState.HIDDEN)
}
/**
* @param signal is no longer used
* @param reminderCount is not longer used
*/
override fun updateNotification(
private fun updateNotification(
context: Context,
conversationId: ConversationId?,
signal: Boolean,
reminderCount: Int,
defaultBubbleState: BubbleState
) {
NotificationChannels.getInstance().ensureCustomChannelConsistency()
@@ -240,10 +230,6 @@ class DefaultMessageNotifier(context: Application) : MessageNotifier {
}
}
override fun clearReminder(context: Context) {
// Intentionally left blank
}
override fun addStickyThread(conversationId: ConversationId, earliestTimestamp: Long) {
stickyThreads[conversationId] = StickyThread(conversationId, NotificationIds.getNotificationIdForThread(conversationId), earliestTimestamp)
}
@@ -409,8 +395,8 @@ private class CancelableExecutor {
}
if (!canceled.get()) {
Log.i(TAG, "Not canceled, notifying...")
ApplicationDependencies.getMessageNotifier().updateNotification(context, thread, true)
ApplicationDependencies.getMessageNotifier().cancelDelayedNotifications()
ApplicationDependencies.getMessageNotifier().updateNotification(context, thread)
} else {
Log.w(TAG, "Canceled, not notifying...")
}

View File

@@ -459,7 +459,7 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
peekInfo.getJoinedMembers(),
WebRtcUtil.isCallFull(peekInfo));
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.forConversation(threadId), true, 0, BubbleUtil.BubbleState.HIDDEN);
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.forConversation(threadId));
EventBus.getDefault().postSticky(new GroupCallPeekEvent(id, peekInfo.getEraId(), peekInfo.getDeviceCount(), peekInfo.getMaxDevices()));
}

View File

@@ -120,7 +120,7 @@ public final class BubbleUtil {
.orElse(null);
if (activeThreadNotification != null && activeThreadNotification.deleteIntent != null) {
ApplicationDependencies.getMessageNotifier().updateNotification(context, conversationId, BubbleState.SHOWN);
ApplicationDependencies.getMessageNotifier().forceBubbleNotification(context, conversationId);
} else {
Recipient recipient = Recipient.resolved(recipientId);
NotificationFactory.notifyToBubbleConversation(context, recipient, threadId);