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;
}
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);
}
}
}
}
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;
}
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());
}
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);
}
Aggregations