mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Switch all mark-read ops to new API using story_hash.
This commit is contained in:
parent
1936515aa0
commit
5f172ace9d
4 changed files with 23 additions and 87 deletions
|
@ -22,22 +22,17 @@ public class APIConstants {
|
|||
public static final String URL_FEED_COUNTS = "http://newsblur.com/reader/refresh_feeds/";
|
||||
public static final String URL_MARK_FEED_AS_READ = "http://newsblur.com/reader/mark_feed_as_read/";
|
||||
public static final String URL_MARK_ALL_AS_READ = "http://newsblur.com/reader/mark_all_as_read/";
|
||||
public static final String URL_MARK_STORY_AS_READ = "http://newsblur.com/reader/mark_story_as_read/";
|
||||
public static final String URL_MARK_FEED_STORIES_AS_READ = "http://newsblur.com/reader/mark_feed_stories_as_read/";
|
||||
public static final String URL_MARK_SOCIALSTORY_AS_READ = "http://newsblur.com/reader/mark_social_stories_as_read/";
|
||||
public static final String URL_MARK_STORIES_READ = "http://newsblur.com/reader/mark_story_hashes_as_read/";
|
||||
public static final String URL_SHARE_STORY = "http://newsblur.com/social/share_story";
|
||||
public static final String URL_MARK_STORY_AS_STARRED = "http://newsblur.com/reader/mark_story_as_starred/";
|
||||
public static final String URL_MARK_STORY_AS_UNREAD = "http://newsblur.com/reader/mark_story_as_unread/";
|
||||
public static final String URL_STARRED_STORIES = "http://newsblur.com/reader/starred_stories";
|
||||
|
||||
public static final String URL_FEED_AUTOCOMPLETE = "http://newsblur.com/rss_feeds/feed_autocomplete";
|
||||
|
||||
public static final String URL_LIKE_COMMENT = "http://newsblur.com/social/like_comment";
|
||||
public static final String URL_UNLIKE_COMMENT = "http://newsblur.com/social/remove_like_comment";
|
||||
public static final String URL_REPLY_TO = "http://newsblur.com/social/save_comment_reply";
|
||||
public static final String URL_ADD_FEED = "http://newsblur.com/reader/add_url";
|
||||
public static final String URL_DELETE_FEED = "http://newsblur.com/reader/delete_feed";
|
||||
|
||||
public static final String URL_CLASSIFIER_SAVE = "http://newsblur.com/classifier/save";
|
||||
|
||||
public static final String PARAMETER_FEEDS = "feeds";
|
||||
|
@ -47,6 +42,7 @@ public class APIConstants {
|
|||
public static final String PARAMETER_EMAIL = "email";
|
||||
public static final String PARAMETER_USERID = "user_id";
|
||||
public static final String PARAMETER_STORYID = "story_id";
|
||||
public static final String PARAMETER_STORY_HASH = "story_hash";
|
||||
public static final String PARAMETER_FEEDS_STORIES = "feeds_stories";
|
||||
public static final String PARAMETER_FEED_SEARCH_TERM = "term";
|
||||
public static final String PARAMETER_FOLDER = "folder";
|
||||
|
|
|
@ -119,16 +119,14 @@ public class APIManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean markSocialStoryAsRead(final String updateJson) {
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(APIConstants.PARAMETER_MARKSOCIAL_JSON, updateJson);
|
||||
final APIResponse response = post(APIConstants.URL_MARK_SOCIALSTORY_AS_READ, values);
|
||||
if (!response.isError()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public NewsBlurResponse markStoriesAsRead(List<String> storyHashes) {
|
||||
ValueMultimap values = new ValueMultimap();
|
||||
for (String storyHash : storyHashes) {
|
||||
values.put(APIConstants.PARAMETER_STORY_HASH, storyHash);
|
||||
}
|
||||
APIResponse response = post(APIConstants.URL_MARK_STORIES_READ, values, false);
|
||||
return response.getResponse(gson, NewsBlurResponse.class);
|
||||
}
|
||||
|
||||
public NewsBlurResponse markStoryAsStarred(final String feedId, final String storyId) {
|
||||
final ValueMultimap values = new ValueMultimap();
|
||||
|
@ -653,15 +651,6 @@ public class APIManager {
|
|||
return (!response.isError());
|
||||
}
|
||||
|
||||
public boolean markMultipleStoriesAsRead(ContentValues values) {
|
||||
final APIResponse response = post(APIConstants.URL_MARK_FEED_STORIES_AS_READ, values);
|
||||
if (!response.isError()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addFeed(String feedUrl, String folderName) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(APIConstants.PARAMETER_URL, feedUrl);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.newsblur.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
|
@ -57,9 +59,8 @@ public class SyncService extends IntentService {
|
|||
public static final int EXTRA_TASK_FOLDER_UPDATE_WITH_COUNT = 41;
|
||||
public static final int EXTRA_TASK_FEED_UPDATE = 31;
|
||||
public static final int EXTRA_TASK_SOCIALFEED_UPDATE = 34;
|
||||
public static final int EXTRA_TASK_MARK_SOCIALSTORY_READ = 35;
|
||||
public static final int EXTRA_TASK_MULTIFEED_UPDATE = 36;
|
||||
public static final int EXTRA_TASK_MARK_MULTIPLE_STORIES_READ = 37;
|
||||
public static final int EXTRA_TASK_MARK_STORIES_READ = 43;
|
||||
public static final int EXTRA_TASK_DELETE_FEED = 39;
|
||||
public static final int EXTRA_TASK_MULTISOCIALFEED_UPDATE = 40;
|
||||
public static final int EXTRA_TASK_STARRED_STORIES_UPDATE = 42;
|
||||
|
@ -110,23 +111,11 @@ public class SyncService extends IntentService {
|
|||
apiManager.getFolderFeedMapping(true);
|
||||
break;
|
||||
|
||||
case EXTRA_TASK_MARK_MULTIPLE_STORIES_READ:
|
||||
final ValueMultimap stories = (ValueMultimap) intent.getSerializableExtra(EXTRA_TASK_STORIES);
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(APIConstants.PARAMETER_FEEDS_STORIES, stories.getJsonString());
|
||||
apiManager.markMultipleStoriesAsRead(values);
|
||||
case EXTRA_TASK_MARK_STORIES_READ:
|
||||
final List<String> storyHashes = (List<String>) intent.getSerializableExtra(EXTRA_TASK_STORIES);
|
||||
apiManager.markStoriesAsRead(storyHashes);
|
||||
break;
|
||||
|
||||
case EXTRA_TASK_MARK_SOCIALSTORY_READ:
|
||||
final String markSocialJson = intent.getStringExtra(EXTRA_TASK_MARK_SOCIAL_JSON);
|
||||
if (!TextUtils.isEmpty(markSocialJson)) {
|
||||
apiManager.markSocialStoryAsRead(markSocialJson);
|
||||
} else {
|
||||
Log.e(this.getClass().getName(), "No feed/story to mark as read included in SyncRequest");
|
||||
receiver.send(STATUS_ERROR, Bundle.EMPTY);
|
||||
}
|
||||
break;
|
||||
|
||||
case EXTRA_TASK_FEED_UPDATE:
|
||||
if (!TextUtils.isEmpty(intent.getStringExtra(EXTRA_TASK_FEED_ID))) {
|
||||
StoriesResponse storiesForFeed = apiManager.getStoriesForFeed(intent.getStringExtra(EXTRA_TASK_FEED_ID), intent.getStringExtra(EXTRA_TASK_PAGE_NUMBER), (StoryOrder) intent.getSerializableExtra(EXTRA_TASK_ORDER), (ReadFilter) intent.getSerializableExtra(EXTRA_TASK_READ_FILTER));
|
||||
|
|
|
@ -75,33 +75,17 @@ public class FeedUtils {
|
|||
/**
|
||||
* This utility method is a fast-returning way to mark as read a batch of stories in both
|
||||
* the local DB and on the server.
|
||||
*
|
||||
* TODO: the next version of the NB API will let us mark-as-read by a UUID, so we can
|
||||
* hopefully remove the ugly detection of social stories and their whole different
|
||||
* API call.
|
||||
*/
|
||||
public static void markStoriesAsRead( Collection<Story> stories, Context context ) {
|
||||
|
||||
// the map of non-social feedIds->storyIds to mark (auto-serializing)
|
||||
ValueMultimap storiesJson = new ValueMultimap();
|
||||
// the map of social userIds->feedIds->storyIds to mark
|
||||
Map<String, Map<String, Set<String>>> socialStories = new HashMap<String, Map<String, Set<String>>>();
|
||||
// the list of story hashes to mark read
|
||||
ArrayList<String> storyHashes = new ArrayList<String>();
|
||||
// a list of local DB ops to perform
|
||||
ArrayList<ContentProviderOperation> updateOps = new ArrayList<ContentProviderOperation>();
|
||||
|
||||
for (Story story : stories) {
|
||||
// ops for the local DB
|
||||
appendStoryReadOperations(story, updateOps);
|
||||
// API call to ensure the story is marked read in the context of a feed
|
||||
storiesJson.put(story.feedId, story.storyHash);
|
||||
// API call to ensure the story is marked read in the context of a social share
|
||||
if (story.socialUserId != null) {
|
||||
putMapHeirarchy(socialStories, story.socialUserId, story.feedId, story.storyHash);
|
||||
} else if ((story.friendUserIds != null) && (story.friendUserIds.length > 0) && (story.friendUserIds[0] != null)) {
|
||||
putMapHeirarchy(socialStories, story.friendUserIds[0], story.feedId, story.storyHash);
|
||||
} else if ((story.sharedUserIds != null) && (story.sharedUserIds.length > 0) && (story.sharedUserIds[0] != null)) {
|
||||
putMapHeirarchy(socialStories, story.sharedUserIds[0], story.feedId, story.storyHash);
|
||||
}
|
||||
storyHashes.add(story.storyHash);
|
||||
}
|
||||
|
||||
// first, update unread counts in the local DB
|
||||
|
@ -111,36 +95,14 @@ public class FeedUtils {
|
|||
Log.w(FeedUtils.class.getName(), "Could not update unread counts in local storage.", e);
|
||||
}
|
||||
|
||||
// next, update the server for normal stories
|
||||
if (storiesJson.size() > 0) {
|
||||
// next, update the server
|
||||
if (storyHashes.size() > 0) {
|
||||
Intent intent = new Intent(Intent.ACTION_SYNC, null, context, SyncService.class);
|
||||
intent.putExtra(SyncService.SYNCSERVICE_TASK, SyncService.EXTRA_TASK_MARK_MULTIPLE_STORIES_READ);
|
||||
intent.putExtra(SyncService.EXTRA_TASK_STORIES, storiesJson);
|
||||
intent.putExtra(SyncService.SYNCSERVICE_TASK, SyncService.EXTRA_TASK_MARK_STORIES_READ);
|
||||
intent.putExtra(SyncService.EXTRA_TASK_STORIES, storyHashes);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
// finally, update the server for social stories
|
||||
if (socialStories.size() > 0) {
|
||||
Intent intent = new Intent(Intent.ACTION_SYNC, null, context, SyncService.class);
|
||||
intent.putExtra(SyncService.SYNCSERVICE_TASK, SyncService.EXTRA_TASK_MARK_SOCIALSTORY_READ);
|
||||
intent.putExtra(SyncService.EXTRA_TASK_MARK_SOCIAL_JSON, gson.toJson(socialStories));
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method to help populate the 3-level map structure that the NB API uses in JSON calls.
|
||||
*/
|
||||
private static void putMapHeirarchy(Map<String, Map<String, Set<String>>> map, String s1, String s2, String s3) {
|
||||
if (! map.containsKey(s1)) {
|
||||
map.put(s1, new HashMap<String, Set<String>>());
|
||||
}
|
||||
Map<String, Set<String>> innerMap = map.get(s1);
|
||||
if (! innerMap.containsKey(s2)) {
|
||||
innerMap.put(s2, new HashSet<String>());
|
||||
}
|
||||
innerMap.get(s2).add(s3);
|
||||
}
|
||||
|
||||
private static void appendStoryReadOperations(Story story, List<ContentProviderOperation> operations) {
|
||||
|
|
Loading…
Add table
Reference in a new issue