summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers/NewPostViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers/NewPostViewController.m')
-rw-r--r--Juick/ViewControllers/NewPostViewController.m29
1 files changed, 22 insertions, 7 deletions
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
+ }
}];
}
}