From dbab6ab54c40a016f75e75a4143576c3fa41c3e0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 1 Oct 2019 17:29:46 +0300 Subject: Drop AFNetworking and SSKeychain --- Juick/ViewControllers/NewPostViewController.m | 29 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'Juick/ViewControllers/NewPostViewController.m') diff --git a/Juick/ViewControllers/NewPostViewController.m b/Juick/ViewControllers/NewPostViewController.m index 65172f1..afa14a9 100644 --- a/Juick/ViewControllers/NewPostViewController.m +++ b/Juick/ViewControllers/NewPostViewController.m @@ -10,6 +10,10 @@ #import "MessagesViewController.h" #import "QuoteView.h" #import "APIClient.h" +#import "AppDelegate.h" + +NSString * const NewMessageNotificationName = @"NewMessage"; +NSString * const ReplyPostedNotificationName = @"ReplyPosted"; @interface NewPostViewController () @@ -42,17 +46,28 @@ - (IBAction)sendAction:(id)sender { self.navigationController.navigationItem.rightBarButtonItem.enabled = NO; if (_replyTo == nil) { + self.navigationController.navigationItem.rightBarButtonItem.enabled = YES; [[APIClient sharedClient] postMessage:self.textView.text result:^(Message *msg, NSError *err) { - self.navigationController.navigationItem.rightBarButtonItem.enabled = YES; - [self.navigationController popViewControllerAnimated:YES]; - [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToUnreadOnRefresh:YES]; + if (!err) { + [self dismissViewControllerAnimated:YES completion:^{ + [[NSNotificationCenter defaultCenter] postNotificationName:NewMessageNotificationName object:msg]; + }]; + } else { + self.navigationController.navigationItem.rightBarButtonItem.enabled = YES; + // TODO: display error + } }]; } else { + self.navigationController.navigationItem.rightBarButtonItem.enabled = NO; [[APIClient sharedClient] postReplyToThread:_replyTo.mid inReplyTo:_replyTo.rid text:self.textView.text result:^(Message *msg, NSError *err) { - self.navigationController.navigationItem.rightBarButtonItem.enabled = YES; - [self.navigationController popViewControllerAnimated:YES]; - [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToUnreadOnRefresh:YES]; - [(MessagesViewController *)self.navigationController.visibleViewController refreshData]; + if (!err) { + [self dismissViewControllerAnimated:YES completion:^{ + [[NSNotificationCenter defaultCenter] postNotificationName:ReplyPostedNotificationName object:msg]; + }]; + } else { + self.navigationController.navigationItem.rightBarButtonItem.enabled = YES; + // TODO: display error + } }]; } } -- cgit v1.2.3