mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-04-27 15:07:44 +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 *)requestAllPostsWithCaching:(BOOL)useCache;
|
||||||
- (PMKPromise *)requestPostWithPath:(NSString *)path;
|
- (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 *)requestUpdatePost:(Post *)post waitForCompilation:(BOOL)waitForCompilation;
|
||||||
- (PMKPromise *)requestPublishDraft:(Post *)post;
|
- (PMKPromise *)requestPublishDraft:(Post *)post;
|
||||||
- (PMKPromise *)requestUnpublishPost:(Post *)post;
|
- (PMKPromise *)requestUnpublishPost:(Post *)post;
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (PMKPromise *)requestCreateDraft:(Post *)draft publishImmediately:(BOOL)publish waitForCompilation:(BOOL)waitForCompilation {
|
- (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 publish:publish waitForCompilation:waitForCompilation].then(^(Post *post) {
|
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];
|
[_store addDraft:post];
|
||||||
return post;
|
return post;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ typedef NS_ENUM(NSUInteger, BlogServiceErrorCode) {
|
||||||
- (PMKPromise *)requestPublishedPosts;
|
- (PMKPromise *)requestPublishedPosts;
|
||||||
- (PMKPromise *)requestPostWithPath:(NSString *)path;
|
- (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 *)requestUpdatePostWithPath:(NSString *)path title:(NSString *)title body:(NSString *)body link:(NSString *)link waitForCompilation:(BOOL)waitForCompilation;
|
||||||
- (PMKPromise *)requestPublishDraftWithPath:(NSString *)path;
|
- (PMKPromise *)requestPublishDraftWithPath:(NSString *)path;
|
||||||
- (PMKPromise *)requestUnpublishPostWithPath:(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]);
|
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 = @{
|
NSDictionary *fields = @{
|
||||||
@"id" : draftID,
|
@"id" : draftID,
|
||||||
@"title" : title ?: [NSNull null],
|
@"title" : title ?: [NSNull null],
|
||||||
@"body" : body,
|
@"body" : body,
|
||||||
@"link" : link ?: [NSNull null],
|
@"link" : link ?: [NSNull null],
|
||||||
@"publish" : publish ? @"true" : [NSNull null],
|
@"env" : env ?: [NSNull null],
|
||||||
@"wait" : waitForCompilation ? @"true" : [NSNull null],
|
@"wait" : waitForCompilation ? @(YES) : [NSNull null],
|
||||||
};
|
};
|
||||||
return [self.client postJSON:[self urlFor:@"/posts/drafts"] headers:nil fields:fields].then([self decodePostBlock]);
|
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;
|
NSString *verb;
|
||||||
if (modifiedPost.new) {
|
if (modifiedPost.new) {
|
||||||
verb = @"create";
|
verb = @"create";
|
||||||
savePromise = [self.blogController requestCreateDraft:modifiedPost publishImmediately:NO waitForCompilation:waitForCompilation];
|
savePromise = [self.blogController requestCreateDraft:modifiedPost publishImmediatelyToEnvironment:nil waitForCompilation:waitForCompilation];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
verb = @"update";
|
verb = @"update";
|
||||||
|
|
|
||||||
|
|
@ -39,17 +39,14 @@
|
||||||
[provider loadItemForTypeIdentifier:@"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
|
[provider loadItemForTypeIdentifier:@"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
|
||||||
// TODO: image
|
// TODO: image
|
||||||
Post *post = [Post newDraftWithTitle:title body:body url:url];
|
Post *post = [Post newDraftWithTitle:title body:body url:url];
|
||||||
[blogController requestCreateDraft:post publishImmediately:YES waitForCompilation:NO].then(^{
|
[blogController requestCreateDraft:post publishImmediatelyToEnvironment:@"production" waitForCompilation:NO].catch(^(NSError *error) {
|
||||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
|
||||||
}).catch(^(NSError *error) {
|
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];
|
||||||
[alert addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
[alert addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||||
[self dismissViewControllerAnimated:YES completion:^{
|
[self dismissViewControllerAnimated:YES completion:nil];
|
||||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
|
||||||
}];
|
|
||||||
}]];
|
}]];
|
||||||
[self presentViewController:alert animated:YES completion:nil];
|
[self presentViewController:alert animated:YES completion:nil];
|
||||||
});
|
});
|
||||||
|
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue