diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java b/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java index 6bce52c28..3b58fac14 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java @@ -12,7 +12,6 @@ import android.util.Log; import org.joinmastodon.android.BuildConfig; import org.joinmastodon.android.MastodonApp; import org.joinmastodon.android.api.requests.notifications.GetNotifications; -import org.joinmastodon.android.api.requests.timelines.GetConversationsTimeline; import org.joinmastodon.android.api.requests.timelines.GetHomeTimeline; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.model.CacheablePaginatedResponse; @@ -127,79 +126,6 @@ public class CacheController{ }); } - public void getConversationsTimeline(String maxID, int count, boolean forceReload, Callback>> callback){ - cancelDelayedClose(); - databaseThread.postRunnable(()->{ - try{ - List filters=AccountSessionManager.getInstance().getAccount(accountID).wordFilters.stream().filter(f->f.context.contains(Filter.FilterContext.HOME)).collect(Collectors.toList()); - if(!forceReload){ - SQLiteDatabase db=getOrOpenDatabase(); - try(Cursor cursor=db.query("conversations_timeline", new String[]{"json", "flags"}, maxID==null ? null : "`id` result=new ArrayList<>(); - cursor.moveToFirst(); - String newMaxID; - outer: - do{ - Status status=MastodonAPIController.gson.fromJson(cursor.getString(0), Status.class); - status.postprocess(); - int flags=cursor.getInt(1); - status.hasGapAfter=((flags & POST_FLAG_GAP_AFTER)!=0); - newMaxID=status.id; - for(Filter filter:filters){ - if(filter.matches(status)) - continue outer; - } - result.add(status); - }while(cursor.moveToNext()); - String _newMaxID=newMaxID; - uiHandler.post(()->callback.onSuccess(new CacheablePaginatedResponse<>(result, _newMaxID, true))); - return; - } - }catch(IOException x){ - Log.w(TAG, "getConversationsTimeline: corrupted status object in database", x); - } - } - new GetConversationsTimeline(maxID, null, count, null) - .setCallback(new Callback<>(){ - @Override - public void onSuccess(List result){ - callback.onSuccess(new CacheablePaginatedResponse<>(result.stream().filter(new StatusFilterPredicate(filters)).collect(Collectors.toList()), result.isEmpty() ? null : result.get(result.size()-1).id, false)); - putConversationsTimeline(result, maxID==null); - } - - @Override - public void onError(ErrorResponse error){ - callback.onError(error); - } - }) - .exec(accountID); - }catch(SQLiteException x){ - Log.w(TAG, x); - uiHandler.post(()->callback.onError(new MastodonErrorResponse(x.getLocalizedMessage(), 500, x))); - }finally{ - closeDelayed(); - } - }, 0); - } - - public void putConversationsTimeline(List posts, boolean clear){ - runOnDbThread((db)->{ - if(clear) - db.delete("conversations_timeline", null, null); - ContentValues values=new ContentValues(3); - for(Status s:posts){ - values.put("id", s.id); - values.put("json", MastodonAPIController.gson.toJson(s)); - int flags=0; - if(s.hasGapAfter) - flags|=POST_FLAG_GAP_AFTER; - values.put("flags", flags); - db.insertWithOnConflict("conversations_timeline", null, values, SQLiteDatabase.CONFLICT_REPLACE); - } - }); - } - public void getNotifications(String maxID, int count, boolean onlyMentions, boolean onlyPosts, boolean forceReload, Callback>> callback){ cancelDelayedClose(); databaseThread.postRunnable(()->{ @@ -393,18 +319,15 @@ public class CacheController{ )"""); createRecentSearchesTable(db); createPostsNotificationsTable(db); - createConversationsTimelineTable(db); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){ if(oldVersion==1){ createRecentSearchesTable(db); - createConversationsTimelineTable(db); } if(oldVersion==2){ createPostsNotificationsTable(db); - createConversationsTimelineTable(db); } } @@ -426,15 +349,6 @@ public class CacheController{ `type` INTEGER NOT NULL )"""); } - - private void createConversationsTimelineTable(SQLiteDatabase db){ - db.execSQL(""" - CREATE TABLE `conversations_timeline` ( - `id` VARCHAR(25) NOT NULL PRIMARY KEY, - `json` TEXT NOT NULL, - `flags` INTEGER NOT NULL DEFAULT 0 - )"""); - } } @FunctionalInterface diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ConversationsTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ConversationsTimelineFragment.java index 0e446b7a3..71560ef97 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ConversationsTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ConversationsTimelineFragment.java @@ -15,6 +15,7 @@ import org.joinmastodon.android.events.StatusCreatedEvent; import org.joinmastodon.android.model.CacheablePaginatedResponse; import org.joinmastodon.android.model.Filter; import org.joinmastodon.android.model.Status; +import org.joinmastodon.android.model.StatusPrivacy; import org.joinmastodon.android.ui.displayitems.GapStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.StatusDisplayItem; import org.joinmastodon.android.utils.StatusFilterPredicate; @@ -43,18 +44,17 @@ public class ConversationsTimelineFragment extends FabStatusListFragment { private List filterPosts(List items) { // Disabling this for DMs, because there are no boosts on DMs, and most of them are replies -// return items.stream().filter(i -> -// (GlobalUserPreferences.showReplies || i.inReplyToId == null) && -// (GlobalUserPreferences.showBoosts || i.reblog == null) -// ).collect(Collectors.toList()); - return items; + return items.stream().filter(i -> + (i.visibility == StatusPrivacy.DIRECT) + ).collect(Collectors.toList()); +// return items; } @Override protected void doLoadData(int offset, int count){ AccountSessionManager.getInstance() .getAccount(accountID).getCacheController() - .getConversationsTimeline(offset>0 ? maxID : null, count, refreshing, new SimpleCallback<>(this){ + .getHomeTimeline(offset>0 ? maxID : null, count, refreshing, new SimpleCallback<>(this){ @Override public void onSuccess(CacheablePaginatedResponse> result){ if(getActivity()==null) @@ -127,7 +127,7 @@ public class ConversationsTimelineFragment extends FabStatusListFragment { if(!toAdd.isEmpty()){ prependItems(toAdd, true); if (parent != null) parent.showNewPostsButton(); - AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putConversationsTimeline(toAdd, false); +// AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putHomTimeline(toAdd, false); } } @@ -166,7 +166,7 @@ public class ConversationsTimelineFragment extends FabStatusListFragment { Status gapStatus=getStatusByID(gap.parentID); if(gapStatus!=null){ gapStatus.hasGapAfter=false; - AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putConversationsTimeline(Collections.singletonList(gapStatus), false); +// AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putConversationsTimeline(Collections.singletonList(gapStatus), false); } }else{ Set idsBelowGap=new HashSet<>(); @@ -178,7 +178,7 @@ public class ConversationsTimelineFragment extends FabStatusListFragment { }else if(s.id.equals(gap.parentID)){ belowGap=true; s.hasGapAfter=false; - AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putConversationsTimeline(Collections.singletonList(s), false); +// AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putConversationsTimeline(Collections.singletonList(s), false); }else{ gapPostIndex++; } @@ -213,7 +213,7 @@ public class ConversationsTimelineFragment extends FabStatusListFragment { adapter.notifyItemChanged(getMainAdapterOffset()+gapPos); adapter.notifyItemRangeInserted(getMainAdapterOffset()+gapPos+1, targetList.size()-1); } - AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putConversationsTimeline(insertedPosts, false); +// AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putConversationsTimeline(insertedPosts, false); } }