Added wait operation

pull/152/head
M66B 6 years ago
parent 5661c5d11e
commit 0c9ccef668

@ -200,6 +200,7 @@ The low priority status bar notification shows the number of pending operations,
* *body*: download message text * *body*: download message text
* *attachment*: download attachment * *attachment*: download attachment
* *sync*: synchronize local and remote messages * *sync*: synchronize local and remote messages
* *wait*: wait for message synchronization
Operations are processed only when there is a connection to the email server or when manually synchronizing. Operations are processed only when there is a connection to the email server or when manually synchronizing.
See also [this FAQ](#user-content-faq16). See also [this FAQ](#user-content-faq16).

@ -142,7 +142,8 @@ class Core {
!(EntityOperation.ADD.equals(op.name) || !(EntityOperation.ADD.equals(op.name) ||
EntityOperation.DELETE.equals(op.name) || EntityOperation.DELETE.equals(op.name) ||
EntityOperation.SEND.equals(op.name) || EntityOperation.SEND.equals(op.name) ||
EntityOperation.SYNC.equals(op.name))) EntityOperation.SYNC.equals(op.name) ||
EntityOperation.WAIT.equals(op.name)))
throw new IllegalArgumentException(op.name + " without uid " + op.args); throw new IllegalArgumentException(op.name + " without uid " + op.args);
// Operations should use database transaction when needed // Operations should use database transaction when needed
@ -200,6 +201,9 @@ class Core {
onSynchronizeMessages(context, jargs, account, folder, (IMAPFolder) ifolder, state); onSynchronizeMessages(context, jargs, account, folder, (IMAPFolder) ifolder, state);
break; break;
case EntityOperation.WAIT:
return;
default: default:
throw new IllegalArgumentException("Unknown operation=" + op.name); throw new IllegalArgumentException("Unknown operation=" + op.name);
} }
@ -1286,6 +1290,10 @@ class Core {
db.message().updateMessage(message); db.message().updateMessage(message);
else if (BuildConfig.DEBUG) else if (BuildConfig.DEBUG)
Log.i(folder.name + " unchanged uid=" + uid); Log.i(folder.name + " unchanged uid=" + uid);
int wait = db.operation().deleteOperationWait(message.id);
if (wait > 0)
Log.i(folder.name + " deleted wait id=" + message.id);
} }
if (!folder.isOutgoing() && !EntityFolder.ARCHIVE.equals(folder.type)) { if (!folder.isOutgoing() && !EntityFolder.ARCHIVE.equals(folder.type)) {

@ -94,6 +94,11 @@ public interface DaoOperation {
@Insert @Insert
long insertOperation(EntityOperation operation); long insertOperation(EntityOperation operation);
@Query("DELETE FROM operation" +
" WHERE message = :message" +
" AND name = '" + EntityOperation.WAIT + "'")
int deleteOperationWait(long message);
@Query("DELETE FROM operation WHERE id = :id") @Query("DELETE FROM operation WHERE id = :id")
void deleteOperation(long id); void deleteOperation(long id);
} }

@ -81,6 +81,7 @@ public class EntityOperation {
static final String BODY = "body"; static final String BODY = "body";
static final String ATTACHMENT = "attachment"; static final String ATTACHMENT = "attachment";
static final String SYNC = "sync"; static final String SYNC = "sync";
static final String WAIT = "wait";
static void queue(Context context, DB db, EntityMessage message, String name, Object... values) { static void queue(Context context, DB db, EntityMessage message, String name, Object... values) {
JSONArray jargs = new JSONArray(); JSONArray jargs = new JSONArray();
@ -149,6 +150,8 @@ public class EntityOperation {
message.ui_seen = true; message.ui_seen = true;
} }
newid = db.message().insertMessage(message); newid = db.message().insertMessage(message);
message.id = newid;
queue(context, db, message, WAIT);
message.id = id; message.id = id;
message.account = source.account; message.account = source.account;
message.folder = source.id; message.folder = source.id;

@ -338,6 +338,12 @@ public class ServiceSend extends LifecycleService {
} else } else
db.message().setMessageUiHide(message.id, true); db.message().setMessageUiHide(message.id, true);
if (message.inreplyto != null) {
List<EntityMessage> replieds = db.message().getMessageByMsgId(message.account, message.inreplyto);
for (EntityMessage replied : replieds)
EntityOperation.queue(this, db, replied, EntityOperation.ANSWERED, true);
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
@ -346,12 +352,6 @@ public class ServiceSend extends LifecycleService {
if (refFile.exists()) if (refFile.exists())
refFile.delete(); refFile.delete();
if (message.inreplyto != null) {
List<EntityMessage> replieds = db.message().getMessageByMsgId(message.account, message.inreplyto);
for (EntityMessage replied : replieds)
EntityOperation.queue(this, db, replied, EntityOperation.ANSWERED, true);
}
db.identity().setIdentityConnected(ident.id, new Date().getTime()); db.identity().setIdentityConnected(ident.id, new Date().getTime());
db.identity().setIdentityError(ident.id, null); db.identity().setIdentityError(ident.id, null);

@ -585,6 +585,7 @@ public class ServiceSynchronize extends LifecycleService {
// Observe operations // Observe operations
Handler handler = new Handler(getMainLooper()) { Handler handler = new Handler(getMainLooper()) {
private List<Long> waiting = new ArrayList<>();
private List<Long> handling = new ArrayList<>(); private List<Long> handling = new ArrayList<>();
private LiveData<List<EntityOperation>> liveOperations; private LiveData<List<EntityOperation>> liveOperations;
@ -612,13 +613,23 @@ public class ServiceSynchronize extends LifecycleService {
@Override @Override
public void onChanged(final List<EntityOperation> operations) { public void onChanged(final List<EntityOperation> operations) {
boolean process = false; boolean process = false;
List<Long> current = new ArrayList<>(); List<Long> ops = new ArrayList<>();
List<Long> waits = new ArrayList<>();
for (EntityOperation op : operations) { for (EntityOperation op : operations) {
if (EntityOperation.WAIT.equals(op.name))
waits.add(op.id);
if (!handling.contains(op.id)) if (!handling.contains(op.id))
process = true; process = true;
current.add(op.id); ops.add(op.id);
} }
handling = current; for (long wait : waits)
if (!waiting.contains(wait)) {
Log.i(folder.name + " not waiting anymore");
process = true;
break;
}
waiting = waits;
handling = ops;
if (handling.size() > 0 && process) { if (handling.size() > 0 && process) {
Log.i(folder.name + " operations=" + operations.size()); Log.i(folder.name + " operations=" + operations.size());

Loading…
Cancel
Save