mirror of https://github.com/M66B/FairEmail.git
Insert/update calendar on accept/reject
This commit is contained in:
parent
338f6f5f6f
commit
c4d5b64717
|
@ -3862,6 +3862,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
if (message == null)
|
||||
return null;
|
||||
|
||||
EntityAccount account = db.account().getAccount(message.account);
|
||||
if (account == null)
|
||||
return null;
|
||||
|
||||
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
||||
for (EntityAttachment attachment : attachments)
|
||||
if (attachment.available && "text/calendar".equals(attachment.getMimeType())) {
|
||||
|
@ -3872,6 +3876,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
: icalendar.getCalendarScale());
|
||||
VEvent event = icalendar.getEvents().get(0);
|
||||
|
||||
boolean permission = Helper.hasPermission(context, Manifest.permission.WRITE_CALENDAR);
|
||||
if (permission || account.calendar != null) {
|
||||
if (action == R.id.btnCalendarAccept)
|
||||
CalendarHelper.insert(context, icalendar, event,
|
||||
CalendarContract.Events.STATUS_CONFIRMED, account, message);
|
||||
else if (action == R.id.btnCalendarDecline)
|
||||
CalendarHelper.delete(context, event, message);
|
||||
else if (action == R.id.btnCalendarMaybe)
|
||||
CalendarHelper.insert(context, icalendar, event,
|
||||
CalendarContract.Events.STATUS_TENTATIVE, account, message);
|
||||
}
|
||||
|
||||
if (action == R.id.ibCalendar) {
|
||||
String summary = (event.getSummary() == null ? null : event.getSummary().getValue());
|
||||
String description = (event.getDescription() == null ? null : event.getDescription().getValue());
|
||||
|
|
|
@ -31,6 +31,8 @@ import android.text.TextUtils;
|
|||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -99,6 +101,23 @@ public class CalendarHelper {
|
|||
}
|
||||
}
|
||||
|
||||
static Long insert(Context context, ICalendar icalendar, VEvent event, int status,
|
||||
EntityAccount account, EntityMessage message) {
|
||||
String selectedAccount;
|
||||
String selectedName;
|
||||
try {
|
||||
JSONObject jselected = new JSONObject(account.calendar);
|
||||
selectedAccount = jselected.getString("account");
|
||||
selectedName = jselected.optString("name", null);
|
||||
} catch (Throwable ex) {
|
||||
Log.i(ex);
|
||||
selectedAccount = account.calendar;
|
||||
selectedName = null;
|
||||
}
|
||||
|
||||
return insert(context, icalendar, event, status, selectedAccount, selectedName, message);
|
||||
}
|
||||
|
||||
static Long insert(Context context, ICalendar icalendar, VEvent event, int status,
|
||||
String selectedAccount, String selectedName, EntityMessage message) {
|
||||
Long existId = null;
|
||||
|
|
|
@ -4450,23 +4450,10 @@ public class MessageHelper {
|
|||
// https://www.rfc-editor.org/rfc/rfc5546#section-3.2
|
||||
if (method != null && method.isCancel())
|
||||
CalendarHelper.delete(context, event, message);
|
||||
else if (method == null || method.isRequest()) {
|
||||
String selectedAccount;
|
||||
String selectedName;
|
||||
try {
|
||||
JSONObject jselected = new JSONObject(account.calendar);
|
||||
selectedAccount = jselected.getString("account");
|
||||
selectedName = jselected.optString("name", null);
|
||||
} catch (Throwable ex) {
|
||||
Log.i(ex);
|
||||
selectedAccount = account.calendar;
|
||||
selectedName = null;
|
||||
}
|
||||
|
||||
else if (method == null || method.isRequest())
|
||||
CalendarHelper.insert(context, icalendar, event,
|
||||
CalendarContract.Events.STATUS_TENTATIVE,
|
||||
selectedAccount, selectedName, message);
|
||||
} else
|
||||
CalendarContract.Events.STATUS_TENTATIVE, account, message);
|
||||
else
|
||||
EntityLog.log(context, "Unknown event method=" + method.getValue());
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
|
|
Loading…
Reference in New Issue