From be54c499185af44e18177c5e4d1dedde8f1ff663 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 14 Aug 2023 16:56:40 +0200 Subject: [PATCH] Whole in timelines due to cache bug --- .../client/entities/app/StatusCache.java | 59 +++++++++++++++---- .../android/mastodon/helper/Helper.java | 9 +++ 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/StatusCache.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/StatusCache.java index 1f1c004b2..67b1ac04c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/StatusCache.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/StatusCache.java @@ -555,15 +555,28 @@ public class StatusCache { String selection = Sqlite.COL_INSTANCE + "='" + instance + "' AND " + Sqlite.COL_USER_ID + "= '" + user_id + "' AND " + Sqlite.COL_TYPE + "= '" + Timeline.TimeLineEnum.NOTIFICATION.getValue() + "' "; String limit = String.valueOf(MastodonHelper.statusesPerCall(context)); if (min_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + min_id + "' "; + if (Helper.isNumeric(min_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " > cast(" + min_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + min_id + "' "; + } order = " ASC"; } else if (max_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " < '" + max_id + "' "; + if (Helper.isNumeric(max_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " < cast(" + max_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " < '" + max_id + "' "; + } + } else if (since_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' "; + if (Helper.isNumeric(since_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " > cast(" + since_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' "; + } + limit = null; } - if (exclude_type != null && exclude_type.size() > 0) { StringBuilder exclude = new StringBuilder(); for (String excluded : exclude_type) { @@ -600,12 +613,25 @@ public class StatusCache { String selection = Sqlite.COL_INSTANCE + "='" + instance + "' AND " + Sqlite.COL_USER_ID + "= '" + user_id + "' AND " + Sqlite.COL_TYPE + "= '" + Timeline.TimeLineEnum.CONVERSATION.getValue() + "' "; String limit = String.valueOf(MastodonHelper.statusesPerCall(context)); if (min_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + min_id + "' "; + if (Helper.isNumeric(min_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " > cast(" + min_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + min_id + "' "; + } order = " ASC"; } else if (max_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " < '" + max_id + "' "; + + if (Helper.isNumeric(max_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " < cast(" + max_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " < '" + max_id + "' "; + } } else if (since_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' "; + if (Helper.isNumeric(since_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " > cast(" + since_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' "; + } limit = null; } try { @@ -636,12 +662,25 @@ public class StatusCache { String selection = Sqlite.COL_INSTANCE + "='" + instance + "' AND " + Sqlite.COL_USER_ID + "= '" + user_id + "' AND " + Sqlite.COL_SLUG + "= '" + slug + "' "; String limit = String.valueOf(MastodonHelper.statusesPerCall(context)); if (min_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + min_id + "' "; + + if (Helper.isNumeric(min_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " > cast(" + min_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + min_id + "' "; + } order = " ASC"; } else if (max_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " < '" + max_id + "' "; + if (Helper.isNumeric(max_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " < cast(" + max_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " < '" + max_id + "' "; + } } else if (since_id != null) { - selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' "; + if (Helper.isNumeric(since_id)) { + selection += "AND " + Sqlite.COL_STATUS_ID + " > cast(" + since_id + " as int) "; + } else { + selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' "; + } limit = null; } try { diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index a8933c420..864fca184 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -2072,4 +2072,13 @@ public class Helper { public interface OnFileCopied { void onFileCopied(File file); } + + public static boolean isNumeric(String str) { + try { + Double.parseDouble(str); + return true; + } catch (NumberFormatException e) { + return false; + } + } }