Minimum hide of 1 minute

pull/156/head
M66B 6 years ago
parent 8e9083b343
commit 192a522551

@ -683,7 +683,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (debug) {
String text = "error=" + error +
"\nuid=" + message.uid + " id=" + message.id + " " + DTF.format(new Date(message.received)) +
"\n" + (message.ui_hide ? "HIDDEN " : "") +
"\n" + (message.ui_hide == 0 ? "" : "HIDDEN ") +
"seen=" + message.seen + "/" + message.ui_seen +
" unseen=" + message.unseen +
" ignored=" + message.ui_ignored +

@ -118,6 +118,7 @@ class Core {
private static final int SYNC_BATCH_SIZE = 20;
private static final int DOWNLOAD_BATCH_SIZE = 20;
private static final long YIELD_DURATION = 200L; // milliseconds
private static final long MIN_HIDE = 60 * 1000L; // milliseconds
static void processOperations(
Context context,
@ -291,7 +292,7 @@ class Core {
// Delete temporary copy in target folder
if (newid != null) {
db.message().deleteMessage(newid);
db.message().setMessageUiHide(message.id, false);
db.message().setMessageUiHide(message.id, 0L);
}
}
@ -1349,7 +1350,7 @@ class Core {
message.ui_seen = seen;
message.ui_answered = answered;
message.ui_flagged = flagged;
message.ui_hide = false;
message.ui_hide = 0L;
message.ui_found = false;
message.ui_ignored = seen;
message.ui_browsed = browsed;
@ -1455,10 +1456,10 @@ class Core {
" keywords=" + TextUtils.join(" ", keywords));
}
if (message.ui_hide && !browsed &&
if (message.ui_hide != 0 && message.ui_hide + MIN_HIDE < new Date().getTime() &&
db.operation().getOperationCount(folder.id, message.id) == 0) {
update = true;
message.ui_hide = false;
message.ui_hide = 0L;
Log.i(folder.name + " updated id=" + message.id + " uid=" + message.uid + " unhide");
}

@ -53,7 +53,7 @@ public interface DaoAccount {
" AND folder.type <> '" + EntityFolder.DRAFTS + "'" +
" AND folder.type <> '" + EntityFolder.OUTBOX + "'" +
" AND NOT ui_seen" +
" AND NOT ui_hide) AS unseen" +
" AND ui_hide = 0) AS unseen" +
", (SELECT COUNT(identity.id)" +
" FROM identity" +
" WHERE identity.account = account.id" +

@ -40,7 +40,7 @@ public interface DaoFolder {
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" WHERE folder.account = :account AND account.synchronize" +
" GROUP BY folder.id")
List<TupleFolderEx> getFoldersEx(long account);
@ -73,7 +73,7 @@ public interface DaoFolder {
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" WHERE CASE WHEN :account IS NULL" +
" THEN folder.unified AND account.synchronize" +
" ELSE folder.account = :account AND account.synchronize" +
@ -90,7 +90,7 @@ public interface DaoFolder {
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
" FROM folder" +
" JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" WHERE account.`synchronize`" +
" AND folder.unified" +
" GROUP BY folder.id")
@ -103,7 +103,7 @@ public interface DaoFolder {
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" WHERE account.id IS NULL" +
" OR (account.`synchronize` AND folder.navigation)" +
" GROUP BY folder.id")
@ -130,7 +130,7 @@ public interface DaoFolder {
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" WHERE folder.id = :id" +
" GROUP BY folder.id")
LiveData<TupleFolderEx> liveFolderEx(long id);

@ -58,7 +58,7 @@ public interface DaoMessage {
" LEFT JOIN identity ON identity.id = message.identity" +
" JOIN folder ON folder.id = message.folder" +
" WHERE account.`synchronize`" +
" AND (NOT message.ui_hide OR :debug)" +
" AND (message.ui_hide = 0 OR :debug)" +
" AND (NOT :found OR ui_found = :found)" +
" GROUP BY account.id, CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
" HAVING (:found OR SUM(folder.unified) > 0)" +
@ -105,7 +105,7 @@ public interface DaoMessage {
" JOIN folder ON folder.id = message.folder" +
" JOIN folder AS f ON f.id = :folder" +
" WHERE (message.account = f.account OR " + is_outbox + ")" +
" AND (NOT message.ui_hide OR :debug)" +
" AND (message.ui_hide = 0 OR :debug)" +
" AND (NOT :found OR ui_found = :found)" +
" GROUP BY CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
" HAVING SUM(CASE WHEN folder.id = :folder THEN 1 ELSE 0 END) > 0" +
@ -148,7 +148,7 @@ public interface DaoMessage {
" WHERE message.account = :account" +
" AND message.thread = :thread" +
" AND (:id IS NULL OR message.id = :id)" +
" AND (NOT message.ui_hide OR :debug)" +
" AND (message.ui_hide = 0 OR :debug)" +
" ORDER BY message.received DESC" +
", CASE WHEN folder.type = '" + EntityFolder.ARCHIVE + "' THEN 1 ELSE 0 END")
DataSource.Factory<Integer, TupleMessageEx> pagedThread(long account, String thread, Long id, boolean debug);
@ -161,20 +161,20 @@ public interface DaoMessage {
" WHERE message.account = :account" +
" AND message.thread = :thread" +
" AND (:id IS NULL OR message.id = :id)" +
" AND NOT message.ui_hide" +
" AND message.ui_hide = 0" +
" GROUP BY account.id")
LiveData<TupleThreadStats> liveThreadStats(long account, String thread, Long id);
@Query("SELECT message.id FROM folder" +
" JOIN message ON message.folder = folder.id" +
" WHERE CASE WHEN :folder IS NULL THEN folder.unified ELSE folder.id = :folder END" +
" AND ui_hide")
" AND ui_hide <> 0")
LiveData<List<Long>> liveHidden(Long folder);
@Query("SELECT id FROM message" +
" WHERE account = :account" +
" AND thread = :thread" +
" AND ui_hide")
" AND ui_hide <> 0")
LiveData<List<Long>> liveHidden(long account, String thread);
@Query("SELECT COUNT(id)" +
@ -196,14 +196,14 @@ public interface DaoMessage {
@Query("SELECT id" +
" FROM message" +
" WHERE folder = :folder" +
" AND NOT ui_hide" +
" AND ui_hide = 0" +
" ORDER BY message.received DESC")
List<Long> getMessageByFolder(long folder);
@Query("SELECT id" +
" FROM message" +
" WHERE (:folder IS NULL OR folder = :folder)" +
" AND NOT ui_hide" +
" AND ui_hide = 0" +
" ORDER BY message.received DESC")
List<Long> getMessageIdsByFolder(Long folder);
@ -211,7 +211,7 @@ public interface DaoMessage {
" FROM folder" +
" JOIN message ON message.folder = folder.id" +
" WHERE CASE WHEN :folder IS NULL THEN folder.unified ELSE folder.id = :folder END" +
" AND NOT ui_hide" +
" AND ui_hide = 0" +
" AND (ui_snoozed IS NULL OR :snoozed)" +
" ORDER BY message.received DESC")
List<Long> getMessageAll(Long folder, boolean snoozed);
@ -223,7 +223,7 @@ public interface DaoMessage {
" AND (:id IS NULL OR message.id = :id)" +
" AND (:folder IS NULL OR message.folder = :folder)" +
" AND NOT uid IS NULL" +
" AND NOT ui_hide")
" AND ui_hide = 0")
List<EntityMessage> getMessageByThread(long account, String thread, Long id, Long folder);
@Query("SELECT * FROM message" +
@ -273,8 +273,8 @@ public interface DaoMessage {
" AND folder.notify" +
" AND (account.created IS NULL OR message.received > account.created)" +
" AND NOT message.ui_seen" +
" AND NOT message.ui_hide" +
" AND NOT message.ui_ignored" +
" AND message.ui_hide = 0" +
" ORDER BY message.received")
LiveData<List<TupleMessageEx>> liveUnseenNotify();
@ -285,8 +285,8 @@ public interface DaoMessage {
" AND folder.unified" +
" AND (account.created IS NULL OR message.received > account.created)" +
" AND NOT message.ui_seen" +
" AND NOT message.ui_hide" +
" AND NOT message.ui_ignored" +
" AND message.ui_hide = 0" +
" ORDER BY message.received")
int getUnseenUnified();
@ -351,10 +351,10 @@ public interface DaoMessage {
int setMessageUiAnswered(long id, boolean ui_answered);
@Query("UPDATE message SET ui_hide = :ui_hide WHERE id = :id")
int setMessageUiHide(long id, boolean ui_hide);
int setMessageUiHide(long id, long ui_hide);
@Query("UPDATE message SET ui_hide = :ui_hide WHERE folder = :folder AND uid = :uid")
int setMessageUiHide(long folder, long uid, boolean ui_hide);
int setMessageUiHide(long folder, long uid, long ui_hide);
@Query("UPDATE message SET ui_ignored = :ui_ignored WHERE id = :id")
int setMessageUiIgnored(long id, boolean ui_ignored);

@ -135,7 +135,7 @@ public class EntityMessage implements Serializable {
@NonNull
public Boolean ui_flagged = false;
@NonNull
public Boolean ui_hide = false;
public Long ui_hide = 0L;
@NonNull
public Boolean ui_found = false;
@NonNull

@ -132,7 +132,7 @@ public class EntityOperation {
return;
if (!EntityFolder.ARCHIVE.equals(source.type) || EntityFolder.TRASH.equals(target.type))
db.message().setMessageUiHide(message.id, true);
db.message().setMessageUiHide(message.id, new Date().getTime());
Calendar cal_keep = Calendar.getInstance();
cal_keep.add(Calendar.DAY_OF_MONTH, -target.keep_days);
@ -204,7 +204,7 @@ public class EntityOperation {
name = RAW;
} else if (DELETE.equals(name))
db.message().setMessageUiHide(message.id, true);
db.message().setMessageUiHide(message.id, new Date().getTime());
} catch (JSONException ex) {
Log.e(ex);

@ -1926,7 +1926,7 @@ public class FragmentCompose extends FragmentBase {
db.beginTransaction();
draft = db.message().getMessage(id);
if (draft == null || draft.ui_hide) {
if (draft == null || draft.ui_hide != 0) {
// New draft
if ("edit".equals(action))
throw new MessageRemovedException("Draft for edit was deleted hide=" + (draft != null));
@ -2307,7 +2307,7 @@ public class FragmentCompose extends FragmentBase {
@Override
public void onChanged(EntityMessage draft) {
// Draft was deleted
if (draft == null || draft.ui_hide)
if (draft == null || draft.ui_hide != 0)
finish();
else {
tvNoInternet.setTag(draft.content);
@ -2399,7 +2399,7 @@ public class FragmentCompose extends FragmentBase {
EntityIdentity identity = db.identity().getIdentity(iid);
// Draft deleted by server
if (draft == null || draft.ui_hide)
if (draft == null || draft.ui_hide != 0)
throw new MessageRemovedException("Draft for action was deleted hide=" + (draft != null));
Log.i("Load action id=" + draft.id + " action=" + getActionName(action));
@ -2420,7 +2420,7 @@ public class FragmentCompose extends FragmentBase {
draft.uid = uid;
draft.msgid = msgid;
draft.content = false;
draft.ui_hide = true;
draft.ui_hide = new Date().getTime();
draft.id = db.message().insertMessage(draft);
EntityOperation.queue(context, draft, EntityOperation.DELETE); // by msgid
@ -2431,7 +2431,7 @@ public class FragmentCompose extends FragmentBase {
draft.uid = null;
draft.msgid = EntityMessage.generateMessageId();
draft.content = true;
draft.ui_hide = false;
draft.ui_hide = 0L;
db.message().updateMessage(draft);
EntityOperation.queue(context, draft, EntityOperation.ADD);
}
@ -2635,7 +2635,7 @@ public class FragmentCompose extends FragmentBase {
draft.id = null;
draft.folder = db.folder().getOutbox().id;
draft.uid = null;
draft.ui_hide = false;
draft.ui_hide = 0L;
draft.id = db.message().insertMessage(draft);
Helper.writeText(draft.getFile(context), body);
if (refDraftFile.exists()) {

@ -1235,7 +1235,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
message.account, message.thread, threading && thread ? null : id, message.folder);
for (EntityMessage threaded : messages) {
result.add(new MessageTarget(threaded, account, target));
db.message().setMessageUiHide(threaded.id, true);
db.message().setMessageUiHide(threaded.id, new Date().getTime());
// Prevent new message notification on undo
db.message().setMessageUiIgnored(threaded.id, true);
}
@ -3254,7 +3254,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
ArrayList<MessageTarget> result = args.getParcelableArrayList("result");
for (MessageTarget target : result) {
Log.i("Move undo id=" + target.id);
db.message().setMessageUiHide(target.id, false);
db.message().setMessageUiHide(target.id, 0L);
}
return null;
}
@ -3292,7 +3292,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (MessageTarget target : result) {
EntityMessage message = db.message().getMessage(target.id);
if (message != null && message.ui_hide) {
if (message != null && message.ui_hide != 0) {
Log.i("Move id=" + id + " target=" + target.folder.name);
EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id);
}

@ -41,6 +41,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class FragmentOperations extends FragmentBase {
@ -149,7 +150,7 @@ public class FragmentOperations extends FragmentBase {
for (EntityOperation op : ops) {
Log.w("Deleting operation=" + op.id + " error=" + op.error);
if (op.message != null)
db.message().setMessageUiHide(op.message, false);
db.message().setMessageUiHide(op.message, 0L);
db.operation().deleteOperation(op.id);
}
return null;

@ -356,7 +356,7 @@ public class ServiceSend extends LifecycleService {
EntityOperation.queue(this, message, EntityOperation.ADD);
} else {
if (!BuildConfig.DEBUG && !debug)
db.message().setMessageUiHide(message.id, true);
db.message().setMessageUiHide(message.id, new Date().getTime());
}
if (message.inreplyto != null) {

@ -847,7 +847,7 @@ public class ServiceSynchronize extends LifecycleService {
long uid = ifolder.getUID(imessage);
DB db = DB.getInstance(ServiceSynchronize.this);
int count = db.message().setMessageUiHide(folder.id, uid, true);
int count = db.message().setMessageUiHide(folder.id, uid, new Date().getTime());
// Will be deleted on next sync
Log.i(folder.name + " deleted uid=" + uid + " count=" + count);

Loading…
Cancel
Save