Experiment: touched

This commit is contained in:
M66B 2024-05-07 18:48:08 +02:00
parent 3b11de947c
commit 0691568835
6 changed files with 52 additions and 11 deletions

View File

@ -358,6 +358,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
criteria.with_size,
criteria.after,
criteria.before,
criteria.touched == null ? null : new Date().getTime() - criteria.touched,
SEARCH_LIMIT_DEVICE, state.offset);
EntityLog.log(context, "Boundary device" +
" account=" + account +
@ -805,15 +806,20 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return false;
}
//
if (criteria.after != null) {
if (message.received < criteria.after)
return false;
}
//
if (criteria.before != null) {
if (message.received > criteria.before)
return false;
}
//
if (criteria.after != null) {
if (message.received < criteria.after)
if (criteria.touched != null) {
if (message.last_attempt == null || message.last_attempt < new Date().getTime() - criteria.touched)
return false;
}
@ -1042,6 +1048,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
boolean in_junk = true;
Long after = null;
Long before = null;
Integer touched = null;
private static final String FROM = "from:";
private static final String TO = "to:";
@ -1295,6 +1302,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (with_size != null)
flags.add(context.getString(R.string.title_search_flag_size,
Helper.humanReadableByteCount(with_size)));
if (touched != null)
flags.add(context.getString(R.string.title_search_flag_touched));
return (query == null ? "" : query + " ")
+ (flags.size() > 0 ? "+" : "")
+ TextUtils.join(",", flags);
@ -1326,7 +1335,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
this.in_trash == other.in_trash &&
this.in_junk == other.in_junk &&
Objects.equals(this.after, other.after) &&
Objects.equals(this.before, other.before));
Objects.equals(this.before, other.before) &&
Objects.equals(this.touched, other.touched));
} else
return false;
}
@ -1376,6 +1386,9 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (before != null)
json.put("before", before - now.getTimeInMillis());
if (touched != null)
json.put("touched", touched);
return json;
}
@ -1425,6 +1438,9 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (json.has("before"))
criteria.before = json.getLong("before") + now.getTimeInMillis();
if (json.has("touched"))
criteria.touched = json.getInt("touched");
return criteria;
}
@ -1453,7 +1469,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
" trash=" + in_trash +
" junk=" + in_junk +
" after=" + (after == null ? "" : new Date(after)) +
" before=" + (before == null ? "" : new Date(before));
" before=" + (before == null ? "" : new Date(before)) +
" touched=" + touched;
}
}
}

View File

@ -387,9 +387,10 @@ public interface DaoMessage {
" AND (:size IS NULL OR total > :size)" +
" AND (:after IS NULL OR received > :after)" +
" AND (:before IS NULL OR received < :before)" +
" AND (:touched IS NULL OR last_attempt > :touched)" +
" AND NOT message.folder IN (:exclude)" +
" GROUP BY message.id" +
" ORDER BY received DESC" +
" ORDER BY CASE WHEN :touched IS NULL THEN received ELSE last_attempt END DESC" +
" LIMIT :limit OFFSET :offset")
List<TupleMatch> matchMessages(
Long account, Long folder, long[] exclude, String find,
@ -397,7 +398,7 @@ public interface DaoMessage {
boolean unseen, boolean flagged, boolean hidden, boolean encrypted, boolean with_attachments, boolean with_notes,
int type_count, String[] types,
Integer size,
Long after, Long before,
Long after, Long before, Long touched,
int limit, int offset);
@Query("SELECT id" +
@ -930,7 +931,7 @@ public interface DaoMessage {
int setMessageVerified(long id, boolean verified);
@Query("UPDATE message SET last_attempt = :last_attempt WHERE id = :id AND NOT (last_attempt IS :last_attempt)")
int setMessageLastAttempt(long id, long last_attempt);
int setMessageLastAttempt(long id, Long last_attempt);
@Query("UPDATE message SET ui_ignored = 1" +
" WHERE NOT ui_ignored" +

View File

@ -261,7 +261,7 @@ public class EntityMessage implements Serializable {
public Integer revisions; // compose
public String warning; // persistent
public String error; // volatile
public Long last_attempt; // send
public Long last_attempt; // send / last touched
static String generateMessageId() {
return generateMessageId("localhost");

View File

@ -65,6 +65,7 @@ import java.util.List;
public class FragmentDialogSearch extends FragmentDialogBase {
private static final int MAX_SUGGESTIONS = 3;
private static final int RECENTLY_TOUCHED = 3600 * 1000; // milliseconds
@NonNull
@Override
@ -613,6 +614,24 @@ public class FragmentDialogSearch extends FragmentDialogBase {
ibUnseen.setOnClickListener(onClick);
ibFlagged.setOnClickListener(onClick);
ibHidden.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
dialog.dismiss();
BoundaryCallbackMessages.SearchCriteria criteria = new BoundaryCallbackMessages.SearchCriteria();
criteria.touched = RECENTLY_TOUCHED;
FragmentMessages.search(
context, getViewLifecycleOwner(), getParentFragmentManager(),
account, -1L,
false,
criteria);
return true;
}
});
etQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO ||

View File

@ -7830,6 +7830,9 @@ public class FragmentMessages extends FragmentBase
EntityOperation.queue(context, message, EntityOperation.BODY);
}
if (!EntityFolder.OUTBOX.equals(folder.type))
db.message().setMessageLastAttempt(message.id, new Date().getTime());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
@ -8192,7 +8195,7 @@ public class FragmentMessages extends FragmentBase
Log.i("Move id=" + target.id + " target=" + target.targetFolder.name);
db.message().setMessageUiBusy(target.id, null);
db.message().setMessageLastAttempt(target.id, new Date().getTime());
db.message().setMessageLastAttempt(target.id, null);
EntityOperation.queue(context, message, EntityOperation.MOVE, target.targetFolder.id);
}
@ -8226,7 +8229,7 @@ public class FragmentMessages extends FragmentBase
db.message().setMessageUiBusy(target.id, null);
db.message().setMessageUiHide(target.id, false);
db.message().setMessageFound(target.id, target.found);
db.message().setMessageLastAttempt(target.id, new Date().getTime());
db.message().setMessageLastAttempt(target.id, null);
}
db.setTransactionSuccessful();

View File

@ -1913,6 +1913,7 @@
<string name="title_search_flag_notes">notes</string>
<string name="title_search_flag_invite">invitation</string>
<string name="title_search_flag_size">size &gt; %1$s</string>
<string name="title_search_flag_touched">touched</string>
<string name="title_search_device">Search on device</string>
<string name="title_search_server">Search on server</string>