From 2ec50b576f563cffc59a25c1f3ba65818c9763b0 Mon Sep 17 00:00:00 2001 From: Al Lansley Date: Fri, 6 Dec 2024 08:34:02 +1100 Subject: [PATCH] Fix minor issue --- .../notifications/DefaultMessageNotifier.kt | 8 +-- .../notifications/NotificationState.java | 72 +++++++------------ .../sending_receiving/pollers/Poller.kt | 2 +- 3 files changed, 32 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt index 60d1085d01..774d227ef9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt @@ -224,14 +224,14 @@ class DefaultMessageNotifier : MessageNotifier { sendSingleThreadNotification(context, NotificationState(notificationState.getNotificationsForThread(threadId)), false, true) } sendMultipleThreadNotification(context, notificationState, playNotificationAudio) - } else if (notificationState.messageCount > 0) { + } else if (notificationState.notificationCount > 0) { sendSingleThreadNotification(context, notificationState, playNotificationAudio, false) } else { cancelActiveNotifications(context) } cancelOrphanedNotifications(context, notificationState) - updateBadge(context, notificationState.messageCount) + updateBadge(context, notificationState.notificationCount) if (playNotificationAudio) { scheduleReminder(context, reminderCount) @@ -289,7 +289,7 @@ class DefaultMessageNotifier : MessageNotifier { if (ApplicationContext.isAppVisible && notificationText == missedCallString) { return } builder.setThread(notifications[0].recipient) - builder.setMessageCount(notificationState.messageCount) + builder.setMessageCount(notificationState.notificationCount) val builderCS = notificationText ?: "" val ss = highlightMentions( @@ -385,7 +385,7 @@ class DefaultMessageNotifier : MessageNotifier { val builder = MultipleRecipientNotificationBuilder(context, getNotificationPrivacy(context)) val notifications = notificationState.notifications - builder.setMessageCount(notificationState.messageCount, notificationState.threadCount) + builder.setMessageCount(notificationState.notificationCount, notificationState.threadCount) builder.setMostRecentSender(notifications[0].individualRecipient, notifications[0].recipient) builder.setGroup(NOTIFICATION_GROUP) builder.setDeleteIntent(notificationState.getDeleteIntent(context)) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java index 7bea5594ed..06961c573c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java @@ -3,20 +3,18 @@ package org.thoughtcrime.securesms.notifications; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; - -import org.session.libsession.utilities.recipients.Recipient; -import org.session.libsession.utilities.recipients.Recipient.VibrateState; -import org.session.libsignal.utilities.Log; -import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2; - import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import org.session.libsession.utilities.recipients.Recipient.VibrateState; +import org.session.libsession.utilities.recipients.Recipient; +import org.session.libsignal.utilities.Log; +import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2; public class NotificationState { @@ -36,68 +34,54 @@ public class NotificationState { } public void addNotification(NotificationItem item) { + // Add this new notification at the beginning of the list notifications.addFirst(item); + // TODO: This doesn't make sense - why would be remove a threadId from the threads LinkedHashSet and then immediately put it back? `add` already only adds it if doesn't already exist - skipping this for now as a test -ACL + /* if (threads.contains(item.getThreadId())) { threads.remove(item.getThreadId()); } - + */ threads.add(item.getThreadId()); + notificationCount++; } public @Nullable Uri getRingtone(@NonNull Context context) { if (!notifications.isEmpty()) { Recipient recipient = notifications.getFirst().getRecipient(); - - if (recipient != null) { - return NotificationChannels.getMessageRingtone(context, recipient); - } + return NotificationChannels.getMessageRingtone(context, recipient); } - return null; + // TODO: Going to try returning the default ringtone for a notification rather than null here - seems like a more sensible option. + //return null; + + return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } public VibrateState getVibrate() { if (!notifications.isEmpty()) { Recipient recipient = notifications.getFirst().getRecipient(); - - if (recipient != null) { - return recipient.resolve().getMessageVibrate(); - } + return recipient.resolve().getMessageVibrate(); } - return VibrateState.DEFAULT; } - public boolean hasMultipleThreads() { - return threads.size() > 1; - } - - public LinkedHashSet getThreads() { - return threads; - } - - public int getThreadCount() { - return threads.size(); - } - - public int getMessageCount() { - return notificationCount; - } - - public List getNotifications() { - return notifications; - } + public boolean hasMultipleThreads() { return threads.size() > 1; } + public LinkedHashSet getThreads() { return threads; } + public int getThreadCount() { return threads.size(); } + public int getNotificationCount() { return notificationCount; } + public List getNotifications() { return notifications; } public List getNotificationsForThread(long threadId) { - LinkedList list = new LinkedList<>(); + LinkedList notificationsInThread = new LinkedList<>(); for (NotificationItem item : notifications) { - if (item.getThreadId() == threadId) list.addFirst(item); + if (item.getThreadId() == threadId) notificationsInThread.addFirst(item); } - return list; + return notificationsInThread; } public PendingIntent getMarkAsReadIntent(Context context, int notificationId) { @@ -111,7 +95,7 @@ public class NotificationState { Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION); intent.setClass(context, MarkReadReceiver.class); - intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); + intent.setData((Uri.parse("custom://" + System.currentTimeMillis()))); intent.putExtra(MarkReadReceiver.THREAD_IDS_EXTRA, threadArray); intent.putExtra(MarkReadReceiver.NOTIFICATION_ID_EXTRA, notificationId); @@ -171,7 +155,7 @@ public class NotificationState { Intent intent = new Intent(AndroidAutoHeardReceiver.HEARD_ACTION); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.setClass(context, AndroidAutoHeardReceiver.class); - intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); + intent.setData((Uri.parse("custom://" + System.currentTimeMillis()))); intent.putExtra(AndroidAutoHeardReceiver.THREAD_IDS_EXTRA, threadArray); intent.putExtra(AndroidAutoHeardReceiver.NOTIFICATION_ID_EXTRA, notificationId); intent.setPackage(context.getPackageName()); @@ -223,6 +207,4 @@ public class NotificationState { return PendingIntent.getBroadcast(context, 0, intent, intentFlags); } - - -} +} \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt index 510ab78a90..88848d546c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt @@ -232,7 +232,7 @@ class Poller( } } } - + private fun poll(snode: Snode, deferred: Deferred): Promise { if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) } return GlobalScope.asyncPromise {