diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java b/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java index 733e28ef7..daa3ade37 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java @@ -35,6 +35,9 @@ public class Notification { public Account account; @SerializedName("status") public Status status; + @SerializedName("cached") + public boolean cached; + public PositionFetchMore positionFetchMore = PositionFetchMore.BOTTOM; public enum PositionFetchMore { diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java b/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java index 96c59221b..3d28f2b1c 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java @@ -358,7 +358,7 @@ public class StatusCache { throw new DBException("db is null. Wrong initialization."); } String order = " DESC"; - String selection = Sqlite.COL_INSTANCE + "='" + instance + "' AND " + Sqlite.COL_USER_ID + "= '" + user_id + "' AND " + Sqlite.COL_SLUG + "= '" + Timeline.TimeLineEnum.NOTIFICATION.getValue() + "' "; + 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 + "' "; @@ -369,6 +369,7 @@ public class StatusCache { 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) { diff --git a/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java index 471c90fc4..69fa3e2a5 100644 --- a/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java @@ -101,6 +101,9 @@ public class TimelineHelper { //If there are filters: if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0 && statuses != null && statuses.size() > 0) { + for (Status status : statuses) { + status.cached = cached; + } for (Filter filter : BaseMainActivity.mainFilters) { if (filter.irreversible) { //Dealt by the server continue; @@ -111,7 +114,6 @@ public class TimelineHelper { Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)"); for (Status status : statuses) { String content; - status.cached = cached; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) content = Html.fromHtml(status.content, Html.FROM_HTML_MODE_LEGACY).toString(); else @@ -136,7 +138,6 @@ public class TimelineHelper { } else { for (Status status : statuses) { String content; - status.cached = cached; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) content = Html.fromHtml(status.content, Html.FROM_HTML_MODE_LEGACY).toString(); else @@ -175,7 +176,7 @@ public class TimelineHelper { * @param notifications - List of {@link Notification} * @return filtered List */ - public static List filterNotification(Context context, List notifications) { + public static List filterNotification(Context context, List notifications, boolean cached) { //A security to make sure filters have been fetched before displaying messages List notificationToRemove = new ArrayList<>(); if (!BaseMainActivity.filterFetched) { @@ -200,6 +201,7 @@ public class TimelineHelper { if (filter.whole_word) { Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)"); for (Notification notification : notifications) { + notification.cached = cached; if (notification.status != null) { String content; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) @@ -215,6 +217,7 @@ public class TimelineHelper { } else { for (Notification notification : notifications) { String content; + notification.cached = cached; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) content = Html.fromHtml(notification.status.content, Html.FROM_HTML_MODE_LEGACY).toString(); else @@ -224,6 +227,10 @@ public class TimelineHelper { } } } + } else { + for (Notification notification : notifications) { + notification.cached = cached; + } } } } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java index 0e499c551..87a255829 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java @@ -186,6 +186,11 @@ public class NotificationAdapter extends RecyclerView.Adapter> notificationsResponse = notificationsCall.execute(); if (notificationsResponse.isSuccessful()) { - notifications.notifications = notificationsResponse.body(); - TimelineHelper.filterNotification(getApplication().getApplicationContext(), notifications.notifications); + List notFiltered = notificationsResponse.body(); + notifications.notifications = TimelineHelper.filterNotification(getApplication().getApplicationContext(), notFiltered, false); addFetchMoreNotifications(notifications.notifications, notificationList, timelineParams); notifications.pagination = MastodonHelper.getPagination(notificationsResponse.headers()); @@ -154,7 +154,7 @@ public class NotificationsVM extends AndroidViewModel { notifications = statusCacheDAO.getNotifications(timelineParams.excludeType, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId); if (notifications != null) { if (notifications.notifications != null && notifications.notifications.size() > 0) { - TimelineHelper.filterNotification(getApplication().getApplicationContext(), notifications.notifications); + TimelineHelper.filterNotification(getApplication().getApplicationContext(), notifications.notifications, true); addFetchMoreNotifications(notifications.notifications, notificationList, timelineParams); notifications.pagination = new Pagination(); notifications.pagination.min_id = notifications.notifications.get(0).id; diff --git a/app/src/main/res/layout/drawer_follow.xml b/app/src/main/res/layout/drawer_follow.xml index 3d17f2b2c..759432ca1 100644 --- a/app/src/main/res/layout/drawer_follow.xml +++ b/app/src/main/res/layout/drawer_follow.xml @@ -34,6 +34,17 @@ android:layout_height="wrap_content" android:orientation="horizontal"> + +