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)
|
if (message == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
EntityAccount account = db.account().getAccount(message.account);
|
||||||
|
if (account == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
||||||
for (EntityAttachment attachment : attachments)
|
for (EntityAttachment attachment : attachments)
|
||||||
if (attachment.available && "text/calendar".equals(attachment.getMimeType())) {
|
if (attachment.available && "text/calendar".equals(attachment.getMimeType())) {
|
||||||
|
@ -3872,6 +3876,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
: icalendar.getCalendarScale());
|
: icalendar.getCalendarScale());
|
||||||
VEvent event = icalendar.getEvents().get(0);
|
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) {
|
if (action == R.id.ibCalendar) {
|
||||||
String summary = (event.getSummary() == null ? null : event.getSummary().getValue());
|
String summary = (event.getSummary() == null ? null : event.getSummary().getValue());
|
||||||
String description = (event.getDescription() == null ? null : event.getDescription().getValue());
|
String description = (event.getDescription() == null ? null : event.getDescription().getValue());
|
||||||
|
|
|
@ -31,6 +31,8 @@ import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
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,
|
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;
|
Long existId = null;
|
||||||
|
|
|
@ -4450,23 +4450,10 @@ public class MessageHelper {
|
||||||
// https://www.rfc-editor.org/rfc/rfc5546#section-3.2
|
// https://www.rfc-editor.org/rfc/rfc5546#section-3.2
|
||||||
if (method != null && method.isCancel())
|
if (method != null && method.isCancel())
|
||||||
CalendarHelper.delete(context, event, message);
|
CalendarHelper.delete(context, event, message);
|
||||||
else if (method == null || method.isRequest()) {
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
CalendarHelper.insert(context, icalendar, event,
|
CalendarHelper.insert(context, icalendar, event,
|
||||||
CalendarContract.Events.STATUS_TENTATIVE,
|
CalendarContract.Events.STATUS_TENTATIVE, account, message);
|
||||||
selectedAccount, selectedName, message);
|
else
|
||||||
} else
|
|
||||||
EntityLog.log(context, "Unknown event method=" + method.getValue());
|
EntityLog.log(context, "Unknown event method=" + method.getValue());
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.w(ex);
|
Log.w(ex);
|
||||||
|
|
Loading…
Reference in New Issue