mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 19:34:15 +01:00
Synchronize pushed add/change/delete
This commit is contained in:
@@ -78,7 +78,7 @@ public class EntityOperation {
|
||||
static final String MOVE = "move";
|
||||
static final String COPY = "copy";
|
||||
static final String DELETE = "delete";
|
||||
static final String SEND = "send";
|
||||
static final String FETCH = "fetch";
|
||||
static final String SEEN = "seen";
|
||||
static final String ANSWERED = "answered";
|
||||
static final String FLAG = "flag";
|
||||
@@ -89,6 +89,7 @@ public class EntityOperation {
|
||||
static final String ATTACHMENT = "attachment";
|
||||
static final String SYNC = "sync";
|
||||
static final String SUBSCRIBE = "subscribe";
|
||||
static final String SEND = "send";
|
||||
|
||||
static void queue(Context context, EntityMessage message, String name, Object... values) {
|
||||
DB db = DB.getInstance(context);
|
||||
@@ -259,6 +260,36 @@ public class EntityOperation {
|
||||
ServiceSynchronize.process(context, false);
|
||||
}
|
||||
|
||||
static void queue(Context context, EntityFolder folder, String name, Object... values) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
JSONArray jargs = new JSONArray();
|
||||
for (Object value : values)
|
||||
jargs.put(value);
|
||||
|
||||
EntityOperation op = new EntityOperation();
|
||||
op.account = folder.account;
|
||||
op.folder = folder.id;
|
||||
op.message = null;
|
||||
op.name = name;
|
||||
op.args = jargs.toString();
|
||||
op.created = new Date().getTime();
|
||||
op.id = db.operation().insertOperation(op);
|
||||
|
||||
Log.i("Queued op=" + op.id + "/" + op.name +
|
||||
" folder=" + op.folder + " msg=" + op.message +
|
||||
" args=" + op.args);
|
||||
|
||||
Map<String, String> crumb = new HashMap<>();
|
||||
crumb.put("name", op.name);
|
||||
crumb.put("args", op.args);
|
||||
crumb.put("folder", op.account + ":" + op.folder);
|
||||
if (op.message != null)
|
||||
crumb.put("message", Long.toString(op.message));
|
||||
crumb.put("free", Integer.toString(Log.getFreeMemMb()));
|
||||
Log.breadcrumb("queued", crumb);
|
||||
}
|
||||
|
||||
static void sync(Context context, long fid, boolean foreground) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
@@ -308,6 +339,21 @@ public class EntityOperation {
|
||||
Log.i("Queued subscribe=" + subscribe + " folder=" + folder);
|
||||
}
|
||||
|
||||
boolean canSquash(EntityOperation next) throws JSONException {
|
||||
if (Objects.equals(this.message, next.message) &&
|
||||
ADD.equals(this.name) &&
|
||||
(ADD.equals(next.name) || DELETE.equals(next.name)))
|
||||
return true;
|
||||
|
||||
if (FETCH.equals(this.name) && FETCH.equals(next.name)) {
|
||||
JSONArray jargs1 = new JSONArray(this.args);
|
||||
JSONArray jargs2 = new JSONArray(next.args);
|
||||
return (jargs1.optLong(0, -1) == jargs2.optLong(0, -2));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EntityOperation) {
|
||||
|
||||
Reference in New Issue
Block a user