Updated existing calendar events

pull/214/head
M66B 1 year ago
parent 35c435f683
commit 1451764b61

@ -100,15 +100,12 @@ public class CalendarHelper {
static Long insert(Context context, ICalendar icalendar, VEvent event, int status, static Long insert(Context context, ICalendar icalendar, VEvent event, int status,
String selectedAccount, String selectedName, EntityMessage message) { String selectedAccount, String selectedName, EntityMessage message) {
Long existId = null;
String uid = (event.getUid() == null ? null : event.getUid().getValue()); String uid = (event.getUid() == null ? null : event.getUid().getValue());
if (!TextUtils.isEmpty(uid)) { if (!TextUtils.isEmpty(uid)) {
Long existId = exists(context, selectedAccount, selectedName, uid); existId = exists(context, selectedAccount, selectedName, uid);
if (existId != null) { if (existId != null) {
EntityLog.log(context, EntityLog.Type.General, message, "Event exists uid=" + uid + " id=" + existId); EntityLog.log(context, EntityLog.Type.General, message, "Event exists uid=" + uid + " id=" + existId);
if (BuildConfig.DEBUG)
delete(context, event, message);
else
return existId;
} }
} }
@ -186,19 +183,53 @@ public class CalendarHelper {
values.put(CalendarContract.Events.EVENT_LOCATION, location); values.put(CalendarContract.Events.EVENT_LOCATION, location);
values.put(CalendarContract.Events.STATUS, status); values.put(CalendarContract.Events.STATUS, status);
Uri uri = resolver.insert(CalendarContract.Events.CONTENT_URI, values); long eventId;
long eventId = Long.parseLong(uri.getLastPathSegment()); if (existId == null) {
EntityLog.log(context, EntityLog.Type.General, message, "Inserted event" + Uri uri = resolver.insert(CalendarContract.Events.CONTENT_URI, values);
" id=" + calId + ":" + eventId + eventId = Long.parseLong(uri.getLastPathSegment());
" uid=" + uid + EntityLog.log(context, EntityLog.Type.General, message, "Inserted event" +
" organizer=" + organizer + " id=" + calId + ":" + eventId +
" tz=" + (tz == null ? null : tz.getID()) + " uid=" + uid +
" start=" + new Date(start.getTime()) + " organizer=" + organizer +
" end=" + new Date(end.getTime()) + " tz=" + (tz == null ? null : tz.getID()) +
" rrule=" + rrule + " start=" + new Date(start.getTime()) +
" summary=" + summary + " end=" + new Date(end.getTime()) +
" location=" + location + " rrule=" + rrule +
" status=" + status); " summary=" + summary +
" location=" + location +
" status=" + status);
} else {
Uri uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, existId);
int rows = resolver.update(uri, values, null, null);
EntityLog.log(context, EntityLog.Type.General, message, "Updated event" +
" id=" + calId + ":" + existId +
" uid=" + uid +
" organizer=" + organizer +
" tz=" + (tz == null ? null : tz.getID()) +
" start=" + new Date(start.getTime()) +
" end=" + new Date(end.getTime()) +
" rrule=" + rrule +
" summary=" + summary +
" location=" + location +
" status=" + status +
" rows=" + rows);
rows = resolver.delete(CalendarContract.Attendees.CONTENT_URI,
CalendarContract.Attendees.EVENT_ID + " = ?",
new String[]{Long.toString(existId)});
EntityLog.log(context, EntityLog.Type.General, message, "Deleted event attendees for update" +
" id=" + calId + ":" + existId +
" rows=" + rows);
rows = resolver.delete(CalendarContract.Reminders.CONTENT_URI,
CalendarContract.Reminders.EVENT_ID + " = ?",
new String[]{Long.toString(existId)});
EntityLog.log(context, EntityLog.Type.General, message, "Deleted event reminders for update" +
" id=" + calId + ":" + existId +
" rows=" + rows);
eventId = existId;
}
for (Attendee a : event.getAttendees()) for (Attendee a : event.getAttendees())
try { try {
@ -240,7 +271,7 @@ public class CalendarHelper {
Uri auri = resolver.insert(CalendarContract.Attendees.CONTENT_URI, avalues); Uri auri = resolver.insert(CalendarContract.Attendees.CONTENT_URI, avalues);
long attendeeId = Long.parseLong(auri.getLastPathSegment()); long attendeeId = Long.parseLong(auri.getLastPathSegment());
EntityLog.log(context, EntityLog.Type.General, message, "Inserted attendee" + EntityLog.log(context, EntityLog.Type.General, message, "Inserted event attendee" +
" id=" + eventId + ":" + attendeeId + " id=" + eventId + ":" + attendeeId +
" email=" + email + " email=" + email +
" name=" + name + " name=" + name +

@ -4444,10 +4444,9 @@ public class MessageHelper {
VEvent event = icalendar.getEvents().get(0); VEvent event = icalendar.getEvents().get(0);
// https://www.rfc-editor.org/rfc/rfc5546#section-3.2 // https://www.rfc-editor.org/rfc/rfc5546#section-3.2
if (method == null || method.isRequest() || method.isCancel()) if (method != null && method.isCancel())
CalendarHelper.delete(context, event, message); CalendarHelper.delete(context, event, message);
else if (method == null || method.isRequest()) {
if (method == null || method.isRequest()) {
String selectedAccount; String selectedAccount;
String selectedName; String selectedName;
try { try {
@ -4463,7 +4462,8 @@ public class MessageHelper {
CalendarHelper.insert(context, icalendar, event, CalendarHelper.insert(context, icalendar, event,
CalendarContract.Events.STATUS_TENTATIVE, CalendarContract.Events.STATUS_TENTATIVE,
selectedAccount, selectedName, message); selectedAccount, selectedName, message);
} } else
EntityLog.log(context, "Unknown event method=" + method.getValue());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
db.attachment().setWarning(local.id, Log.formatThrowable(ex)); db.attachment().setWarning(local.id, Log.formatThrowable(ex));

Loading…
Cancel
Save