-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathReaderPostService.h
219 lines (175 loc) · 7.92 KB
/
ReaderPostService.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#import <Foundation/Foundation.h>
@import WordPressData;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
@import WordPressKit;
@import WordPressSharedObjC;
@class ReaderPost;
@class ReaderAbstractTopic;
extern NSString * const ReaderPostServiceErrorDomain;
extern NSString * const ReaderPostServiceToggleSiteFollowingState;
@interface ReaderPostService : CoreDataService
/**
Fetches and saves the posts for the specified topic
@param topic The Topic for which to request posts.
@param date The date to get posts earlier than.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)fetchPostsForTopic:(ReaderAbstractTopic *)topic
earlierThan:(NSDate *)date
success:(void (^)(NSInteger count, BOOL hasMore))success
failure:(void (^)(NSError *error))failure;
/**
Fetches and saves the posts for the specified topic
@param topic The Topic for which to request posts.
@param date The date to get posts earlier than.
@param deletingEarlier Deletes any cached posts earlier than the earliers post returned.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)fetchPostsForTopic:(ReaderAbstractTopic *)topic
earlierThan:(NSDate *)date
deletingEarlier:(BOOL)deleteEarlier
success:(void (^)(NSInteger count, BOOL hasMore))success
failure:(void (^)(NSError *error))failure;
/**
Fetches and saves the posts for the specified topic
@param topic The Topic for which to request posts.
@param offset The offset of the posts to fetch.
@param deletingEarlier Deletes any cached posts earlier than the earliers post returned.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)fetchPostsForTopic:(ReaderAbstractTopic *)topic
atOffset:(NSUInteger)offset
deletingEarlier:(BOOL)deleteEarlier
success:(void (^)(NSInteger count, BOOL hasMore))success
failure:(void (^)(NSError *error))failure;
/**
Fetches a specific post from the specified remote site
@param postID The ID of the post to fetch.
@param siteID The ID of the post's site.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)fetchPost:(NSUInteger)postID
forSite:(NSUInteger)siteID
isFeed:(BOOL)isFeed
success:(void (^)(ReaderPost *post))success
failure:(void (^)(NSError *error))failure;
/**
Fetches a specific post from the specified URL
@param postURL The URL of the post to fetch
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)fetchPostAtURL:(NSURL *)postURL
success:(void (^)(ReaderPost *post))success
failure:(void (^)(NSError *error))failure;
/**
Silently refresh posts for the followed sites topic.
Note that calling this method creates a new service instance that performs
all its work on a derived managed object context, and background queue.
*/
- (void)refreshPostsForFollowedTopic;
/**
Toggle the liked status of the specified post.
@param post The reader post to like/unlike.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)toggleLikedForPost:(ReaderPost *)post
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;
/**
Toggle the liked status of the specified post.
@param post The reader post to like/unlike.
@param source A string that hints the source of where action was performed. Optional.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)toggleLikedForPost:(ReaderPost *)post
source:(nullable NSString *)source
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;
/**
Toggle the following status of the specified post's blog.
@param post The ReaderPost whose blog should be followed.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)toggleFollowingForPost:(ReaderPost *)post
success:(void (^)(BOOL follow))success
failure:(void (^)(BOOL follow, NSError *error))failure;
/**
Toggle the saved for later status of the specified post.
@param post The reader post to like/unlike.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)toggleSavedForLaterForPost:(ReaderPost *)post
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;
/**
Toggle the seen status of the specified post.
@param post The reader post to mark seen/unseen.
@param success block called on a successful fetch.
@param failure block called if there is any error. `error` can be any underlying network error.
*/
- (void)toggleSeenForPost:(ReaderPost *)post
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;
/**
Deletes all posts that do not belong to a `ReaderAbstractTopic`
Saves the NSManagedObjectContext.
*/
- (void)deletePostsWithNoTopic;
/**
Sets the `isSavedForLater` flag to false for all posts.
*/
- (void)clearSavedPostFlags;
/**
Globally sets the `inUse` flag to false for all posts.
*/
- (void)clearInUseFlags;
/**
Updates in core data the following status of posts belonging to the specified site & url
@param following Whether the user is following the site.
@param siteID The ID of the site
@siteURL the URL of the site.
*/
- (void)setFollowing:(BOOL)following forPostsFromSiteWithID:(NSNumber *)siteID andURL:(NSString *)siteURL;
/**
Delete all `ReaderPosts` beyond the max number to be retained.
The managed object context is not saved.
@param topic the `ReaderAbstractTopic` to delete posts from.
*/
- (void)deletePostsInExcessOfMaxAllowedForTopic:(ReaderAbstractTopic *)topic;
/**
Delete posts that are flagged as belonging to a blocked site.
The managed object context is not saved.
*/
- (void)deletePostsFromBlockedSites;
#pragma mark - Merging and Deletion
/**
Merge a freshly fetched batch of posts into the existing set of posts for the specified topic.
Saves the managed object context.
@param remotePosts An array of RemoteReaderPost objects
@param date The `before` date posts were requested.
@param topicObjectID The ObjectID of the ReaderAbstractTopic to assign to the newly created posts.
@param success block called on a successful fetch which should be performed after merging
*/
- (void)mergePosts:(NSArray *)remotePosts
rankedLessThan:(NSNumber *)rank
forTopic:(NSManagedObjectID *)topicObjectID
deletingEarlier:(BOOL)deleteEarlier
callingSuccess:(void (^)(NSInteger count, BOOL hasMore))success;
#pragma mark Internal
@property (readwrite, assign) BOOL isSilentlyFetchingPosts;
- (WordPressComRestApi *)apiForRequest;
- (NSUInteger)numberToSyncForTopic:(ReaderAbstractTopic *)topic;
- (void)updateTopic:(NSManagedObjectID *)topicObjectID withAlgorithm:(NSString *)algorithm;
- (BOOL)canLoadMorePostsForTopic:(ReaderAbstractTopic * _Nonnull)readerTopic remotePosts:(NSArray * _Nonnull)remotePosts inContext: (NSManagedObjectContext * _Nonnull)context;
@end
#pragma clang diagnostic pop // -Wnullability-completeness