From 6e49fc5c4273e7597925c133c3a6985b6ad85ecc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 21 Mar 2019 23:39:03 +0300 Subject: First RC --- Juick.xcodeproj/project.pbxproj | 12 ++++++ Juick/APIClient.h | 2 +- Juick/APIClient.m | 2 +- Juick/AppDelegate.h | 3 ++ Juick/AppDelegate.m | 12 ++++-- Juick/Main.storyboard | 23 +++++------ Juick/ViewControllers/DiscoverViewController.h | 17 ++++++++ Juick/ViewControllers/DiscoverViewController.m | 34 ++++++++++++++++ Juick/ViewControllers/DiscussionsController.h | 17 ++++++++ Juick/ViewControllers/DiscussionsController.m | 35 ++++++++++++++++ Juick/ViewControllers/FeedViewController.m | 35 ++-------------- Juick/ViewControllers/MessagesViewController.h | 2 + Juick/ViewControllers/MessagesViewController.m | 56 +++++++++++++------------- Juick/ViewControllers/ThreadViewController.h | 2 +- Juick/ViewControllers/ThreadViewController.m | 10 ++++- 15 files changed, 183 insertions(+), 79 deletions(-) create mode 100644 Juick/ViewControllers/DiscoverViewController.h create mode 100644 Juick/ViewControllers/DiscoverViewController.m create mode 100644 Juick/ViewControllers/DiscussionsController.h create mode 100644 Juick/ViewControllers/DiscussionsController.m diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 495e857..f548a6c 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -50,6 +50,8 @@ 77B8DCD62093FC03000DBB04 /* BlogViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B8DCD52093FC03000DBB04 /* BlogViewController.m */; }; 77C3648C2241B3060017522C /* DeviceRegistration.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C3648B2241B3060017522C /* DeviceRegistration.m */; }; 77C364922243FAEF0017522C /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 77C364912243FAEF0017522C /* Colors.xcassets */; }; + 77C36495224417E90017522C /* DiscoverViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C36494224417E90017522C /* DiscoverViewController.m */; }; + 77C36498224417FC0017522C /* DiscussionsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C36497224417FC0017522C /* DiscussionsController.m */; }; 77C67EE51828342000427098 /* NSURL+PathParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C67EE41828342000427098 /* NSURL+PathParameters.m */; }; 77C67EEC18283F2D00427098 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77C67EEB18283F2D00427098 /* QuartzCore.framework */; }; 77C6ADDE1F770EB2000AEA8C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 77C6ADDD1F770EB2000AEA8C /* Main.storyboard */; }; @@ -156,6 +158,10 @@ 77B8DCD52093FC03000DBB04 /* BlogViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BlogViewController.m; sourceTree = ""; }; 77C3648B2241B3060017522C /* DeviceRegistration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceRegistration.m; sourceTree = ""; }; 77C364912243FAEF0017522C /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = ""; }; + 77C36493224417E90017522C /* DiscoverViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DiscoverViewController.h; sourceTree = ""; }; + 77C36494224417E90017522C /* DiscoverViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DiscoverViewController.m; sourceTree = ""; }; + 77C36496224417FC0017522C /* DiscussionsController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DiscussionsController.h; sourceTree = ""; }; + 77C36497224417FC0017522C /* DiscussionsController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DiscussionsController.m; sourceTree = ""; }; 77C67EE31828342000427098 /* NSURL+PathParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+PathParameters.h"; sourceTree = ""; }; 77C67EE41828342000427098 /* NSURL+PathParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+PathParameters.m"; sourceTree = ""; }; 77C67EEB18283F2D00427098 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -318,6 +324,10 @@ 773E639F204BDF16008B8F8D /* ChatViewController.m */, 77B8DCD42093FC03000DBB04 /* BlogViewController.h */, 77B8DCD52093FC03000DBB04 /* BlogViewController.m */, + 77C36493224417E90017522C /* DiscoverViewController.h */, + 77C36494224417E90017522C /* DiscoverViewController.m */, + 77C36496224417FC0017522C /* DiscussionsController.h */, + 77C36497224417FC0017522C /* DiscussionsController.m */, ); path = ViewControllers; sourceTree = ""; @@ -550,6 +560,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 77C36498224417FC0017522C /* DiscussionsController.m in Sources */, 7761133821766A3000D350CD /* ContentLoadingCell.m in Sources */, 77E61A5E1FD4682B00B4E304 /* QuoteView.m in Sources */, 77317BBC181BBE8500D60005 /* AppDelegate.m in Sources */, @@ -567,6 +578,7 @@ 77C6ADE41F7717BC000AEA8C /* ThreadViewController.m in Sources */, 773E63A3204BE036008B8F8D /* BubbleMessageCell.m in Sources */, 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */, + 77C36495224417E90017522C /* DiscoverViewController.m in Sources */, 77C67EE51828342000427098 /* NSURL+PathParameters.m in Sources */, 77E35A82189A5B5A00B2D216 /* LoginViewController.m in Sources */, 773E6397204BCB64008B8F8D /* ConversationCell.m in Sources */, diff --git a/Juick/APIClient.h b/Juick/APIClient.h index 1329868..f2b2a7c 100644 --- a/Juick/APIClient.h +++ b/Juick/APIClient.h @@ -15,7 +15,7 @@ +(APIClient *) sharedClient; --(void) pullNextFromPath:(NSString *)path params:(NSDictionary *)params callback:(void(^)(NSArray *, NSError *))callback; +-(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; diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 44e7537..869e944 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -52,7 +52,7 @@ return _manager; } --(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback { +-(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.backgroundQueue addOperationWithBlock:^{ [self.manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { diff --git a/Juick/AppDelegate.h b/Juick/AppDelegate.h index 931cf0b..59dd7f5 100644 --- a/Juick/AppDelegate.h +++ b/Juick/AppDelegate.h @@ -7,6 +7,7 @@ // @import UIKit; +#import "ThreadViewController.h" @interface AppDelegate : UIResponder @@ -16,6 +17,8 @@ +(AppDelegate *) shared; ++(ThreadViewController *) threadViewController; + @property (strong, nonatomic) NSNumber *pushedThread; @property (strong, nonatomic) NSString *pushedUname; diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index cf2afa8..802bbab 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -95,10 +95,11 @@ [main setSelectedIndex:0]; UINavigationController *discover = (UINavigationController *)[main.viewControllers objectAtIndex:0]; [discover popToRootViewControllerAnimated:NO]; - [[discover.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"threadViewSegue" sender:discover]; + MessagesViewController *msgVC = (MessagesViewController *)[discover.viewControllers objectAtIndex:0]; + [msgVC viewThreadForMessage:nil mid:self.pushedThread]; } else { - [main setSelectedIndex:1]; - UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:1]; + [main setSelectedIndex:2]; + UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:2]; [[dialogs.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"chatSegue" sender:dialogs]; } }]; @@ -128,4 +129,9 @@ return (AppDelegate *)[UIApplication sharedApplication].delegate; } ++ (id)threadViewController { + UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; + return [mainStoryboard instantiateViewControllerWithIdentifier:@"threadViewControllerIdentifier"]; +} + @end diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard index 532d492..c2c1717 100644 --- a/Juick/Main.storyboard +++ b/Juick/Main.storyboard @@ -13,7 +13,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -77,9 +77,6 @@ - - - @@ -289,7 +286,7 @@ - + @@ -328,7 +325,7 @@ - + @@ -359,10 +356,10 @@ - + - + @@ -401,18 +398,18 @@ - + - + - + @@ -486,6 +483,6 @@ - + diff --git a/Juick/ViewControllers/DiscoverViewController.h b/Juick/ViewControllers/DiscoverViewController.h new file mode 100644 index 0000000..8325008 --- /dev/null +++ b/Juick/ViewControllers/DiscoverViewController.h @@ -0,0 +1,17 @@ +// +// DiscoverViewController.h +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "MessagesViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DiscoverViewController : MessagesViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m new file mode 100644 index 0000000..cba3ca2 --- /dev/null +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -0,0 +1,34 @@ +// +// DiscoverViewController.m +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "DiscoverViewController.h" +#import "APIClient.h" + +@interface DiscoverViewController () + +@end + +@implementation DiscoverViewController +- (void)viewDidLoad { + self.messagesDelegate = self; + self.title = @"Discover"; + self.path = [APIClient messagesUrl]; + [self setShouldScrollToBottomOnRefresh:NO]; + [super viewDidLoad]; +} + +- (void)loadMore { + Message *lastMsg = [self.messages lastObject]; + if (lastMsg != nil) { + NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp]; + self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy]; + [self setShouldScrollToBottomOnRefresh:NO]; + } +} + +@end diff --git a/Juick/ViewControllers/DiscussionsController.h b/Juick/ViewControllers/DiscussionsController.h new file mode 100644 index 0000000..93b2ad5 --- /dev/null +++ b/Juick/ViewControllers/DiscussionsController.h @@ -0,0 +1,17 @@ +// +// DiscussionsController.h +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "MessagesViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DiscussionsController : MessagesViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Juick/ViewControllers/DiscussionsController.m b/Juick/ViewControllers/DiscussionsController.m new file mode 100644 index 0000000..b8abd3d --- /dev/null +++ b/Juick/ViewControllers/DiscussionsController.m @@ -0,0 +1,35 @@ +// +// DiscussionsController.m +// Juick +// +// Created by Vitaly Takmazov on 21/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import "DiscussionsController.h" +#import "APIClient.h" + +@interface DiscussionsController () + +@end + +@implementation DiscussionsController + +- (void)viewDidLoad { + self.messagesDelegate = self; + self.title = @"Discussions"; + self.path = [APIClient discussionsUrl]; + [self setShouldScrollToBottomOnRefresh:NO]; + [super viewDidLoad]; +} + +- (void)loadMore { + Message *lastMsg = [self.messages lastObject]; + if (lastMsg != nil) { + NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp]; + self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy]; + [self setShouldScrollToBottomOnRefresh:NO]; + } +} + +@end diff --git a/Juick/ViewControllers/FeedViewController.m b/Juick/ViewControllers/FeedViewController.m index d7b51a8..b6b578f 100644 --- a/Juick/ViewControllers/FeedViewController.m +++ b/Juick/ViewControllers/FeedViewController.m @@ -22,41 +22,12 @@ -(void) viewDidLoad { self.messagesDelegate = self; - if ([[APIClient sharedClient] isAuthenticated]) { - [[APIClient sharedClient] authenticate:^(User *user, NSError *error) { - if (user) { - if ([self.path length] == 0) { - self.path = [APIClient feedUrl]; - self.navigationController.visibleViewController.navigationItem.title = @"My feed"; - } - [self setShouldScrollToBottomOnRefresh:NO]; - [self refreshData]; - } else { - [User throwUnableToLogin:self error:error]; - } - }]; - - } else { - if ([self.path length] == 0) { - self.path = [APIClient messagesUrl]; - self.navigationController.visibleViewController.navigationItem.title = @"Discover"; - } - [self setShouldScrollToBottomOnRefresh:NO]; - [self refreshData]; - } + self.title = @"Today"; + self.path = [APIClient feedUrl]; + [self setShouldScrollToBottomOnRefresh:NO]; [super viewDidLoad]; } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - if (!self.dataLoading) { - MessageCell *cell = (MessageCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath]; - cell.delegate = self; - return cell; - } else { - return [super tableView:tableView cellForRowAtIndexPath:indexPath]; - } -} - -(void)avatarClicked:(NSString *)uname { self.selectedUser = uname; [self performSegueWithIdentifier:@"profileSegue" sender:self]; diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h index 48a9f6b..c8eb4cf 100644 --- a/Juick/ViewControllers/MessagesViewController.h +++ b/Juick/ViewControllers/MessagesViewController.h @@ -22,6 +22,8 @@ extern NSString* const messageCellIdentifier; -(void) refreshData; +-(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid; + @property(nonatomic, strong) NSMutableArray *messages; @property(nonatomic, assign) Boolean dataLoading; @property(nonatomic, weak) id messagesDelegate; diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 8a1d072..7029beb 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -95,14 +95,12 @@ NSString* const messageCellIdentifier = @"messageCell"; [self.tableView registerNib:[UINib nibWithNibName:@"ContentLoadingCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"contentLoadingCell"]; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 500.0f; - if (![self.path isEqualToString:[APIClient threadUrl]]) { + if (!self.messages) { self.messages = [NSMutableArray array]; } self.refreshControl = [UIRefreshControl new]; [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; [self refreshData]; - [self addObserver:self forKeyPath:@"path" options:0 context:nil]; - [self addObserver:self forKeyPath:@"params" options:0 context:nil]; } - (void) composePressed { @@ -133,32 +131,30 @@ NSString* const messageCellIdentifier = @"messageCell"; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellIdentifier forIndexPath:indexPath]; - [self performSegueWithIdentifier:@"threadViewSegue" sender:cell]; + Message *msg = [self.messages objectAtIndex:indexPath.row]; + [self viewThreadForMessage:msg mid:msg.mid]; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - if ([segue.identifier isEqual: @"threadViewSegue"]) { - NSNumber *mid; - Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; - BOOL scrollToEnd = NO; - if ([AppDelegate shared].pushedThread != nil) { - mid = [[AppDelegate shared].pushedThread copy]; - [AppDelegate shared].pushedThread = nil; - [AppDelegate shared].pushedUname = nil; - scrollToEnd = YES; - } else { - mid = msg.mid; - } - if ([mid integerValue] > 0) { - ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; - [threadVC setMessages:[@[msg] mutableCopy]]; - [threadVC setPath:[APIClient threadUrl]]; - [threadVC setParams:@{@"mid": mid }]; - [threadVC setShouldScrollToBottomOnRefresh:scrollToEnd]; - } - } /* + NSNumber *mid; + Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; + BOOL scrollToEnd = NO; + if ([AppDelegate shared].pushedThread != nil) { + mid = [[AppDelegate shared].pushedThread copy]; + [AppDelegate shared].pushedThread = nil; + [AppDelegate shared].pushedUname = nil; + scrollToEnd = YES; + } else { + mid = msg.mid; + } + if ([mid integerValue] > 0) { + ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; + [threadVC setMessages:[@[msg] mutableCopy]]; + [threadVC setPath:[APIClient threadUrl]]; + [threadVC setParams:@{@"mid": mid }]; + [threadVC setShouldScrollToBottomOnRefresh:scrollToEnd]; + } if ([segue.identifier isEqual: @"profileSegue"]) { BlogViewController *blogVC = (BlogViewController *)segue.destinationViewController; [blogVC setUname:self.selectedUser]; @@ -176,8 +172,14 @@ NSString* const messageCellIdentifier = @"messageCell"; } } -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - [self refreshData]; +-(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid { + ThreadViewController *threadVC = [AppDelegate threadViewController]; + if (msg) { + [threadVC setMessages:[@[msg] mutableCopy]]; + } + [threadVC setParams:@{@"mid": mid }]; + [threadVC setShouldScrollToBottomOnRefresh:NO]; + [self.navigationController pushViewController:threadVC animated:YES]; } @end diff --git a/Juick/ViewControllers/ThreadViewController.h b/Juick/ViewControllers/ThreadViewController.h index a9c5259..5a4324e 100644 --- a/Juick/ViewControllers/ThreadViewController.h +++ b/Juick/ViewControllers/ThreadViewController.h @@ -9,5 +9,5 @@ #import #include "MessagesViewController.h" -@interface ThreadViewController : MessagesViewController +@interface ThreadViewController : MessagesViewController @end diff --git a/Juick/ViewControllers/ThreadViewController.m b/Juick/ViewControllers/ThreadViewController.m index ead94fe..44f9e8a 100644 --- a/Juick/ViewControllers/ThreadViewController.m +++ b/Juick/ViewControllers/ThreadViewController.m @@ -9,13 +9,16 @@ #import "ThreadViewController.h" #import "NewPostViewController.h" #import "MessageCell.h" +#import "APIClient.h" @implementation ThreadViewController -(void) viewDidLoad { - [super viewDidLoad]; [self setTitle:@"Thread"]; + [self setPath:[APIClient threadUrl]]; + [super viewDidLoad]; + self.messagesDelegate = self; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { @@ -31,4 +34,9 @@ } } +-(void) loadMore { + Message *lastMsg = [self.messages lastObject]; + [self setShouldScrollToBottomOnRefresh:lastMsg.rid > 0]; +} + @end -- cgit v1.2.3