Synchronize pushed add/change/delete

This commit is contained in:
M66B
2019-09-17 13:38:23 +02:00
parent e210b19c4a
commit 2f62dc21f1
5 changed files with 418 additions and 429 deletions

View File

@@ -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) {