mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 05:15:13 +02:00
Updated existing calendar events
This commit is contained in:
@@ -100,15 +100,12 @@ public class CalendarHelper {
|
||||
|
||||
static Long insert(Context context, ICalendar icalendar, VEvent event, int status,
|
||||
String selectedAccount, String selectedName, EntityMessage message) {
|
||||
Long existId = null;
|
||||
String uid = (event.getUid() == null ? null : event.getUid().getValue());
|
||||
if (!TextUtils.isEmpty(uid)) {
|
||||
Long existId = exists(context, selectedAccount, selectedName, uid);
|
||||
existId = exists(context, selectedAccount, selectedName, uid);
|
||||
if (existId != null) {
|
||||
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.STATUS, status);
|
||||
|
||||
Uri uri = resolver.insert(CalendarContract.Events.CONTENT_URI, values);
|
||||
long eventId = Long.parseLong(uri.getLastPathSegment());
|
||||
EntityLog.log(context, EntityLog.Type.General, message, "Inserted event" +
|
||||
" id=" + calId + ":" + eventId +
|
||||
" 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);
|
||||
long eventId;
|
||||
if (existId == null) {
|
||||
Uri uri = resolver.insert(CalendarContract.Events.CONTENT_URI, values);
|
||||
eventId = Long.parseLong(uri.getLastPathSegment());
|
||||
EntityLog.log(context, EntityLog.Type.General, message, "Inserted event" +
|
||||
" id=" + calId + ":" + eventId +
|
||||
" 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);
|
||||
} 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())
|
||||
try {
|
||||
@@ -240,7 +271,7 @@ public class CalendarHelper {
|
||||
|
||||
Uri auri = resolver.insert(CalendarContract.Attendees.CONTENT_URI, avalues);
|
||||
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 +
|
||||
" email=" + email +
|
||||
" name=" + name +
|
||||
|
||||
@@ -4444,10 +4444,9 @@ public class MessageHelper {
|
||||
VEvent event = icalendar.getEvents().get(0);
|
||||
|
||||
// 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);
|
||||
|
||||
if (method == null || method.isRequest()) {
|
||||
else if (method == null || method.isRequest()) {
|
||||
String selectedAccount;
|
||||
String selectedName;
|
||||
try {
|
||||
@@ -4463,7 +4462,8 @@ public class MessageHelper {
|
||||
CalendarHelper.insert(context, icalendar, event,
|
||||
CalendarContract.Events.STATUS_TENTATIVE,
|
||||
selectedAccount, selectedName, message);
|
||||
}
|
||||
} else
|
||||
EntityLog.log(context, "Unknown event method=" + method.getValue());
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
db.attachment().setWarning(local.id, Log.formatThrowable(ex));
|
||||
|
||||
Reference in New Issue
Block a user