diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ConversationNotificationDebouncer.kt b/app/src/main/java/org/thoughtcrime/securesms/database/ConversationNotificationDebouncer.kt index 2d96e722f2..84e1b9b20a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ConversationNotificationDebouncer.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ConversationNotificationDebouncer.kt @@ -8,12 +8,13 @@ import org.thoughtcrime.securesms.ApplicationContext class ConversationNotificationDebouncer(private val context: Context) { private val threadIDs = mutableSetOf() private val handler = (context.applicationContext as ApplicationContext).conversationListNotificationHandler - private val debouncer = Debouncer(handler, 1000) + private val debouncer = Debouncer(handler, 100) companion object { @SuppressLint("StaticFieldLeak") lateinit var shared: ConversationNotificationDebouncer + @Synchronized fun get(context: Context): ConversationNotificationDebouncer { if (::shared.isInitialized) { return shared } shared = ConversationNotificationDebouncer(context) diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeDiffUtil.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeDiffUtil.kt index cb4d6cd746..23ea811c6b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeDiffUtil.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeDiffUtil.kt @@ -34,6 +34,9 @@ class HomeDiffUtil( if (!sameUsername) return false val sameSnippet = oldItem.getDisplayBody(context) == newItem.getDisplayBody(context) if (!sameSnippet) return false + val sameSendStatus = oldItem.isFailed == newItem.isFailed && oldItem.isDelivered == newItem.isDelivered + && oldItem.isSent == newItem.isSent && oldItem.isPending == newItem.isPending + if (!sameSendStatus) return false // all same return true diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/BackgroundPollWorker.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/BackgroundPollWorker.kt index cac1bfb9a0..95760a093d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/BackgroundPollWorker.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/BackgroundPollWorker.kt @@ -3,12 +3,19 @@ package org.thoughtcrime.securesms.notifications import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import androidx.work.* +import androidx.work.Constraints +import androidx.work.ExistingPeriodicWorkPolicy +import androidx.work.NetworkType +import androidx.work.PeriodicWorkRequestBuilder +import androidx.work.WorkManager +import androidx.work.Worker +import androidx.work.WorkerParameters import nl.komponents.kovenant.Promise import nl.komponents.kovenant.all -import nl.komponents.kovenant.functional.map +import nl.komponents.kovenant.functional.bind import org.session.libsession.messaging.MessagingModuleConfiguration -import org.session.libsession.messaging.jobs.MessageReceiveJob +import org.session.libsession.messaging.jobs.BatchMessageReceiveJob +import org.session.libsession.messaging.jobs.MessageReceiveParameters import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2 import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPollerV2 import org.session.libsession.snode.SnodeAPI @@ -48,13 +55,14 @@ class BackgroundPollWorker(val context: Context, params: WorkerParameters) : Wor // DMs val userPublicKey = TextSecurePreferences.getLocalNumber(context)!! - val dmsPromise = SnodeAPI.getMessages(userPublicKey).map { envelopes -> - envelopes.map { (envelope, serverHash) -> + val dmsPromise = SnodeAPI.getMessages(userPublicKey).bind { envelopes -> + val params = envelopes.map { (envelope, serverHash) -> // FIXME: Using a job here seems like a bad idea... - MessageReceiveJob(envelope.toByteArray(), serverHash).executeAsync() + MessageReceiveParameters(envelope.toByteArray(), serverHash, null) } + BatchMessageReceiveJob(params).executeAsync() } - promises.addAll(dmsPromise.get()) + promises.add(dmsPromise) // Closed groups val closedGroupPoller = ClosedGroupPollerV2() // Intentionally don't use shared diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java index cb277fcf7b..63709a0e9e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java @@ -301,15 +301,6 @@ public class DefaultMessageNotifier implements MessageNotifier { } } - private String getTrimmedText(CharSequence text) { - String trimmedText = ""; - if (text != null) { - int trimEnd = Math.min(text.length(), 50); - trimmedText = text.subSequence(0,trimEnd) + (text.length() >= 50 ? "..." : ""); - } - return trimmedText; - } - private void sendSingleThreadNotification(@NonNull Context context, @NonNull NotificationState notificationState, boolean signal, boolean bundled) @@ -342,13 +333,12 @@ public class DefaultMessageNotifier implements MessageNotifier { builder.putStringExtra(LATEST_MESSAGE_ID_TAG, messageIdTag); CharSequence text = notifications.get(0).getText(); - String trimmedText = getTrimmedText(text); builder.setThread(notifications.get(0).getRecipient()); builder.setMessageCount(notificationState.getMessageCount()); MentionManagerUtilities.INSTANCE.populateUserPublicKeyCacheIfNeeded(notifications.get(0).getThreadId(),context); builder.setPrimaryMessageBody(recipient, notifications.get(0).getIndividualRecipient(), - MentionUtilities.highlightMentions(trimmedText, + MentionUtilities.highlightMentions(text == null ? "" : text, notifications.get(0).getThreadId(), context), notifications.get(0).getSlideDeck()); diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt index 77922ff1de..d44a72e3e0 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt @@ -128,19 +128,21 @@ class BatchMessageReceiveJob( } // increment unreads, notify, and update thread val unreadFromMine = messageIds.indexOfLast { (_,fromMe) -> fromMe } - var trueUnreadCount = messageIds.size + var trueUnreadCount = messageIds.filter { (_,fromMe) -> !fromMe }.size if (unreadFromMine >= 0) { trueUnreadCount -= (unreadFromMine + 1) storage.markConversationAsRead(threadId, false) } - storage.incrementUnread(threadId, trueUnreadCount) + if (trueUnreadCount > 0) { + storage.incrementUnread(threadId, trueUnreadCount) + } storage.updateThread(threadId, true) + SSKEnvironment.shared.notificationManager.updateNotification(context, threadId) } } // await all thread processing deferredThreadMap.awaitAll() } - SSKEnvironment.shared.notificationManager.updateNotification(context) if (failures.isEmpty()) { handleSuccess() } else {