diff options
author | Vitaly Takmazov | 2018-04-08 23:17:47 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-04-08 23:17:47 +0300 |
commit | f6fed5b2374c7d847c68efccce363f9513aa2efb (patch) | |
tree | 74021a451bd5cfb1df1a7771a32dbc121a7163c6 /Juick | |
parent | 6f8855ce3b83cc50583b62b4a1960c27fdf66bb3 (diff) |
PM posts
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/APIClient.h | 1 | ||||
-rw-r--r-- | Juick/APIClient.m | 19 | ||||
-rw-r--r-- | Juick/AppDelegate.m | 3 | ||||
-rw-r--r-- | Juick/Supporting Files/Juick-Info.plist | 2 | ||||
-rw-r--r-- | Juick/ViewControllers/ChatViewController.h | 4 | ||||
-rw-r--r-- | Juick/ViewControllers/ChatViewController.m | 53 | ||||
-rw-r--r-- | Juick/ViewControllers/DialogsViewController.m | 1 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscoverViewController.m | 2 | ||||
-rw-r--r-- | Juick/Views/MessageCell.xib | 4 | ||||
-rw-r--r-- | Juick/Views/MessageInputView.h | 15 | ||||
-rw-r--r-- | Juick/Views/MessageInputView.m | 19 | ||||
-rw-r--r-- | Juick/Views/MessageInputView.xib | 59 |
12 files changed, 169 insertions, 13 deletions
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<AFMultipartFormData> _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 @@ <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> - <string>64</string> + <string>65</string> <key>ITSAppUsesNonExemptEncryption</key> <false/> <key>LSApplicationCategoryType</key> 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 <UIKit/UIKit.h> #import "User.h" -@interface ChatViewController : UITableViewController +@import PHFComposeBarView; + +@interface ChatViewController : UITableViewController<PHFComposeBarViewDelegate> @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 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <device id="retina4_7" orientation="portrait"> <adaptation id="fullscreen"/> </device> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> 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 <UIKit/UIKit.h> + +@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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> + <device id="retina4_7" orientation="portrait"> + <adaptation id="fullscreen"/> + </device> + <dependencies> + <deployment identifier="iOS"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/> + <capability name="Constraints to layout margins" minToolsVersion="6.0"/> + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> + </dependencies> + <objects> + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> + <visualEffectView opaque="NO" contentMode="scaleToFill" id="2Ze-bx-tgN" customClass="MessageInputView"> + <rect key="frame" x="0.0" y="0.0" width="320" height="74"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> + <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="Jo1-Go-4dO"> + <rect key="frame" x="0.0" y="0.0" width="320" height="74"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <subviews> + <stackView opaque="NO" contentMode="scaleToFill" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="OCM-7q-caQ"> + <rect key="frame" x="4" y="4" width="300" height="54"/> + <subviews> + <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="112-Yb-83a"> + <rect key="frame" x="0.0" y="0.0" width="30" height="54"/> + <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> + <state key="normal" title="@"/> + </button> + <textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" horizontalCompressionResistancePriority="751" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Dkb-8O-5u6"> + <rect key="frame" x="36" y="0.0" width="218" height="54"/> + <nil key="textColor"/> + <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> + <textInputTraits key="textInputTraits"/> + </textField> + <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iUb-5g-Btb"> + <rect key="frame" x="260" y="0.0" width="40" height="54"/> + <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> + <state key="normal" title="Send"/> + </button> + </subviews> + </stackView> + </subviews> + <constraints> + <constraint firstAttribute="trailingMargin" secondItem="OCM-7q-caQ" secondAttribute="trailing" constant="8" id="70a-kb-HZp"/> + <constraint firstItem="OCM-7q-caQ" firstAttribute="topMargin" secondItem="Jo1-Go-4dO" secondAttribute="top" constant="4" id="Voz-db-iEt"/> + <constraint firstItem="OCM-7q-caQ" firstAttribute="leadingMargin" secondItem="Jo1-Go-4dO" secondAttribute="leading" constant="4" id="epV-Pa-CnX"/> + <constraint firstAttribute="bottomMargin" secondItem="OCM-7q-caQ" secondAttribute="bottom" constant="8" id="hsT-4s-U3s"/> + </constraints> + </view> + <blurEffect style="light"/> + <connections> + <outlet property="bottomConstraint" destination="hsT-4s-U3s" id="b1V-Gk-1At"/> + <outlet property="textView" destination="Dkb-8O-5u6" id="6YC-Bn-7P6"/> + </connections> + <point key="canvasLocation" x="-85" y="105"/> + </visualEffectView> + </objects> +</document> |