summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Juick.xcodeproj/project.pbxproj12
-rw-r--r--Juick/APIClient.h2
-rw-r--r--Juick/APIClient.m2
-rw-r--r--Juick/AppDelegate.h3
-rw-r--r--Juick/AppDelegate.m12
-rw-r--r--Juick/Main.storyboard23
-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
15 files changed, 183 insertions, 79 deletions
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 = "<group>"; };
77C3648B2241B3060017522C /* DeviceRegistration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceRegistration.m; sourceTree = "<group>"; };
77C364912243FAEF0017522C /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
+ 77C36493224417E90017522C /* DiscoverViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DiscoverViewController.h; sourceTree = "<group>"; };
+ 77C36494224417E90017522C /* DiscoverViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DiscoverViewController.m; sourceTree = "<group>"; };
+ 77C36496224417FC0017522C /* DiscussionsController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DiscussionsController.h; sourceTree = "<group>"; };
+ 77C36497224417FC0017522C /* DiscussionsController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DiscussionsController.m; sourceTree = "<group>"; };
77C67EE31828342000427098 /* NSURL+PathParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+PathParameters.h"; sourceTree = "<group>"; };
77C67EE41828342000427098 /* NSURL+PathParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+PathParameters.m"; sourceTree = "<group>"; };
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 = "<group>";
@@ -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<Message *>*, 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<Message *> *, 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 <UIApplicationDelegate, UNUserNotificationCenterDelegate>
@@ -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 @@
<!--Thread View Controller-->
<scene sceneID="hRe-9n-wGd">
<objects>
- <tableViewController hidesBottomBarWhenPushed="YES" id="egN-ti-sbh" customClass="ThreadViewController" sceneMemberID="viewController">
+ <tableViewController storyboardIdentifier="threadViewControllerIdentifier" hidesBottomBarWhenPushed="YES" id="egN-ti-sbh" customClass="ThreadViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="R7I-ps-E4b">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -40,7 +40,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="woP-g5-FaQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
- <point key="canvasLocation" x="1520.8" y="-964.76761619190415"/>
+ <point key="canvasLocation" x="76" y="-889"/>
</scene>
<!--Today-->
<scene sceneID="NkO-CZ-YSO">
@@ -77,9 +77,6 @@
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
- <connections>
- <segue destination="egN-ti-sbh" kind="push" identifier="threadViewSegue" id="Z1t-ZV-yVS"/>
- </connections>
</tableViewCell>
</prototypes>
<connections>
@@ -289,7 +286,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="XYj-Y4-lfM">
- <rect key="frame" x="4" y="60" width="367" height="603"/>
+ <rect key="frame" x="4" y="16" width="367" height="647"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
@@ -328,7 +325,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Pm0-3R-NV9" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
- <point key="canvasLocation" x="583.20000000000005" y="-169.56521739130437"/>
+ <point key="canvasLocation" x="1148" y="-889"/>
</scene>
<!--Chat View Controller-->
<scene sceneID="pvH-EU-EhQ">
@@ -359,10 +356,10 @@
</objects>
<point key="canvasLocation" x="1408.8" y="-162.3688155922039"/>
</scene>
- <!--Table View Controller-->
+ <!--Discover View Controller-->
<scene sceneID="g01-td-y6A">
<objects>
- <tableViewController id="q23-tm-nTI" sceneMemberID="viewController">
+ <tableViewController id="q23-tm-nTI" customClass="DiscoverViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="kjj-SM-22v">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -401,18 +398,18 @@
<connections>
<segue destination="k3X-uv-0IF" kind="relationship" relationship="viewControllers" id="5rb-rf-WgC"/>
<segue destination="YkB-dq-pv4" kind="relationship" relationship="viewControllers" id="uQw-Xa-hwe"/>
- <segue destination="wJv-nS-OaN" kind="relationship" relationship="viewControllers" id="5Pl-1T-DRQ"/>
<segue destination="bqF-EV-jyA" kind="relationship" relationship="viewControllers" id="L49-RF-BJa"/>
+ <segue destination="wJv-nS-OaN" kind="relationship" relationship="viewControllers" id="5Pl-1T-DRQ"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="AnM-ht-zf8" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1886" y="-170"/>
</scene>
- <!--Table View Controller-->
+ <!--Discussions Controller-->
<scene sceneID="m4V-XQ-WRo">
<objects>
- <tableViewController id="irg-YA-Ovi" sceneMemberID="viewController">
+ <tableViewController id="irg-YA-Ovi" customClass="DiscussionsController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="txa-ky-5bK">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -486,6 +483,6 @@
<image name="ei-search" width="32" height="32"/>
</resources>
<inferredMetricsTieBreakers>
- <segue reference="vj1-M0-h6U"/>
+ <segue reference="gw8-QZ-Hrt"/>
</inferredMetricsTieBreakers>
</document>
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