From 4c6683f152426d60602573535164cd07d3456f45 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Thu, 25 Feb 2010 17:37:52 -0800 Subject: [PATCH] Fix # 2467153 (Handle change in attendee status from Calendar UI) * Fill in this missing piece of meeting related functionality. * We keep track of the last synced attendee status in the newly created syncAdapterData event column * When this changes, we (in addition to syncing up the change) send an email to the organizer (unless we're the organizer, of course) Bug: 2467153 Change-Id: I6332fb6d0839e33d4c54bd4358ee0f154bff6612 --- .../exchange/adapter/CalendarSyncAdapter.java | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/com/android/exchange/adapter/CalendarSyncAdapter.java b/src/com/android/exchange/adapter/CalendarSyncAdapter.java index 28cde2f2f..361de1e92 100644 --- a/src/com/android/exchange/adapter/CalendarSyncAdapter.java +++ b/src/com/android/exchange/adapter/CalendarSyncAdapter.java @@ -20,6 +20,7 @@ package com.android.exchange.adapter; import com.android.email.Email; import com.android.email.provider.EmailContent; import com.android.email.provider.EmailContent.Mailbox; +import com.android.email.provider.EmailContent.Message; import com.android.exchange.EasOutboxService; import com.android.exchange.EasSyncService; import com.android.exchange.utility.CalendarUtilities; @@ -1184,11 +1185,17 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter { boolean first = true; while (eventIterator.hasNext()) { Entity entity = eventIterator.next(); - String clientId = UUID.randomUUID().toString(); + // For each of these entities, create the change commands ContentValues entityValues = entity.getEntityValues(); String serverId = entityValues.getAsString(Events._SYNC_ID); + // Find our uid in the entity; otherwise create one + String clientId = entityValues.getAsString(Events._SYNC_LOCAL_ID); + if (clientId == null) { + clientId = UUID.randomUUID().toString(); + } + // EAS 2.5 needs: BusyStatus DtStamp EndTime Sensitivity StartTime TimeZone UID // We can generate all but what we're testing for below String organizerEmail = entityValues.getAsString(Events.ORGANIZER); @@ -1251,7 +1258,8 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter { mUpdatedIdList.add(entityValues.getAsLong(Events._ID)); // Send the meeting invite if there are attendees and we're the organizer - if (hasAttendees && organizerEmail.equalsIgnoreCase(mAccount.mEmailAddress)) { + boolean selfOrganizer = organizerEmail.equalsIgnoreCase(mAccount.mEmailAddress); + if (hasAttendees && selfOrganizer) { EmailContent.Message msg = CalendarUtilities.createMessageForEventId(mContext, eventId, EmailContent.Message.FLAG_OUTGOING_MEETING_INVITE, clientId, @@ -1259,6 +1267,46 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter { if (msg != null) { EasOutboxService.sendMessage(mContext, mAccount.mId, msg); } + } else if (!selfOrganizer) { + // If we're not the organizer, see if we've changed our attendee status + int currentStatus = entityValues.getAsInteger(Events.SELF_ATTENDEE_STATUS); + String adapterData = entityValues.getAsString(Events.SYNC_ADAPTER_DATA); + int syncStatus = Attendees.ATTENDEE_STATUS_NONE; + if (adapterData != null) { + syncStatus = Integer.parseInt(adapterData); + } + if ((currentStatus != syncStatus) && + (currentStatus != Attendees.ATTENDEE_STATUS_NONE)) { + // If so, send a meeting reply + int messageFlag = 0; + switch (currentStatus) { + case Attendees.ATTENDEE_STATUS_ACCEPTED: + messageFlag = Message.FLAG_OUTGOING_MEETING_ACCEPT; + break; + case Attendees.ATTENDEE_STATUS_DECLINED: + messageFlag = Message.FLAG_OUTGOING_MEETING_DECLINE; + break; + case Attendees.ATTENDEE_STATUS_TENTATIVE: + messageFlag = Message.FLAG_OUTGOING_MEETING_TENTATIVE; + break; + } + // Make sure we have a valid status (messageFlag should never be zero) + if (messageFlag != 0) { + // Save away the new status + cidValues.clear(); + cidValues.put(Events.SYNC_ADAPTER_DATA, + Integer.toString(currentStatus)); + cr.update(ContentUris.withAppendedId(uri, eventId), cidValues, null, + null); + // Send mail to the organizer advising of the new status + EmailContent.Message msg = + CalendarUtilities.createMessageForEventId(mContext, eventId, + messageFlag, clientId, mAccount); + if (msg != null) { + EasOutboxService.sendMessage(mContext, mAccount.mId, msg); + } + } + } } } if (!first) {