From f6fed5b2374c7d847c68efccce363f9513aa2efb Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 8 Apr 2018 23:17:47 +0300 Subject: PM posts --- Juick/APIClient.h | 1 + Juick/APIClient.m | 19 +++++++++ Juick/AppDelegate.m | 3 -- Juick/Supporting Files/Juick-Info.plist | 2 +- Juick/ViewControllers/ChatViewController.h | 4 +- Juick/ViewControllers/ChatViewController.m | 53 ++++++++++++++++++++--- Juick/ViewControllers/DialogsViewController.m | 1 - Juick/ViewControllers/DiscoverViewController.m | 2 + Juick/Views/MessageCell.xib | 4 +- Juick/Views/MessageInputView.h | 15 +++++++ Juick/Views/MessageInputView.m | 19 +++++++++ Juick/Views/MessageInputView.xib | 59 ++++++++++++++++++++++++++ 12 files changed, 169 insertions(+), 13 deletions(-) create mode 100644 Juick/Views/MessageInputView.h create mode 100644 Juick/Views/MessageInputView.m create mode 100644 Juick/Views/MessageInputView.xib (limited to 'Juick') diff --git a/Juick/APIClient.h b/Juick/APIClient.h index 46e86c7..dd7d13b 100644 --- a/Juick/APIClient.h +++ b/Juick/APIClient.h @@ -19,6 +19,7 @@ -(void) pullNextFromPath:(NSString *)path params:(NSDictionary *)params callback:(void(^)(NSArray *, NSError *))callback; -(void) postMessage:(NSString *)text result:(void(^)(Message *, NSError *))callback; -(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text result:(void(^)(Message *, NSError *))callback; +-(void) postPMToUser:(NSString *)uname text:(NSString *)text result:(void(^)(NSError *))callback; -(void) fetchChats:(void(^)(NSArray *, NSError *))callback; -(void) fetchChatWithUser:(NSString *)uname callback:(void(^)(NSArray *, NSError *))callback; diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 079db5a..1b3fb6e 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -102,6 +102,25 @@ }]; }]; } +-(void) postPMToUser:(NSString *)uname text:(NSString *)text result:(void (^)(NSError *))callback { + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + [self.backgroundQueue addOperationWithBlock:^{ + [manager POST:@"/pm" parameters:nil constructingBodyWithBlock:^(id _Nonnull formData) { + [formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"]; + [formData appendPartWithFormData:[uname dataUsingEncoding:NSUTF8StringEncoding] name:@"uname"]; + } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(nil); + }]; + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Error: %@", [error localizedDescription]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(error); + }]; + }]; + }]; +} + -(void) fetchChats:(void (^)(NSArray *, NSError *))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; [self.backgroundQueue addOperationWithBlock:^{ diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 3e92687..9bbf567 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -83,7 +83,6 @@ //Called to let your app know which action was selected by the user for a given notification. -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{ NSDictionary *userInfo = response.notification.request.content.userInfo; - NSLog(@"User Info : %@", userInfo); [self parseNotificationPayload:userInfo]; UITabBarController *main = (UITabBarController *)self.window.rootViewController; if ([self.pushedThread integerValue] > 0) { @@ -91,10 +90,8 @@ UINavigationController *discover = (UINavigationController *)[main.viewControllers objectAtIndex:0]; [[discover.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"threadViewSegue" sender:discover]; } else { - NSLog(@"Pushing to PM"); [main setSelectedIndex:1]; UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:1]; - NSLog(@"perform PM segue"); [[dialogs.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"chatSegue" sender:dialogs]; } completionHandler(); diff --git a/Juick/Supporting Files/Juick-Info.plist b/Juick/Supporting Files/Juick-Info.plist index cee6d40..796dab8 100644 --- a/Juick/Supporting Files/Juick-Info.plist +++ b/Juick/Supporting Files/Juick-Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 64 + 65 ITSAppUsesNonExemptEncryption LSApplicationCategoryType diff --git a/Juick/ViewControllers/ChatViewController.h b/Juick/ViewControllers/ChatViewController.h index 7ea8030..3479942 100644 --- a/Juick/ViewControllers/ChatViewController.h +++ b/Juick/ViewControllers/ChatViewController.h @@ -9,7 +9,9 @@ #import #import "User.h" -@interface ChatViewController : UITableViewController +@import PHFComposeBarView; + +@interface ChatViewController : UITableViewController @property(nonatomic, strong) NSMutableArray *messages; @property(nonatomic, strong) NSString *uname; @end diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m index e94bb40..489de66 100644 --- a/Juick/ViewControllers/ChatViewController.m +++ b/Juick/ViewControllers/ChatViewController.m @@ -12,6 +12,8 @@ @interface ChatViewController () +@property (nonatomic, readwrite, retain) UIView *inputAccessoryView; + @end @implementation ChatViewController @@ -23,7 +25,13 @@ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; self.tableView.allowsSelection = NO; + [self reloadChat]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; +} + +-(void) reloadChat { self.messages = [NSMutableArray array]; + [self.tableView reloadData]; [[APIClient sharedClient] fetchChatWithUser:self.uname callback:^(NSArray *messages, NSError *err) { if (err == nil) { [self.messages addObjectsFromArray:[[messages reverseObjectEnumerator] allObjects]]; @@ -39,11 +47,6 @@ }]; } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { @@ -62,4 +65,44 @@ return cell; } +-(BOOL) canBecomeFirstResponder { + return YES; +} + +- (UIView *) inputAccessoryView { + if (!_inputAccessoryView) { + PHFComposeBarView *composeView = [[PHFComposeBarView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - PHFComposeBarViewInitialHeight, self.view.bounds.size.width, PHFComposeBarViewInitialHeight)]; + composeView.delegate = self; + [composeView.bottomAnchor constraintEqualToSystemSpacingBelowAnchor:self.view.safeAreaLayoutGuide.bottomAnchor multiplier:1.0f]; + composeView.maxLinesCount = 4; + _inputAccessoryView = composeView; + } + return _inputAccessoryView; +} + +-(void) keyboardWillChangeFrame:(NSNotification *)notification { + NSDictionary *userInfo = [notification userInfo]; + if (userInfo) { + CGRect beginFrame = [userInfo [UIKeyboardFrameBeginUserInfoKey] CGRectValue]; + CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGFloat delta = endFrame.origin.y - beginFrame.origin.y; + CGFloat duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]; + UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]; + [UIView animateWithDuration:duration delay:0 options:(animationCurve << 16) animations:^{ + self.tableView.contentOffset = CGPointMake(0, self.tableView.contentOffset.y - delta); + } completion:nil]; + } +} + +-(void) composeBarViewDidPressButton:(PHFComposeBarView *)composeBarView { + [[APIClient sharedClient] postPMToUser:self.uname text:composeBarView.text result:^(NSError *err) { + if (!err) { + NSLog(@"Success!"); + [composeBarView becomeFirstResponder]; + [composeBarView setText:nil animated:NO]; + [self reloadChat]; + } + }]; +} + @end diff --git a/Juick/ViewControllers/DialogsViewController.m b/Juick/ViewControllers/DialogsViewController.m index a36acf3..d080176 100644 --- a/Juick/ViewControllers/DialogsViewController.m +++ b/Juick/ViewControllers/DialogsViewController.m @@ -59,7 +59,6 @@ if ([segue.identifier isEqualToString:@"chatSegue"]) { NSString *uname; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - NSLog(@"pushed name is %@", appDelegate.pushedUname); if ([appDelegate.pushedUname length] > 0) { uname = [appDelegate.pushedUname copy]; appDelegate.pushedThread = nil; diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index 110d8c7..d57947e 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -11,6 +11,7 @@ #import "MessageCell.h" #import "APIClient.h" #import "AppDelegate.h" +#import "ColorScheme.h" @interface DiscoverViewController () @@ -107,6 +108,7 @@ [self.tableView reloadData]; [self refreshData:NO]; }]]; + [filterAlert.view setTintColor:[ColorScheme linkColor]]; [self presentViewController:filterAlert animated:YES completion:nil]; } diff --git a/Juick/Views/MessageCell.xib b/Juick/Views/MessageCell.xib index bb7f9c5..7d410af 100644 --- a/Juick/Views/MessageCell.xib +++ b/Juick/Views/MessageCell.xib @@ -1,11 +1,11 @@ - + - + diff --git a/Juick/Views/MessageInputView.h b/Juick/Views/MessageInputView.h new file mode 100644 index 0000000..38ce721 --- /dev/null +++ b/Juick/Views/MessageInputView.h @@ -0,0 +1,15 @@ +// +// MessageInputView.h +// Juick +// +// Created by Vitaly Takmazov on 08/04/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import + +@interface MessageInputView : UIVisualEffectView +@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint; +@property (strong, nonatomic) IBOutlet UITextField *textView; + +@end diff --git a/Juick/Views/MessageInputView.m b/Juick/Views/MessageInputView.m new file mode 100644 index 0000000..f16f490 --- /dev/null +++ b/Juick/Views/MessageInputView.m @@ -0,0 +1,19 @@ +// +// MessageInputView.m +// Juick +// +// Created by Vitaly Takmazov on 08/04/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "MessageInputView.h" +#import "ColorScheme.h" + +@implementation MessageInputView + +-(void) awakeFromNib { + [super awakeFromNib]; + [self setTintColor:[ColorScheme linkColor]]; +} + +@end diff --git a/Juick/Views/MessageInputView.xib b/Juick/Views/MessageInputView.xib new file mode 100644 index 0000000..70fcdef --- /dev/null +++ b/Juick/Views/MessageInputView.xib @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3