Fix minor issue

pull/1706/head
Al Lansley 4 months ago
parent 6b3fd2ad97
commit 2ec50b576f

@ -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))

@ -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<Long> 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<Long> getThreads() {
return threads;
}
public int getThreadCount() {
return threads.size();
}
public int getMessageCount() {
return notificationCount;
}
public List<NotificationItem> getNotifications() {
return notifications;
}
public boolean hasMultipleThreads() { return threads.size() > 1; }
public LinkedHashSet<Long> getThreads() { return threads; }
public int getThreadCount() { return threads.size(); }
public int getNotificationCount() { return notificationCount; }
public List<NotificationItem> getNotifications() { return notifications; }
public List<NotificationItem> getNotificationsForThread(long threadId) {
LinkedList<NotificationItem> list = new LinkedList<>();
LinkedList<NotificationItem> 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);
}
}
}

@ -232,7 +232,7 @@ class Poller(
}
}
}
private fun poll(snode: Snode, deferred: Deferred<Unit, Exception>): Promise<Unit, Exception> {
if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) }
return GlobalScope.asyncPromise {

Loading…
Cancel
Save