From 59472e7f6785e2bc03d315654147b7e76d60a224 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 22 Nov 2022 09:33:55 +0100 Subject: [PATCH 1/3] Fix db calls --- .../client/entities/app/StatusCache.java | 132 +++--------------- .../viewmodel/mastodon/NotificationsVM.java | 74 +++++----- .../viewmodel/mastodon/TimelinesVM.java | 68 ++++----- 3 files changed, 87 insertions(+), 187 deletions(-) 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 655dbc1e7..e40206572 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 @@ -24,18 +24,13 @@ import com.google.gson.annotations.SerializedName; import java.util.ArrayList; import java.util.Calendar; -import java.util.Collections; import java.util.Date; import java.util.List; import app.fedilab.android.activities.MainActivity; import app.fedilab.android.client.entities.api.Conversation; -import app.fedilab.android.client.entities.api.Conversations; import app.fedilab.android.client.entities.api.Notification; -import app.fedilab.android.client.entities.api.Notifications; -import app.fedilab.android.client.entities.api.Pagination; import app.fedilab.android.client.entities.api.Status; -import app.fedilab.android.client.entities.api.Statuses; import app.fedilab.android.exception.DBException; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.MastodonHelper; @@ -266,36 +261,21 @@ public class StatusCache { if (db == null) { throw new DBException("db is null. Wrong initialization."); } - Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUS_CACHE + String query = "select count(*) from " + Sqlite.TABLE_STATUS_CACHE + " where " + Sqlite.COL_STATUS_ID + " = '" + statusCache.status_id + "'" + " AND " + Sqlite.COL_INSTANCE + " = '" + statusCache.instance + "'" - + " AND " + Sqlite.COL_USER_ID + "= '" + statusCache.user_id + "'", null); + + " AND " + Sqlite.COL_USER_ID + "= '" + statusCache.user_id + "'"; + if (statusCache.type != null) { + query += " AND " + Sqlite.COL_TYPE + " = '" + statusCache.type.getValue() + "'"; + } + + Cursor mCount = db.rawQuery(query, null); mCount.moveToFirst(); int count = mCount.getInt(0); mCount.close(); return (count > 0); } - /** - * Check if a status exists in db - * - * @param status Status {@link Status} - * @return boolean - StatusCache exists - * @throws DBException Exception - */ - public boolean statusExist(Status status) throws DBException { - if (db == null) { - throw new DBException("db is null. Wrong initialization."); - } - Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUS_CACHE - + " where " + Sqlite.COL_STATUS_ID + " = '" + status.id + "'" - + " AND " + Sqlite.COL_INSTANCE + " = '" + MainActivity.currentInstance + "'" - + " AND " + Sqlite.COL_USER_ID + "= '" + MainActivity.currentUserID + "'", null); - mCount.moveToFirst(); - int count = mCount.getInt(0); - mCount.close(); - return (count > 0); - } /** * Insert a status in db @@ -313,7 +293,9 @@ public class StatusCache { values.put(Sqlite.COL_INSTANCE, statusCache.instance); values.put(Sqlite.COL_SLUG, slug); values.put(Sqlite.COL_STATUS_ID, statusCache.status_id); - values.put(Sqlite.COL_TYPE, statusCache.type.getValue()); + if (type != null) { + values.put(Sqlite.COL_TYPE, statusCache.type.getValue()); + } if (statusCache.status != null) { values.put(Sqlite.COL_STATUS, mastodonStatusToStringStorage(statusCache.status)); } @@ -345,8 +327,6 @@ public class StatusCache { throw new DBException("db is null. Wrong initialization."); } ContentValues values = new ContentValues(); - values.put(Sqlite.COL_USER_ID, statusCache.user_id); - values.put(Sqlite.COL_STATUS_ID, statusCache.status_id); if (statusCache.status != null) { values.put(Sqlite.COL_STATUS, mastodonStatusToStringStorage(statusCache.status)); } @@ -360,8 +340,8 @@ public class StatusCache { //Inserts token try { return db.update(Sqlite.TABLE_STATUS_CACHE, - values, Sqlite.COL_STATUS_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?", - new String[]{statusCache.status_id, statusCache.instance}); + values, Sqlite.COL_STATUS_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_TYPE + " =? AND " + Sqlite.COL_USER_ID + " =?", + new String[]{statusCache.status_id, statusCache.instance, statusCache.type != null ? statusCache.type.getValue() : "", statusCache.user_id}); } catch (Exception e) { e.printStackTrace(); return -1; @@ -543,10 +523,10 @@ public class StatusCache { * @param user_id String - us * @param max_id String - status having max id * @param min_id String - status having min id - * @return Statuses + * @return List * @throws DBException - throws a db exception */ - public Notifications getNotifications(List exclude_type, String instance, String user_id, String max_id, String min_id, String since_id) throws DBException { + public List getNotifications(List exclude_type, String instance, String user_id, String max_id, String min_id, String since_id) throws DBException { if (db == null) { throw new DBException("db is null. Wrong initialization."); } @@ -573,7 +553,7 @@ public class StatusCache { } try { Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + order, limit); - return createNotificationReply(cursorToListOfNotifications(c)); + return cursorToListOfNotifications(c); } catch (Exception e) { e.printStackTrace(); return null; @@ -588,10 +568,10 @@ public class StatusCache { * @param user_id String - us * @param max_id String - status having max id * @param min_id String - status having min id - * @return Statuses + * @return List * @throws DBException - throws a db exception */ - public Conversations getConversations(String instance, String user_id, String max_id, String min_id, String since_id) throws DBException { + public List getConversations(String instance, String user_id, String max_id, String min_id, String since_id) throws DBException { if (db == null) { throw new DBException("db is null. Wrong initialization."); } @@ -607,10 +587,9 @@ public class StatusCache { selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' "; limit = null; } - try { Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + order, limit); - return createConversationReply(cursorToListOfConversations(c)); + return cursorToListOfConversations(c); } catch (Exception e) { e.printStackTrace(); return null; @@ -625,10 +604,10 @@ public class StatusCache { * @param user_id String - us * @param max_id String - status having max id * @param min_id String - status having min id - * @return Statuses + * @return List * @throws DBException - throws a db exception */ - public Statuses geStatuses(String slug, String instance, String user_id, String max_id, String min_id, String since_id) throws DBException { + public List geStatuses(String slug, String instance, String user_id, String max_id, String min_id, String since_id) throws DBException { if (db == null) { throw new DBException("db is null. Wrong initialization."); } @@ -646,7 +625,7 @@ public class StatusCache { } try { Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + order, limit); - return createStatusReply(cursorToListOfStatuses(c)); + return cursorToListOfStatuses(c); } catch (Exception e) { e.printStackTrace(); return null; @@ -769,75 +748,6 @@ public class StatusCache { return conversationList; } - /** - * Create a reply from db in the same way than API call - * - * @param notificationList List - * @return Notifications (with pagination) - */ - private Notifications createNotificationReply(List notificationList) { - Notifications notifications = new Notifications(); - notifications.notifications = notificationList; - Pagination pagination = new Pagination(); - if (notificationList != null && notificationList.size() > 0) { - //Status list is inverted, it happens for min_id due to ASC ordering - if (Helper.compareTo(notificationList.get(0).id, notificationList.get(notificationList.size() - 1).id) < 0) { - Collections.reverse(notificationList); - notifications.notifications = notificationList; - } - pagination.max_id = notificationList.get(0).id; - pagination.min_id = notificationList.get(notificationList.size() - 1).id; - } - notifications.pagination = pagination; - return notifications; - } - - - /** - * Create a reply from db in the same way than API call - * - * @param conversationList List - * @return Conversations (with pagination) - */ - private Conversations createConversationReply(List conversationList) { - Conversations conversations = new Conversations(); - conversations.conversations = conversationList; - Pagination pagination = new Pagination(); - if (conversationList != null && conversationList.size() > 0) { - //Status list is inverted, it happens for min_id due to ASC ordering - if (Helper.compareTo(conversationList.get(0).id, conversationList.get(conversationList.size() - 1).id) < 0) { - Collections.reverse(conversationList); - conversations.conversations = conversationList; - } - pagination.max_id = conversationList.get(0).id; - pagination.min_id = conversationList.get(conversationList.size() - 1).id; - } - conversations.pagination = pagination; - return conversations; - } - - /** - * Create a reply from db in the same way than API call - * - * @param statusList List - * @return Statuses (with pagination) - */ - private Statuses createStatusReply(List statusList) { - Statuses statuses = new Statuses(); - statuses.statuses = statusList; - Pagination pagination = new Pagination(); - if (statusList != null && statusList.size() > 0) { - //Status list is inverted, it happens for min_id due to ASC ordering - if (Helper.compareTo(statusList.get(0).id, statusList.get(statusList.size() - 1).id) < 0) { - Collections.reverse(statusList); - statuses.statuses = statusList; - } - pagination.max_id = statusList.get(0).id; - pagination.min_id = statusList.get(statusList.size() - 1).id; - } - statuses.pagination = pagination; - return statuses; - } /** * Read cursor and hydrate without closing it diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java index e58e4bd34..16271d4e0 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java @@ -112,24 +112,24 @@ public class NotificationsVM extends AndroidViewModel { if (notificationsResponse.isSuccessful()) { List notFiltered = notificationsResponse.body(); notifications.notifications = TimelineHelper.filterNotification(getApplication().getApplicationContext(), notFiltered); - addFetchMoreNotifications(notifications.notifications, notificationList, timelineParams); notifications.pagination = MastodonHelper.getPagination(notificationsResponse.headers()); - if (notifications.notifications != null && notifications.notifications.size() > 0) { addFetchMoreNotifications(notifications.notifications, notificationList, timelineParams); - for (Notification notification : notifications.notifications) { - StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext()); - StatusCache statusCache = new StatusCache(); - statusCache.instance = timelineParams.instance; - statusCache.user_id = timelineParams.userId; - statusCache.notification = notification; - statusCache.slug = notification.type; - statusCache.type = Timeline.TimeLineEnum.NOTIFICATION; - statusCache.status_id = notification.id; - try { - statusCacheDAO.insertOrUpdate(statusCache, notification.type); - } catch (DBException e) { - e.printStackTrace(); + if (notFiltered != null && notFiltered.size() > 0) { + for (Notification notification : notFiltered) { + StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext()); + StatusCache statusCache = new StatusCache(); + statusCache.instance = timelineParams.instance; + statusCache.user_id = timelineParams.userId; + statusCache.notification = notification; + statusCache.slug = notification.type; + statusCache.type = Timeline.TimeLineEnum.NOTIFICATION; + statusCache.status_id = notification.id; + try { + statusCacheDAO.insertOrUpdate(statusCache, notification.type); + } catch (DBException e) { + e.printStackTrace(); + } } } } @@ -146,41 +146,39 @@ public class NotificationsVM extends AndroidViewModel { return notificationsMutableLiveData; } - public LiveData getNotificationCache(List notificationList, TimelinesVM.TimelineParams timelineParams) { + public LiveData getNotificationCache(List timelineNotification, TimelinesVM.TimelineParams timelineParams) { notificationsMutableLiveData = new MutableLiveData<>(); new Thread(() -> { StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext()); - Notifications notifications = null; + Notifications notifications = new Notifications(); + List notificationsDb; try { - 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) { - if (notificationList != null) { - List notPresentNotifications = new ArrayList<>(); - for (Notification notification : notifications.notifications) { - if (!notificationList.contains(notification)) { - notification.cached = true; - notPresentNotifications.add(notification); - } + notificationsDb = statusCacheDAO.getNotifications(timelineParams.excludeType, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId); + if (notificationsDb != null && notificationsDb.size() > 0) { + if (timelineNotification != null) { + List notPresentNotifications = new ArrayList<>(); + for (Notification notification : notificationsDb) { + if (!timelineNotification.contains(notification)) { + notification.cached = true; + notPresentNotifications.add(notification); } - //Only not already present statuses are added - notifications.notifications = notPresentNotifications; - } - TimelineHelper.filterNotification(getApplication().getApplicationContext(), notifications.notifications); - if (notifications.notifications.size() > 0) { - addFetchMoreNotifications(notifications.notifications, notificationList, timelineParams); - notifications.pagination = new Pagination(); - notifications.pagination.min_id = notifications.notifications.get(0).id; - notifications.pagination.max_id = notifications.notifications.get(notifications.notifications.size() - 1).id; } + //Only not already present statuses are added + notificationsDb = notPresentNotifications; + } + notifications.notifications = TimelineHelper.filterNotification(getApplication().getApplicationContext(), notificationsDb); + if (notifications.notifications.size() > 0) { + addFetchMoreNotifications(notifications.notifications, timelineNotification, timelineParams); + notifications.pagination = new Pagination(); + notifications.pagination.min_id = notifications.notifications.get(0).id; + notifications.pagination.max_id = notifications.notifications.get(notifications.notifications.size() - 1).id; } } } catch (DBException e) { e.printStackTrace(); } Handler mainHandler = new Handler(Looper.getMainLooper()); - Notifications finalNotifications = notifications; - Runnable myRunnable = () -> notificationsMutableLiveData.setValue(finalNotifications); + Runnable myRunnable = () -> notificationsMutableLiveData.setValue(notifications); mainHandler.post(myRunnable); }).start(); return notificationsMutableLiveData; diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index b3fff9571..79fc7669f 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -463,21 +463,21 @@ public class TimelinesVM extends AndroidViewModel { StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext()); Statuses statuses = new Statuses(); try { - Statuses statusesDb = statusCacheDAO.geStatuses(timelineParams.slug, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId); - if (statusesDb != null && statusesDb.statuses != null && statusesDb.statuses.size() > 0) { + List statusesDb = statusCacheDAO.geStatuses(timelineParams.slug, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId); + if (statusesDb != null && statusesDb.size() > 0) { if (timelineStatuses != null) { List notPresentStatuses = new ArrayList<>(); - for (Status status : statusesDb.statuses) { + for (Status status : statusesDb) { if (!timelineStatuses.contains(status)) { status.cached = true; notPresentStatuses.add(status); } } //Only not already present statuses are added - statusesDb.statuses = notPresentStatuses; + statusesDb = notPresentStatuses; } - statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusesDb.statuses, timelineParams.type); - if (statuses.statuses != null && statuses.statuses.size() > 0) { + statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusesDb, timelineParams.type); + if (statuses.statuses.size() > 0) { addFetchMore(statuses.statuses, timelineStatuses, timelineParams); statuses.pagination = new Pagination(); statuses.pagination.min_id = statuses.statuses.get(0).id; @@ -528,21 +528,16 @@ public class TimelinesVM extends AndroidViewModel { conversationListMutableLiveData = new MutableLiveData<>(); MastodonTimelinesService mastodonTimelinesService = init(timelineParams.instance); new Thread(() -> { - Conversations conversations = null; + Conversations conversations = new Conversations(); Call> conversationsCall = mastodonTimelinesService.getConversations(timelineParams.token, timelineParams.maxId, timelineParams.sinceId, timelineParams.minId, timelineParams.limit); if (conversationsCall != null) { - conversations = new Conversations(); try { Response> conversationsResponse = conversationsCall.execute(); if (conversationsResponse.isSuccessful()) { - List conversationList = conversationsResponse.body(); - conversations.conversations = conversationList; + conversations.conversations = conversationsResponse.body(); conversations.pagination = MastodonHelper.getPagination(conversationsResponse.headers()); - - if (conversationList != null && conversationList.size() > 0) { - - addFetchMoreConversation(conversationList, conversationsTimeline, timelineParams); - + if (conversations.conversations != null && conversations.conversations.size() > 0) { + addFetchMoreConversation(conversations.conversations, conversationsTimeline, timelineParams); for (Conversation conversation : conversations.conversations) { StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext()); StatusCache statusCache = new StatusCache(); @@ -564,8 +559,7 @@ public class TimelinesVM extends AndroidViewModel { } } Handler mainHandler = new Handler(Looper.getMainLooper()); - Conversations finalConversations = conversations; - Runnable myRunnable = () -> conversationListMutableLiveData.setValue(finalConversations); + Runnable myRunnable = () -> conversationListMutableLiveData.setValue(conversations); mainHandler.post(myRunnable); }).start(); @@ -577,36 +571,34 @@ public class TimelinesVM extends AndroidViewModel { conversationListMutableLiveData = new MutableLiveData<>(); new Thread(() -> { StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext()); - Conversations conversations = null; + Conversations conversations = new Conversations(); try { - conversations = statusCacheDAO.getConversations(timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId); - if (conversations != null) { - if (conversations.conversations != null && conversations.conversations.size() > 0) { - if (timelineConversations != null) { - List notPresentConversations = new ArrayList<>(); - for (Conversation conversation : conversations.conversations) { - if (!timelineConversations.contains(conversation)) { - conversation.cached = true; - timelineConversations.add(conversation); - } + List conversationsDb = statusCacheDAO.getConversations(timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId); + if (conversationsDb != null && conversationsDb.size() > 0) { + if (timelineConversations != null) { + List notPresentConversations = new ArrayList<>(); + for (Conversation conversation : conversationsDb) { + if (!timelineConversations.contains(conversation)) { + conversation.cached = true; + timelineConversations.add(conversation); } - //Only not already present statuses are added - conversations.conversations = notPresentConversations; - } - if (conversations.conversations.size() > 0) { - addFetchMoreConversation(conversations.conversations, timelineConversations, timelineParams); - conversations.pagination = new Pagination(); - conversations.pagination.min_id = conversations.conversations.get(0).id; - conversations.pagination.max_id = conversations.conversations.get(conversations.conversations.size() - 1).id; } + //Only not already present statuses are added + conversationsDb = notPresentConversations; + } + conversations.conversations = conversationsDb; + if (conversations.conversations.size() > 0) { + addFetchMoreConversation(conversations.conversations, timelineConversations, timelineParams); + conversations.pagination = new Pagination(); + conversations.pagination.min_id = conversations.conversations.get(0).id; + conversations.pagination.max_id = conversations.conversations.get(conversations.conversations.size() - 1).id; } } } catch (DBException e) { e.printStackTrace(); } Handler mainHandler = new Handler(Looper.getMainLooper()); - Conversations finalConversations = conversations; - Runnable myRunnable = () -> conversationListMutableLiveData.setValue(finalConversations); + Runnable myRunnable = () -> conversationListMutableLiveData.setValue(conversations); mainHandler.post(myRunnable); }).start(); return conversationListMutableLiveData; From 0bcb4e0fca1bddd66047bcf1ec266beaf9444d1a Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 22 Nov 2022 11:03:43 +0100 Subject: [PATCH 2/3] Fix #515 - set resolve to false when searching accounts --- .../android/client/entities/app/StatusCache.java | 2 +- app/src/main/res/layout/activity_actions.xml | 16 ++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) 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 e40206572..61868bd3b 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 @@ -293,7 +293,7 @@ public class StatusCache { values.put(Sqlite.COL_INSTANCE, statusCache.instance); values.put(Sqlite.COL_SLUG, slug); values.put(Sqlite.COL_STATUS_ID, statusCache.status_id); - if (type != null) { + if (statusCache.type != null) { values.put(Sqlite.COL_TYPE, statusCache.type.getValue()); } if (statusCache.status != null) { diff --git a/app/src/main/res/layout/activity_actions.xml b/app/src/main/res/layout/activity_actions.xml index 88ce22459..052ae1c6a 100644 --- a/app/src/main/res/layout/activity_actions.xml +++ b/app/src/main/res/layout/activity_actions.xml @@ -71,6 +71,22 @@ app:iconTint="@color/cyanea_accent_dark_reference" app:strokeColor="@color/cyanea_accent_dark_reference" /> + + + Signed up Suggestions Not interested + Blocked domains \ No newline at end of file From 28e10ddc82ca4de41d9f62221179bb9c2d560330 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 22 Nov 2022 12:32:16 +0100 Subject: [PATCH 3/3] Fix pagination from db --- .../android/client/entities/app/StatusCache.java | 11 +++++------ .../app/fedilab/android/helper/TimelineHelper.java | 1 - 2 files changed, 5 insertions(+), 7 deletions(-) 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 61868bd3b..626722580 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 @@ -242,7 +242,6 @@ public class StatusCache { } Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUS_CACHE + " where " + Sqlite.COL_TYPE + " != '" + Timeline.TimeLineEnum.HOME.getValue() + "'" - + " AND " + Sqlite.COL_INSTANCE + " = '" + baseAccount.instance + "'" + " AND " + Sqlite.COL_USER_ID + "= '" + baseAccount.user_id + "'", null); mCount.moveToFirst(); int count = mCount.getInt(0); @@ -465,8 +464,8 @@ public class StatusCache { } try { return db.delete(Sqlite.TABLE_STATUS_CACHE, - Sqlite.COL_TYPE + " != ? AND " + Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?", - new String[]{Timeline.TimeLineEnum.HOME.getValue(), account.user_id, account.instance}); + Sqlite.COL_TYPE + " != ? AND " + Sqlite.COL_USER_ID + " = ?", + new String[]{Timeline.TimeLineEnum.HOME.getValue(), account.user_id}); } catch (Exception e) { e.printStackTrace(); return -1; @@ -552,7 +551,7 @@ public class StatusCache { selection += "AND " + Sqlite.COL_SLUG + " NOT IN (" + exclude + ") "; } try { - Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + order, limit); + Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + " + 0 " + order, limit); return cursorToListOfNotifications(c); } catch (Exception e) { e.printStackTrace(); @@ -588,7 +587,7 @@ public class StatusCache { limit = null; } try { - Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + order, limit); + Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + " + 0 " + order, limit); return cursorToListOfConversations(c); } catch (Exception e) { e.printStackTrace(); @@ -624,7 +623,7 @@ public class StatusCache { limit = null; } try { - Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + order, limit); + Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, selection, null, Sqlite.COL_STATUS_ID, null, Sqlite.COL_STATUS_ID + " + 0 " + order, limit); return cursorToListOfStatuses(c); } catch (Exception e) { e.printStackTrace(); 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 3dd0704ea..02ce2b2fa 100644 --- a/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/TimelineHelper.java @@ -177,7 +177,6 @@ public class TimelineHelper { public static List filterNotification(Context context, List notifications) { //A security to make sure filters have been fetched before displaying messages List notificationToRemove = new ArrayList<>(); - if (!BaseMainActivity.filterFetched) { try { FiltersVM filtersVM = new ViewModelProvider((ViewModelStoreOwner) context).get(FiltersVM.class);