Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 302b668d authored by Philip's avatar Philip Committed by cketti
Browse files

On removing notification, mark it's ID no longer in use (#1677)

On removing notification, mark it's ID no longer in use

Fixes #1662
parent c7b5a506
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -85,6 +85,10 @@ class NotificationData {
        notificationIdsInUse.put(notificationId, true);
    }

    private void markNotificationIdAsFree(int notificationId) {
        notificationIdsInUse.delete(notificationId);
    }

    NotificationHolder createNotificationHolder(int notificationId, NotificationContent content) {
        return new NotificationHolder(notificationId, content);
    }
@@ -165,6 +169,8 @@ class NotificationData {
        activeNotifications.remove(holder);

        int notificationId = holder.notificationId;
        markNotificationIdAsFree(notificationId);

        if (!additionalNotifications.isEmpty()) {
            NotificationContent newContent = additionalNotifications.removeFirst();
            NotificationHolder replacement = createNotificationHolder(notificationId, newContent);
+12 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import java.util.List;

import com.fsck.k9.Account;
import com.fsck.k9.activity.MessageReference;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,8 +53,7 @@ public class NotificationDataTest {

    @Test
    public void testAddNotificationContentWithReplacingNotification() throws Exception {
        NotificationContent content = createNotificationContent("1");
        notificationData.addNotificationContent(content);
        notificationData.addNotificationContent(createNotificationContent("1"));
        notificationData.addNotificationContent(createNotificationContent("2"));
        notificationData.addNotificationContent(createNotificationContent("3"));
        notificationData.addNotificationContent(createNotificationContent("4"));
@@ -107,6 +107,15 @@ public class NotificationDataTest {
        assertEquals(content, holder.content);
    }

    @Test
    public void testRemoveDoesNotLeakNotificationIds() {
        for (int i = 1; i <= NotificationData.MAX_NUMBER_OF_STACKED_NOTIFICATIONS + 1; i++) {
            NotificationContent content = createNotificationContent("" + i);
            notificationData.addNotificationContent(content);
            notificationData.removeNotificationForMessage(content.messageReference);
        }
    }

    @Test
    public void testNewMessagesCount() throws Exception {
        assertEquals(0, notificationData.getNewMessagesCount());