diff options
author | Vitaly Takmazov | 2017-12-09 23:47:30 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-12-09 23:47:30 +0300 |
commit | a38541e14ecfea8e37c80755fb3b2ef25cd81272 (patch) | |
tree | 3b26f5e4f86a4eb103193535abf7f9b15e0e67e6 /Juick/ViewControllers/NewPostViewController.m | |
parent | e2ac87809468e9487389e5d22ab9766996898478 (diff) |
working post/reply
Diffstat (limited to 'Juick/ViewControllers/NewPostViewController.m')
-rw-r--r-- | Juick/ViewControllers/NewPostViewController.m | 45 |
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 |