From 29580f0eb6c19efc7fda8a8f5e996d4c9e138a79 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 26 Oct 2023 12:49:25 +0200 Subject: [PATCH] Revert "Insert event REPLY" This reverts commit 4d24edc9abb67183ace64991b1421d6878c1a59b. --- .../eu/faircode/email/CalendarHelper.java | 51 +++++++++++++++++++ .../java/eu/faircode/email/ServiceSend.java | 34 +------------ 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/CalendarHelper.java b/app/src/main/java/eu/faircode/email/CalendarHelper.java index 74e8fc32ec..44eff2ef65 100644 --- a/app/src/main/java/eu/faircode/email/CalendarHelper.java +++ b/app/src/main/java/eu/faircode/email/CalendarHelper.java @@ -398,6 +398,57 @@ public class CalendarHelper { return null; } + static void update(Context context, VEvent event, EntityMessage message) { + String uid = (event.getUid() == null ? null : event.getUid().getValue()); + if (TextUtils.isEmpty(uid)) { + EntityLog.log(context, EntityLog.Type.General, message, + "Update event: no uid"); + return; + } + + List attendees = event.getAttendees(); + if (attendees == null || attendees.size() == 0) { + EntityLog.log(context, EntityLog.Type.General, message, + "Update event: no attendees"); + return; + } + + ParticipationStatus status = attendees.get(0).getParticipationStatus(); + if (!ParticipationStatus.ACCEPTED.equals(status) && + !ParticipationStatus.DECLINED.equals(status)) { + EntityLog.log(context, EntityLog.Type.General, message, + "Update event: not accepted/declined"); + return; + } + + ContentResolver resolver = context.getContentResolver(); + try (Cursor cursor = resolver.query(CalendarContract.Events.CONTENT_URI, + new String[]{CalendarContract.Events._ID}, + CalendarContract.Events.UID_2445 + " = ?", + new String[]{uid}, + null)) { + if (cursor.getCount() == 0) + EntityLog.log(context, EntityLog.Type.General, message, + "Update event: uid not found"); + while (cursor.moveToNext()) { + long eventId = cursor.getLong(0); + + // https://developer.android.com/guide/topics/providers/calendar-provider#modify-calendar + Uri updateUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId); + ContentValues values = new ContentValues(); + if (ParticipationStatus.ACCEPTED.equals(status)) + values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED); + else + values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CANCELED); + int rows = resolver.update(updateUri, values, null, null); + + EntityLog.log(context, EntityLog.Type.General, message, + "Updated event id=" + eventId + " uid=" + uid + " rows=" + rows + + " status=" + status + " accept=" + ParticipationStatus.ACCEPTED.equals(status)); + } + } + } + static void delete(Context context, VEvent event, EntityMessage message) { String uid = (event.getUid() == null ? null : event.getUid().getValue()); if (TextUtils.isEmpty(uid)) diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 95634f6df8..48d1147b89 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -38,7 +38,6 @@ import android.net.NetworkRequest; import android.net.Uri; import android.os.PowerManager; import android.os.SystemClock; -import android.provider.CalendarContract; import android.text.TextUtils; import androidx.annotation.NonNull; @@ -78,8 +77,6 @@ import javax.mail.internet.MimeMessage; import biweekly.Biweekly; import biweekly.ICalendar; import biweekly.component.VEvent; -import biweekly.parameter.ParticipationStatus; -import biweekly.property.Attendee; import biweekly.property.Method; public class ServiceSend extends ServiceBase implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -971,36 +968,9 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar if (method == null || !method.isReply()) return; - EntityMessage message = db.message().getMessage(sid); - if (message == null) { - EntityLog.log(this, "Event REPLY message not found"); - return; - } - - EntityAccount account = db.account().getAccount(message.account); - if (account == null) { - EntityLog.log(this, "Event REPLY account not found"); - return; - } - VEvent event = icalendar.getEvents().get(0); - - List attendees = event.getAttendees(); - if (attendees == null || attendees.size() == 0) { - EntityLog.log(this, "Event REPLY attendee not found"); - return; - } - - int status; - ParticipationStatus pstatus = attendees.get(0).getParticipationStatus(); - if (ParticipationStatus.ACCEPTED.equals(pstatus)) - status = CalendarContract.Events.STATUS_CONFIRMED; - else if (ParticipationStatus.DECLINED.equals(pstatus)) - status = CalendarContract.Events.STATUS_CANCELED; - else - status = CalendarContract.Events.STATUS_TENTATIVE; - - CalendarHelper.insert(this, icalendar, event, status, account, message); + EntityMessage message = db.message().getMessage(sid); + CalendarHelper.update(this, event, message); break; } catch (Throwable ex) {