Search in sources :

Example 6 with Type

use of com.zimbra.cs.mailbox.MailItem.Type in project zm-mailbox by Zimbra.

the class CtagInfoCache method notifyCommittedChanges.

void notifyCommittedChanges(PendingModifications mods, int changeId) {
    int inboxFolder = Mailbox.ID_FOLDER_INBOX;
    Set<CalendarKey> keysToInvalidate = new HashSet<CalendarKey>();
    if (mods.created != null) {
        for (Map.Entry<ModificationKey, MailItem> entry : mods.created.entrySet()) {
            MailItem item = entry.getValue();
            if (item instanceof Message) {
                Message msg = (Message) item;
                if (msg.hasCalendarItemInfos() && msg.getFolderId() == inboxFolder) {
                    CalendarKey key = new CalendarKey(msg.getMailbox().getAccountId(), inboxFolder);
                    keysToInvalidate.add(key);
                }
            }
        }
    }
    if (mods.modified != null) {
        for (Map.Entry<ModificationKey, Change> entry : mods.modified.entrySet()) {
            Change change = entry.getValue();
            Object whatChanged = change.what;
            if (whatChanged instanceof Folder) {
                Folder folder = (Folder) whatChanged;
                MailItem.Type viewType = folder.getDefaultView();
                if (viewType == MailItem.Type.APPOINTMENT || viewType == MailItem.Type.TASK) {
                    CalendarKey key = new CalendarKey(folder.getMailbox().getAccountId(), folder.getId());
                    keysToInvalidate.add(key);
                }
            } else if (whatChanged instanceof Message) {
                Message msg = (Message) whatChanged;
                if (msg.hasCalendarItemInfos()) {
                    if (msg.getFolderId() == inboxFolder || (change.why & Change.FOLDER) != 0) {
                        // If message was moved, we don't know which folder it was moved from.
                        // Just invalidate the Inbox because that's the only message folder we care
                        // about in calendaring.
                        CalendarKey key = new CalendarKey(msg.getMailbox().getAccountId(), inboxFolder);
                        keysToInvalidate.add(key);
                    }
                }
            }
        }
    }
    if (mods.deleted != null) {
        for (Entry<ModificationKey, Change> entry : mods.deleted.entrySet()) {
            Type type = (Type) entry.getValue().what;
            if (type == MailItem.Type.FOLDER) {
                // We only have item id.  Assume it's a folder id and issue a delete.
                String acctId = entry.getKey().getAccountId();
                if (acctId == null)
                    // just to be safe
                    continue;
                CalendarKey key = new CalendarKey(acctId, entry.getKey().getItemId());
                keysToInvalidate.add(key);
            }
        // Let's not worry about hard deletes of invite/reply emails.  It has no practical benefit.
        }
    }
    try {
        mMemcachedLookup.removeMulti(keysToInvalidate);
    } catch (ServiceException e) {
        ZimbraLog.calendar.warn("Unable to notify ctag info cache.  Some cached data may become stale.", e);
    }
}
Also used : Message(com.zimbra.cs.mailbox.Message) ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) Change(com.zimbra.cs.session.PendingModifications.Change) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) Type(com.zimbra.cs.mailbox.MailItem.Type) MailItem(com.zimbra.cs.mailbox.MailItem) Type(com.zimbra.cs.mailbox.MailItem.Type) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) MemcachedMap(com.zimbra.common.util.memcached.MemcachedMap) HashSet(java.util.HashSet)

Example 7 with Type

use of com.zimbra.cs.mailbox.MailItem.Type in project zm-mailbox by Zimbra.

the class PendingModifications method recordDeleted.

public void recordDeleted(MailItem itemSnapshot) {
    MailItem.Type type = itemSnapshot.getType();
    changedTypes.add(type);
    delete(new ModificationKey(itemSnapshot), type, itemSnapshot);
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Type(com.zimbra.cs.mailbox.MailItem.Type)

Aggregations

Type (com.zimbra.cs.mailbox.MailItem.Type)7 MailItem (com.zimbra.cs.mailbox.MailItem)3 PagedDelete (com.zimbra.cs.mailbox.util.PagedDelete)3 TypedIdList (com.zimbra.cs.mailbox.util.TypedIdList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Test (org.junit.Test)3 ServiceException (com.zimbra.common.service.ServiceException)2 Folder (com.zimbra.cs.mailbox.Folder)2 Metadata (com.zimbra.cs.mailbox.Metadata)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 Color (com.zimbra.common.mailbox.Color)1 MemcachedMap (com.zimbra.common.util.memcached.MemcachedMap)1 DavException (com.zimbra.cs.dav.DavException)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Message (com.zimbra.cs.mailbox.Message)1 Change (com.zimbra.cs.session.PendingModifications.Change)1 ModificationKey (com.zimbra.cs.session.PendingModifications.ModificationKey)1