// // ThreadViewController.m // Juick // // Created by Vitaly Takmazov on 24/09/2017. // Copyright © 2017 com.juick. All rights reserved. // #import "ThreadViewController.h" #import "ColorScheme.h" #import "MessageCell.h" #import "MessageInputView.h" #import "APIClient.h" @interface ThreadViewController () @property (nonatomic, readwrite, retain) UIView *inputAccessoryView; -(void) updateQuoteText:(Message *)message; @property NSNumber *replyTo; @end @implementation ThreadViewController - (void)viewDidLoad { [super viewDidLoad]; self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; _replyTo = @(0); } - (BOOL) canBecomeFirstResponder { return YES; } - (UIView *)inputAccessoryView { if (!_inputAccessoryView) { MessageInputView *inputView = (MessageInputView *)[[[NSBundle mainBundle] loadNibNamed:@"MessageInputView" owner:self options:nil] firstObject]; /*inputView.backgroundColor = [UIColor whiteColor]; inputView.buttonTintColor = [ColorScheme linkColor]; inputView.maxLinesCount = 4; inputView.utilityButtonImage = [UIImage imageNamed:@"Camera"]; inputView.delegate = self;*/ inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight; [inputView.sendButton addTarget:self action:@selector(sendReply) forControlEvents:UIControlEventTouchUpInside]; _inputAccessoryView = inputView; } return _inputAccessoryView; } -(void) updateQuoteText:(Message *)message { MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView; inputView.quoteText.text = message.text; [inputView.textContent becomeFirstResponder]; } -(void) sendReply { MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView; Message *msg = [self.messages firstObject]; [[APIClient sharedClient] postReplyToThread:msg.mid inReplyTo:self.replyTo text:inputView.textContent.text result:^(Message *msg, NSError *err) { MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView; inputView.quoteText.text = @""; [inputView.textContent endEditing:YES]; [self refreshData]; }]; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Message * selectedMessage = [self.messages objectAtIndex:indexPath.row]; _replyTo = selectedMessage.rid; [self updateQuoteText:selectedMessage]; } @end