Small improvements

pull/146/head
M66B 6 years ago
parent d3032555ee
commit 1d31e1848c

@ -328,7 +328,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
for (Long mid : db.message().getMessageByFolder(id, false)) { for (Long mid : db.message().getMessageByFolder(id, false)) {
EntityMessage message = db.message().getMessage(mid); EntityMessage message = db.message().getMessage(mid);
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.DELETE); EntityOperation.queue(db, message, EntityOperation.DELETE);
} }

@ -963,7 +963,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK); EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK);
EntityOperation.queue(db, message, EntityOperation.MOVE, junk.id); EntityOperation.queue(db, message, EntityOperation.MOVE, junk.id);
db.message().setMessageUiHide(id, true);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -1108,8 +1107,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
db.message().setMessageUiSeen(message.id, false);
db.message().setMessageUiIgnored(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, false); EntityOperation.queue(db, message, EntityOperation.SEEN, false);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -1146,7 +1143,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean flagged = args.getBoolean("flagged"); boolean flagged = args.getBoolean("flagged");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
db.message().setMessageUiFlagged(message.id, flagged);
EntityOperation.queue(db, message, EntityOperation.FLAG, flagged); EntityOperation.queue(db, message, EntityOperation.FLAG, flagged);
return null; return null;
} }
@ -1421,10 +1417,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.message().deleteMessage(id); db.message().deleteMessage(id);
NotificationManager nm = context.getSystemService(NotificationManager.class); NotificationManager nm = context.getSystemService(NotificationManager.class);
nm.cancel("send", message.account.intValue()); nm.cancel("send", message.account.intValue());
} else { } else
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.DELETE); EntityOperation.queue(db, message, EntityOperation.DELETE);
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

@ -31,7 +31,9 @@ public interface DaoOperation {
@Query("SELECT * FROM operation WHERE message = :message ORDER BY id") @Query("SELECT * FROM operation WHERE message = :message ORDER BY id")
LiveData<List<EntityOperation>> getOperationsByMessage(long message); LiveData<List<EntityOperation>> getOperationsByMessage(long message);
@Query("SELECT * FROM operation WHERE folder = :folder ORDER BY id") @Query("SELECT * FROM operation" +
" WHERE folder = :folder" +
" ORDER BY CASE WHEN name = '" + EntityOperation.SYNC + "' THEN 1 ELSE 0 END, id")
List<EntityOperation> getOperationsByFolder(long folder); List<EntityOperation> getOperationsByFolder(long folder);
@Query("SELECT * FROM operation ORDER BY id") @Query("SELECT * FROM operation ORDER BY id")

@ -82,6 +82,18 @@ public class EntityOperation {
JSONArray jargs = new JSONArray(); JSONArray jargs = new JSONArray();
jargs.put(value); jargs.put(value);
queue(db, message.folder, message.id, name, jargs); queue(db, message.folder, message.id, name, jargs);
if (SEEN.equals(name)) {
db.message().setMessageUiSeen(message.id, (boolean) value);
db.message().setMessageUiIgnored(message.id, true);
} else if (FLAG.equals(name))
db.message().setMessageUiFlagged(message.id, (boolean) value);
else if (ANSWERED.equals(name))
db.message().setMessageUiAnswered(message.id, (boolean) value);
else if (MOVE.equals(name))
db.message().setMessageUiHide(message.id, true);
else if (DELETE.equals(name))
db.message().setMessageUiHide(message.id, true);
} }
static void queue(DB db, EntityMessage message, String name, Object value1, Object value2) { static void queue(DB db, EntityMessage message, String name, Object value1, Object value2) {

@ -1639,7 +1639,6 @@ public class FragmentCompose extends FragmentEx {
if (draft.replying != null) { if (draft.replying != null) {
EntityMessage replying = db.message().getMessage(draft.replying); EntityMessage replying = db.message().getMessage(draft.replying);
db.message().setMessageUiAnswered(replying.id, true);
EntityOperation.queue(db, replying, EntityOperation.ANSWERED, true); EntityOperation.queue(db, replying, EntityOperation.ANSWERED, true);
} }
} }

@ -744,12 +744,9 @@ public class FragmentMessages extends FragmentEx {
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message.ui_seen != seen) { if (message.ui_seen != seen)
db.message().setMessageUiSeen(message.id, seen);
db.message().setMessageUiIgnored(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, seen); EntityOperation.queue(db, message, EntityOperation.SEEN, seen);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -785,11 +782,9 @@ public class FragmentMessages extends FragmentEx {
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message.ui_flagged != flagged) { if (message.ui_flagged != flagged)
db.message().setMessageUiFlagged(message.id, flagged);
EntityOperation.queue(db, message, EntityOperation.FLAG, flagged); EntityOperation.queue(db, message, EntityOperation.FLAG, flagged);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -984,11 +979,9 @@ public class FragmentMessages extends FragmentEx {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message.uid == null && !TextUtils.isEmpty(message.error)) // outbox if (message.uid == null && !TextUtils.isEmpty(message.error)) // outbox
db.message().deleteMessage(id); db.message().deleteMessage(id);
else { else
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.DELETE); EntityOperation.queue(db, message, EntityOperation.DELETE);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -1601,11 +1594,8 @@ public class FragmentMessages extends FragmentEx {
if (!message.content) if (!message.content)
EntityOperation.queue(db, message, EntityOperation.BODY); EntityOperation.queue(db, message, EntityOperation.BODY);
if (!message.ui_seen && !EntityFolder.OUTBOX.equals(folder.type)) { if (!message.ui_seen && !EntityFolder.OUTBOX.equals(folder.type))
db.message().setMessageUiSeen(message.id, true);
db.message().setMessageUiIgnored(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, true); EntityOperation.queue(db, message, EntityOperation.SEEN, true);
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

@ -330,8 +330,6 @@ public class ServiceSynchronize extends LifecycleService {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
switch (parts[0]) { switch (parts[0]) {
case "seen": case "seen":
db.message().setMessageUiSeen(message.id, true);
db.message().setMessageUiIgnored(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, true); EntityOperation.queue(db, message, EntityOperation.SEEN, true);
break; break;
@ -342,7 +340,6 @@ public class ServiceSynchronize extends LifecycleService {
if (archive != null) { if (archive != null) {
EntityOperation.queue(db, message, EntityOperation.SEEN, true); EntityOperation.queue(db, message, EntityOperation.SEEN, true);
EntityOperation.queue(db, message, EntityOperation.MOVE, archive.id); EntityOperation.queue(db, message, EntityOperation.MOVE, archive.id);
db.message().setMessageUiHide(message.id, true);
} }
break; break;
@ -351,7 +348,6 @@ public class ServiceSynchronize extends LifecycleService {
if (trash != null) { if (trash != null) {
EntityOperation.queue(db, message, EntityOperation.SEEN, true); EntityOperation.queue(db, message, EntityOperation.SEEN, true);
EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id); EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id);
db.message().setMessageUiHide(message.id, true);
} }
break; break;
@ -1117,7 +1113,7 @@ public class ServiceSynchronize extends LifecycleService {
EntityFolder ofolder = null; EntityFolder ofolder = null;
IMAPFolder ifolder = null; IMAPFolder ifolder = null;
for (EntityFolder f : folders.keySet()) for (EntityFolder f : folders.keySet())
if (f.id == folder.id) { if (f.id.equals(folder.id)) {
ofolder = f; ofolder = f;
ifolder = folders.get(f); ifolder = folders.get(f);
break; break;
@ -1357,10 +1353,9 @@ public class ServiceSynchronize extends LifecycleService {
db.message().setMessageError(message.id, null); db.message().setMessageError(message.id, null);
if (message != null && message.uid == null && if (message != null && message.uid == null &&
(EntityOperation.SEEN.equals(op.name) || !(EntityOperation.ADD.equals(op.name) ||
EntityOperation.DELETE.equals(op.name) || EntityOperation.SEND.equals(op.name) ||
EntityOperation.MOVE.equals(op.name) || EntityOperation.SYNC.equals(op.name)))
EntityOperation.HEADERS.equals(op.name)))
throw new IllegalArgumentException(op.name + " without uid " + op.args); throw new IllegalArgumentException(op.name + " without uid " + op.args);
JSONArray jargs = new JSONArray(op.args); JSONArray jargs = new JSONArray(op.args);
@ -1370,12 +1365,12 @@ public class ServiceSynchronize extends LifecycleService {
if (EntityOperation.SEEN.equals(op.name)) if (EntityOperation.SEEN.equals(op.name))
doSeen(folder, ifolder, message, jargs, db); doSeen(folder, ifolder, message, jargs, db);
else if (EntityOperation.ANSWERED.equals(op.name))
doAnswered(folder, ifolder, message, jargs, db);
else if (EntityOperation.FLAG.equals(op.name)) else if (EntityOperation.FLAG.equals(op.name))
doFlag(folder, ifolder, message, jargs, db); doFlag(folder, ifolder, message, jargs, db);
else if (EntityOperation.ANSWERED.equals(op.name))
doAnswered(folder, ifolder, message, jargs, db);
else if (EntityOperation.KEYWORD.equals(op.name)) else if (EntityOperation.KEYWORD.equals(op.name))
doKeyword(folder, ifolder, message, jargs, db); doKeyword(folder, ifolder, message, jargs, db);
@ -1401,10 +1396,10 @@ public class ServiceSynchronize extends LifecycleService {
doAttachment(folder, op, ifolder, message, jargs, db); doAttachment(folder, op, ifolder, message, jargs, db);
else if (EntityOperation.SYNC.equals(op.name)) else if (EntityOperation.SYNC.equals(op.name))
if (!EntityFolder.OUTBOX.equals(folder.type)) if (EntityFolder.OUTBOX.equals(folder.type))
synchronizeMessages(account, folder, ifolder, state);
else
db.folder().setFolderError(folder.id, null); db.folder().setFolderError(folder.id, null);
else
synchronizeMessages(account, folder, ifolder, state);
else else
throw new MessagingException("Unknown operation name=" + op.name); throw new MessagingException("Unknown operation name=" + op.name);
@ -1471,46 +1466,46 @@ public class ServiceSynchronize extends LifecycleService {
db.message().setMessageSeen(message.id, seen); db.message().setMessageSeen(message.id, seen);
} }
private void doAnswered(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException { private void doFlag(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException {
// Mark message (un)answered // Star/unstar message
if (!ifolder.getPermanentFlags().contains(Flags.Flag.ANSWERED)) { if (!ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) {
db.message().setMessageAnswered(message.id, false); db.message().setMessageFlagged(message.id, false);
db.message().setMessageUiAnswered(message.id, false); db.message().setMessageUiFlagged(message.id, false);
return; return;
} }
boolean answered = jargs.getBoolean(0); boolean flagged = jargs.getBoolean(0);
if (message.answered.equals(answered)) if (message.flagged.equals(flagged))
return; return;
Message imessage = ifolder.getMessageByUID(message.uid); Message imessage = ifolder.getMessageByUID(message.uid);
if (imessage == null) if (imessage == null)
throw new MessageRemovedException(); throw new MessageRemovedException();
imessage.setFlag(Flags.Flag.ANSWERED, answered); imessage.setFlag(Flags.Flag.FLAGGED, flagged);
db.message().setMessageAnswered(message.id, answered); db.message().setMessageFlagged(message.id, flagged);
} }
private void doFlag(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException { private void doAnswered(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException {
// Star/unstar message // Mark message (un)answered
if (!ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) { if (!ifolder.getPermanentFlags().contains(Flags.Flag.ANSWERED)) {
db.message().setMessageFlagged(message.id, false); db.message().setMessageAnswered(message.id, false);
db.message().setMessageUiFlagged(message.id, false); db.message().setMessageUiAnswered(message.id, false);
return; return;
} }
boolean flagged = jargs.getBoolean(0); boolean answered = jargs.getBoolean(0);
if (message.flagged.equals(flagged)) if (message.answered.equals(answered))
return; return;
Message imessage = ifolder.getMessageByUID(message.uid); Message imessage = ifolder.getMessageByUID(message.uid);
if (imessage == null) if (imessage == null)
throw new MessageRemovedException(); throw new MessageRemovedException();
imessage.setFlag(Flags.Flag.FLAGGED, flagged); imessage.setFlag(Flags.Flag.ANSWERED, answered);
db.message().setMessageFlagged(message.id, flagged); db.message().setMessageAnswered(message.id, answered);
} }
private void doKeyword(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException { private void doKeyword(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException {

Loading…
Cancel
Save