summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/DiscoverViewController.h17
-rw-r--r--Juick/ViewControllers/DiscoverViewController.m34
-rw-r--r--Juick/ViewControllers/DiscussionsController.h17
-rw-r--r--Juick/ViewControllers/DiscussionsController.m35
-rw-r--r--Juick/ViewControllers/FeedViewController.m35
-rw-r--r--Juick/ViewControllers/MessagesViewController.h2
-rw-r--r--Juick/ViewControllers/MessagesViewController.m56
-rw-r--r--Juick/ViewControllers/ThreadViewController.h2
-rw-r--r--Juick/ViewControllers/ThreadViewController.m10
9 files changed, 147 insertions, 61 deletions
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<MessagesDelegate>
+
+@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<MessagesDelegate>
+
+@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> 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<NSKeyValueChangeKey,id> *)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 <UIKit/UIKit.h>
#include "MessagesViewController.h"
-@interface ThreadViewController : MessagesViewController
+@interface ThreadViewController : MessagesViewController<MessagesDelegate>
@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