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.m45
1 files changed, 42 insertions, 3 deletions
diff --git a/Juick/ViewControllers/NewPostViewController.m b/Juick/ViewControllers/NewPostViewController.m
index 9643b78..8a9bc0e 100644
--- a/Juick/ViewControllers/NewPostViewController.m
+++ b/Juick/ViewControllers/NewPostViewController.m
@@ -7,13 +7,18 @@
//
#import "NewPostViewController.h"
+#import "MessagesViewController.h"
#import "ColorScheme.h"
+#import "MessageInputView.h"
+#import "APIClient.h"
@interface NewPostViewController ()
@property (nonatomic, assign) BOOL didSetupConstraints;
@property (nonatomic, assign) int paddingValue;
+@property (nonatomic, readwrite, retain) UIView *inputAccessoryView;
+
@end
@implementation NewPostViewController
@@ -21,8 +26,14 @@
- (void)viewDidLoad
{
[super viewDidLoad];
- self.navigationController.visibleViewController.title = @"Post";
- self.navigationController.visibleViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
+ if (_replyTo != nil) {
+ MessageInputView *inputView = (MessageInputView *) self.inputAccessoryView;
+ inputView.quoteText.text = _replyTo.text;
+ self.navigationController.visibleViewController.title = [NSString stringWithFormat:@"Reply to %@", _replyTo.user.uname];
+ } else {
+ self.navigationController.visibleViewController.title = @"Post";
+ }
+ self.navigationController.visibleViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelCompose)];
self.navigationController.visibleViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:@selector(doneCompose)];
@@ -37,7 +48,19 @@
}
- (void) doneCompose {
- [self.navigationController.visibleViewController.navigationController popToRootViewControllerAnimated:YES];
+ if (_replyTo == nil) {
+ [[APIClient sharedClient] postMessage:self.textView.text result:^(Message *msg, NSError *err) {
+ [self.navigationController.visibleViewController.navigationController popViewControllerAnimated:YES];
+ MessagesViewController *target = (MessagesViewController *)self.navigationController.visibleViewController;
+ [target refreshData:YES];
+ }];
+ } else {
+ [[APIClient sharedClient] postReplyToThread:_replyTo.mid inReplyTo:_replyTo.rid text:self.textView.text result:^(Message *msg, NSError *err) {
+ [self.navigationController.visibleViewController.navigationController popViewControllerAnimated:YES];
+ MessagesViewController *target = (MessagesViewController *)self.navigationController.visibleViewController;
+ [target refreshData:YES];
+ }];
+ }
}
-(void) keyboardDidShow:(NSNotification *)sender {
@@ -53,4 +76,20 @@
self.bottomConstraint.constant = self.paddingValue;
[self.view layoutIfNeeded];
}
+
+-(BOOL) canBecomeFirstResponder {
+ return YES;
+}
+
+- (UIView *) inputAccessoryView {
+ if (!_inputAccessoryView) {
+ MessageInputView *inputView = (MessageInputView *)[[[NSBundle mainBundle] loadNibNamed:@"MessageInputView" owner:self options:nil] firstObject];
+ inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
+ inputView.quoteText.text = self.replyTo.text;
+ _inputAccessoryView = inputView;
+ }
+ return _inputAccessoryView;
+}
+
+
@end