Search in sources :

Example 66 with MessageReference

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

the class NewMailNotificationsTest method testRemoveNewMailNotificationWithCreateNotification.

@Test
public void testRemoveNewMailNotificationWithCreateNotification() throws Exception {
    MessageReference messageReference = createMessageReference(1);
    int notificationIndex = 0;
    int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
    LocalMessage message = createLocalMessage();
    NotificationContent contentOne = createNotificationContent();
    NotificationContent contentTwo = createNotificationContent();
    NotificationHolder holderOne = createNotificationHolder(contentOne, notificationIndex);
    NotificationHolder holderTwo = createNotificationHolder(contentTwo, notificationIndex);
    addToNotificationContentCreator(message, contentOne);
    whenAddingContentReturn(contentOne, AddNotificationResult.newNotification(holderOne));
    Notification summaryNotification = createNotification();
    addToDeviceNotifications(summaryNotification);
    Notification wearNotificationOne = createNotification();
    Notification wearNotificationTwo = createNotification();
    addToWearNotifications(holderOne, wearNotificationOne);
    addToWearNotifications(holderTwo, wearNotificationTwo);
    newMailNotifications.addNewMailNotification(account, message, 23);
    whenRemovingContentReturn(messageReference, RemoveNotificationResult.createNotification(holderTwo));
    newMailNotifications.removeNewMailNotification(account, messageReference);
    int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    verify(notificationManager).cancel(notificationId);
    verify(notificationManager).notify(notificationId, wearNotificationTwo);
    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)

Example 67 with MessageReference

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

the class MessageProvider method delete.

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    if (K9.app == null) {
        return 0;
    }
    Timber.v("MessageProvider/delete: %s", uri);
    // Note: can only delete a message
    List<String> segments = uri.getPathSegments();
    int accountId = Integer.parseInt(segments.get(1));
    String folderName = segments.get(2);
    String msgUid = segments.get(3);
    // get account
    Account myAccount = null;
    for (Account account : Preferences.getPreferences(getContext()).getAccounts()) {
        if (account.getAccountNumber() == accountId) {
            myAccount = account;
            if (!account.isAvailable(getContext())) {
                Timber.w("not deleting messages because account is unavailable at the moment");
                return 0;
            }
        }
    }
    if (myAccount == null) {
        Timber.e("Could not find account with id %d", accountId);
    }
    if (myAccount != null) {
        MessageReference messageReference = new MessageReference(myAccount.getUuid(), folderName, msgUid, null);
        MessagingController controller = MessagingController.getInstance(getContext());
        controller.deleteMessage(messageReference, null);
    }
    // FIXME return the actual number of deleted messages
    return 0;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) MessagingController(com.fsck.k9.controller.MessagingController) MessageReference(com.fsck.k9.activity.MessageReference)

Example 68 with MessageReference

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

the class MessagingController method actOnMessageGroup.

private void actOnMessageGroup(Account account, long folderId, List<MessageReference> messageReferences, MessageActor actor) {
    try {
        LocalFolder messageFolder = localStoreProvider.getInstance(account).getFolder(folderId);
        List<LocalMessage> localMessages = messageFolder.getMessagesByReference(messageReferences);
        actor.act(account, messageFolder, localMessages);
    } catch (MessagingException e) {
        Timber.e(e, "Error loading account?!");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessagingException(com.fsck.k9.mail.MessagingException)

Example 69 with MessageReference

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

the class MessagingController method deleteDraft.

public void deleteDraft(final Account account, long id) {
    try {
        Long folderId = account.getDraftsFolderId();
        if (folderId == null) {
            Timber.w("No Drafts folder configured. Can't delete draft.");
            return;
        }
        LocalStore localStore = localStoreProvider.getInstance(account);
        LocalFolder localFolder = localStore.getFolder(folderId);
        localFolder.open();
        String uid = localFolder.getMessageUidById(id);
        if (uid != null) {
            MessageReference messageReference = new MessageReference(account.getUuid(), folderId, uid);
            deleteMessage(messageReference);
        }
    } catch (MessagingException me) {
        Timber.e(me, "Error deleting draft");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 70 with MessageReference

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

the class LocalMessage method makeMessageReference.

public MessageReference makeMessageReference() {
    if (messageReference == null) {
        String accountUuid = getFolder().getAccountUuid();
        long folderId = getFolder().getDatabaseId();
        messageReference = new MessageReference(accountUuid, folderId, mUid);
    }
    return messageReference;
}
Also used : MessageReference(com.fsck.k9.controller.MessageReference)

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