diff --git a/app/src/main/java/eu/faircode/email/CalendarHelper.java b/app/src/main/java/eu/faircode/email/CalendarHelper.java index 44eff2ef65..74e8fc32ec 100644 --- a/app/src/main/java/eu/faircode/email/CalendarHelper.java +++ b/app/src/main/java/eu/faircode/email/CalendarHelper.java @@ -398,57 +398,6 @@ 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 48d1147b89..95634f6df8 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -38,6 +38,7 @@ 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; @@ -77,6 +78,8 @@ 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 { @@ -968,9 +971,36 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar if (method == null || !method.isReply()) return; - VEvent event = icalendar.getEvents().get(0); EntityMessage message = db.message().getMessage(sid); - CalendarHelper.update(this, event, message); + 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); break; } catch (Throwable ex) {