mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-03-25 09:25:47 +00:00
fix completing the share extension request
This commit is contained in:
parent
8a8dfbea89
commit
bdc2e16e3a
6 changed files with 11 additions and 14 deletions
|
|
@ -27,7 +27,7 @@
|
|||
- (PMKPromise *)requestAllPostsWithCaching:(BOOL)useCache;
|
||||
- (PMKPromise *)requestPostWithPath:(NSString *)path;
|
||||
|
||||
- (PMKPromise *)requestCreateDraft:(Post *)draft publishImmediately:(BOOL)publish waitForCompilation:(BOOL)waitForCompilation;
|
||||
- (PMKPromise *)requestCreateDraft:(Post *)draft publishImmediatelyToEnvironment:(NSString *)env waitForCompilation:(BOOL)waitForCompilation;
|
||||
- (PMKPromise *)requestUpdatePost:(Post *)post waitForCompilation:(BOOL)waitForCompilation;
|
||||
- (PMKPromise *)requestPublishDraft:(Post *)post;
|
||||
- (PMKPromise *)requestUnpublishPost:(Post *)post;
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (PMKPromise *)requestCreateDraft:(Post *)draft publishImmediately:(BOOL)publish waitForCompilation:(BOOL)waitForCompilation {
|
||||
return [_service requestCreateDraftWithID:draft.objectID title:draft.title body:draft.body link:draft.url.absoluteString publish:publish waitForCompilation:waitForCompilation].then(^(Post *post) {
|
||||
- (PMKPromise *)requestCreateDraft:(Post *)draft publishImmediatelyToEnvironment:(NSString *)env waitForCompilation:(BOOL)waitForCompilation {
|
||||
return [_service requestCreateDraftWithID:draft.objectID title:draft.title body:draft.body link:draft.url.absoluteString environment:env waitForCompilation:waitForCompilation].then(^(Post *post) {
|
||||
[_store addDraft:post];
|
||||
return post;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ typedef NS_ENUM(NSUInteger, BlogServiceErrorCode) {
|
|||
- (PMKPromise *)requestPublishedPosts;
|
||||
- (PMKPromise *)requestPostWithPath:(NSString *)path;
|
||||
|
||||
- (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link publish:(BOOL)publish waitForCompilation:(BOOL)waitForCompilation;
|
||||
- (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link environment:(NSString *)env waitForCompilation:(BOOL)waitForCompilation;
|
||||
- (PMKPromise *)requestUpdatePostWithPath:(NSString *)path title:(NSString *)title body:(NSString *)body link:(NSString *)link waitForCompilation:(BOOL)waitForCompilation;
|
||||
- (PMKPromise *)requestPublishDraftWithPath:(NSString *)path;
|
||||
- (PMKPromise *)requestUnpublishPostWithPath:(NSString *)path;
|
||||
|
|
|
|||
|
|
@ -93,14 +93,14 @@ NSString *const BlogServiceErrorDomain = @"BlogServiceErrorDomain";
|
|||
return [self.client get:[self urlFor:path] headers:nil].then([self decodePostBlock]);
|
||||
}
|
||||
|
||||
- (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link publish:(BOOL)publish waitForCompilation:(BOOL)waitForCompilation {
|
||||
- (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link environment:(NSString *)env waitForCompilation:(BOOL)waitForCompilation {
|
||||
NSDictionary *fields = @{
|
||||
@"id" : draftID,
|
||||
@"title" : title ?: [NSNull null],
|
||||
@"body" : body,
|
||||
@"link" : link ?: [NSNull null],
|
||||
@"publish" : publish ? @"true" : [NSNull null],
|
||||
@"wait" : waitForCompilation ? @"true" : [NSNull null],
|
||||
@"env" : env ?: [NSNull null],
|
||||
@"wait" : waitForCompilation ? @(YES) : [NSNull null],
|
||||
};
|
||||
return [self.client postJSON:[self urlFor:@"/posts/drafts"] headers:nil fields:fields].then([self decodePostBlock]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ static NSString *const StateRestorationModifiedPostKey = @"modifiedPost";
|
|||
NSString *verb;
|
||||
if (modifiedPost.new) {
|
||||
verb = @"create";
|
||||
savePromise = [self.blogController requestCreateDraft:modifiedPost publishImmediately:NO waitForCompilation:waitForCompilation];
|
||||
savePromise = [self.blogController requestCreateDraft:modifiedPost publishImmediatelyToEnvironment:nil waitForCompilation:waitForCompilation];
|
||||
}
|
||||
else {
|
||||
verb = @"update";
|
||||
|
|
|
|||
|
|
@ -39,17 +39,14 @@
|
|||
[provider loadItemForTypeIdentifier:@"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
|
||||
// TODO: image
|
||||
Post *post = [Post newDraftWithTitle:title body:body url:url];
|
||||
[blogController requestCreateDraft:post publishImmediately:YES waitForCompilation:NO].then(^{
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}).catch(^(NSError *error) {
|
||||
[blogController requestCreateDraft:post publishImmediatelyToEnvironment:@"production" waitForCompilation:NO].catch(^(NSError *error) {
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];
|
||||
[alert addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||
[self dismissViewControllerAnimated:YES completion:^{
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}]];
|
||||
[self presentViewController:alert animated:YES completion:nil];
|
||||
});
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue