1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-29 11:15:51 +00:00

Small improvements

This commit is contained in:
M66B 2018-12-03 15:46:24 +01:00
parent d3032555ee
commit 1d31e1848c
7 changed files with 51 additions and 60 deletions

View file

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

View file

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

View file

@ -31,7 +31,9 @@ public interface DaoOperation {
@Query("SELECT * FROM operation WHERE message = :message ORDER BY id")
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);
@Query("SELECT * FROM operation ORDER BY id")

View file

@ -82,6 +82,18 @@ public class EntityOperation {
JSONArray jargs = new JSONArray();
jargs.put(value);
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) {

View file

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

View file

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

View file

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