Search in sources :

Example 11 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class MessageListFragment method groupMessagesByAccount.

private Map<Account, List<MessageReference>> groupMessagesByAccount(final List<MessageReference> messages) {
    Map<Account, List<MessageReference>> messagesByAccount = new HashMap<>();
    for (MessageReference message : messages) {
        Account account = preferences.getAccount(message.getAccountUuid());
        List<MessageReference> msgList = messagesByAccount.get(account);
        if (msgList == null) {
            msgList = new ArrayList<>();
            messagesByAccount.put(account, msgList);
        }
        msgList.add(message);
    }
    return messagesByAccount;
}
Also used : Account(com.fsck.k9.Account) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) MessageReference(com.fsck.k9.activity.MessageReference)

Example 12 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class MessagingController method refreshLocalMessageFlags.

private void refreshLocalMessageFlags(final Account account, final Folder remoteFolder, final LocalFolder localFolder, List<Message> syncFlagMessages, final AtomicInteger progress, final int todo) throws MessagingException {
    final String folder = remoteFolder.getName();
    if (remoteFolder.supportsFetchingFlags()) {
        Timber.d("SYNC: About to sync flags for %d remote messages for folder %s", syncFlagMessages.size(), folder);
        FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.FLAGS);
        List<Message> undeletedMessages = new LinkedList<>();
        for (Message message : syncFlagMessages) {
            if (!message.isSet(Flag.DELETED)) {
                undeletedMessages.add(message);
            }
        }
        remoteFolder.fetch(undeletedMessages, fp, null);
        for (Message remoteMessage : syncFlagMessages) {
            LocalMessage localMessage = localFolder.getMessage(remoteMessage.getUid());
            boolean messageChanged = syncFlags(localMessage, remoteMessage);
            if (messageChanged) {
                boolean shouldBeNotifiedOf = false;
                if (localMessage.isSet(Flag.DELETED) || isMessageSuppressed(localMessage)) {
                    for (MessagingListener l : getListeners()) {
                        l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
                    }
                } else {
                    if (shouldNotifyForMessage(account, localFolder, localMessage)) {
                        shouldBeNotifiedOf = true;
                    }
                }
                // we're only interested in messages that need removing
                if (!shouldBeNotifiedOf) {
                    MessageReference messageReference = localMessage.makeMessageReference();
                    notificationController.removeNewMailNotification(account, messageReference);
                }
            }
            progress.incrementAndGet();
            for (MessagingListener l : getListeners()) {
                l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
            }
        }
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) FetchProfile(com.fsck.k9.mail.FetchProfile) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessageReference(com.fsck.k9.activity.MessageReference) LinkedList(java.util.LinkedList)

Example 13 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class MessagingController method groupMessagesByAccountAndFolder.

@NonNull
private Map<String, Map<String, List<MessageReference>>> groupMessagesByAccountAndFolder(List<MessageReference> messages) {
    Map<String, Map<String, List<MessageReference>>> accountMap = new HashMap<>();
    for (MessageReference message : messages) {
        if (message == null) {
            continue;
        }
        String accountUuid = message.getAccountUuid();
        String folderName = message.getFolderName();
        Map<String, List<MessageReference>> folderMap = accountMap.get(accountUuid);
        if (folderMap == null) {
            folderMap = new HashMap<>();
            accountMap.put(accountUuid, folderMap);
        }
        List<MessageReference> messageList = folderMap.get(folderName);
        if (messageList == null) {
            messageList = new LinkedList<>();
            folderMap.put(folderName, messageList);
        }
        messageList.add(message);
    }
    return accountMap;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MessageReference(com.fsck.k9.activity.MessageReference) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull)

Example 14 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class NewMailNotificationsTest method testRemoveNewMailNotificationWithoutNotificationData.

@Test
public void testRemoveNewMailNotificationWithoutNotificationData() throws Exception {
    MessageReference messageReference = createMessageReference(1);
    newMailNotifications.removeNewMailNotification(account, messageReference);
    verify(notificationManager, never()).cancel(anyInt());
}
Also used : MessageReference(com.fsck.k9.activity.MessageReference) Test(org.junit.Test)

Example 15 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class NewMailNotificationsTest method testRemoveNewMailNotification.

@Test
public void testRemoveNewMailNotification() throws Exception {
    enablePrivacyMode();
    MessageReference messageReference = createMessageReference(1);
    int notificationIndex = 0;
    int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
    LocalMessage message = createLocalMessage();
    NotificationContent content = createNotificationContent();
    NotificationHolder holder = createNotificationHolder(content, notificationIndex);
    addToNotificationContentCreator(message, content);
    whenAddingContentReturn(content, AddNotificationResult.newNotification(holder));
    Notification summaryNotification = createNotification();
    addToDeviceNotifications(summaryNotification);
    newMailNotifications.addNewMailNotification(account, message, 23);
    whenRemovingContentReturn(messageReference, RemoveNotificationResult.cancelNotification(notificationId));
    newMailNotifications.removeNewMailNotification(account, messageReference);
    int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    verify(notificationManager).cancel(notificationId);
    verify(notificationManager, times(2)).notify(summaryNotificationId, summaryNotification);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessageReference(com.fsck.k9.activity.MessageReference) Notification(android.app.Notification) Test(org.junit.Test)

Aggregations

MessageReference (com.fsck.k9.activity.MessageReference)49 PendingIntent (android.app.PendingIntent)25 Account (com.fsck.k9.Account)22 Test (org.junit.Test)14 LocalMessage (com.fsck.k9.mailstore.LocalMessage)13 MessageReference (com.fsck.k9.controller.MessageReference)12 NotificationCompat (android.support.v4.app.NotificationCompat)9 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 List (java.util.List)7 MessagingException (com.fsck.k9.mail.MessagingException)6 LocalFolder (com.fsck.k9.mailstore.LocalFolder)5 SearchAccount (com.fsck.k9.search.SearchAccount)5 HashMap (java.util.HashMap)5 Cursor (android.database.Cursor)3 Message (com.fsck.k9.mail.Message)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2