File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
WordPress/src/main/java/org/wordpress/android Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -398,6 +398,14 @@ public static int deletePostsWithTag(final ReaderTag tag) {
398398 return numDeleted ;
399399 }
400400
401+ /*
402+ * delete all the posts from the blogs we no longer follow
403+ */
404+ public static int deletePostsFromUnfollowedBlogs () {
405+ return ReaderDatabase .getWritableDb ().delete ("tbl_posts" ,
406+ "blog_id NOT IN (SELECT DISTINCT blog_id FROM tbl_blog_info WHERE tbl_blog_info.is_following != 0)" , null );
407+ }
408+
401409 public static int deletePostsInBlog (long blogId ) {
402410 String [] args = {Long .toString (blogId )};
403411 return ReaderDatabase .getWritableDb ().delete ("tbl_posts" , "blog_id = ?" , args );
Original file line number Diff line number Diff line change @@ -261,16 +261,24 @@ public void onErrorResponse(VolleyError volleyError) {
261261 // request using ?meta=site,feed to get extra info
262262 WordPress .getRestClientUtilsV1_1 ().get ("read/following/mine?meta=site%2Cfeed" , listener , errorListener );
263263 }
264+
264265 private void handleFollowedBlogsResponse (final JSONObject jsonObject ) {
265266 new Thread () {
266267 @ Override
267268 public void run () {
268269 ReaderBlogList serverBlogs = ReaderBlogList .fromJson (jsonObject );
269270 ReaderBlogList localBlogs = ReaderBlogTable .getFollowedBlogs ();
270271
271- if (!localBlogs .isSameList (serverBlogs )) {
272+ boolean followedBlogsChanged = !localBlogs .isSameList (serverBlogs );
273+
274+ if (followedBlogsChanged ) {
272275 ReaderBlogTable .setFollowedBlogs (serverBlogs );
273276 AppLog .d (AppLog .T .READER , "reader blogs service > followed blogs changed" );
277+ }
278+
279+ int numberOfDeletedPosts = ReaderPostTable .deletePostsFromUnfollowedBlogs ();
280+
281+ if (followedBlogsChanged || numberOfDeletedPosts > 0 ) {
274282 EventBus .getDefault ().post (new ReaderEvents .FollowedBlogsChanged ());
275283 }
276284
You can’t perform that action at this time.
0 commit comments