summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-10-01 17:29:46 +0300
committerGravatar Vitaly Takmazov2019-10-01 22:14:59 +0300
commitdbab6ab54c40a016f75e75a4143576c3fa41c3e0 (patch)
tree6fd5e68ec76c249fcaa07219c53ccab2f4c98fd5 /Juick/ViewControllers
parentaeb513ed5c165e355c9c378efde7445f597d0380 (diff)
Drop AFNetworking and SSKeychain
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/ChatViewController.m2
-rw-r--r--Juick/ViewControllers/FeedViewController.m2
-rw-r--r--Juick/ViewControllers/LoginViewController.m16
-rw-r--r--Juick/ViewControllers/MessagesViewController.m6
-rw-r--r--Juick/ViewControllers/NewPostViewController.h3
-rw-r--r--Juick/ViewControllers/NewPostViewController.m29
-rw-r--r--Juick/ViewControllers/ThreadViewController.m6
7 files changed, 42 insertions, 22 deletions
diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m
index 0de3d2a..989b531 100644
--- a/Juick/ViewControllers/ChatViewController.m
+++ b/Juick/ViewControllers/ChatViewController.m
@@ -26,7 +26,7 @@
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
self.tableView.allowsSelection = NO;
- self.me = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"];
+ self.me = [APIClient sharedClient].credential.user;
[self reloadChat];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
self.refreshControl = [UIRefreshControl new];
diff --git a/Juick/ViewControllers/FeedViewController.m b/Juick/ViewControllers/FeedViewController.m
index 523ea52..31bf0ca 100644
--- a/Juick/ViewControllers/FeedViewController.m
+++ b/Juick/ViewControllers/FeedViewController.m
@@ -70,7 +70,7 @@
}
}
-- (void)userDidSignedIn:(User *) user {
+- (void)userDidSignedIn:(NSNotification *) notification {
[self refreshPath];
[self refreshData];
}
diff --git a/Juick/ViewControllers/LoginViewController.m b/Juick/ViewControllers/LoginViewController.m
index 898e59c..f9b17a3 100644
--- a/Juick/ViewControllers/LoginViewController.m
+++ b/Juick/ViewControllers/LoginViewController.m
@@ -29,8 +29,8 @@ NSString * const UserSignedInNotificationName = @"UserSignedIn";
target:self action:@selector(cancelSignIn)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:@selector(doneSignIn)];
- self.usernameField.text = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"];
- self.passwordField.text = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"];;
+ self.usernameField.text = [APIClient sharedClient].credential.user;
+ self.passwordField.text = [APIClient sharedClient].credential.password;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
}
@@ -57,6 +57,7 @@ NSString * const UserSignedInNotificationName = @"UserSignedIn";
}
- (void) doneSignIn {
+ [[APIClient sharedClient] setCredential:[NSURLCredential credentialWithUser:self.usernameField.text password:self.passwordField.text persistence:NSURLCredentialPersistenceSynchronizable]];
[[APIClient sharedClient] authenticate:^(User *user, NSError *error) {
if (user) {
[[NSNotificationCenter defaultCenter] postNotificationName:UserSignedInNotificationName object:user];
@@ -73,15 +74,4 @@ NSString * const UserSignedInNotificationName = @"UserSignedIn";
}
}];
}
-- (IBAction)passwordChanged:(id)sender {
- if ([self.passwordField.text isKindOfClass:[NSString class]]) {
- [SAMKeychain setPassword:self.passwordField.text forService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"];
- }
-}
-
-- (IBAction)usernameChanged:(id)sender {
- if ([self.usernameField.text isKindOfClass:[NSString class]]) {
- [SAMKeychain setPassword:self.usernameField.text forService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"];
- }
-}
@end
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m
index afa0f9a..ad28484 100644
--- a/Juick/ViewControllers/MessagesViewController.m
+++ b/Juick/ViewControllers/MessagesViewController.m
@@ -106,6 +106,7 @@ NSString* const messageCellIdentifier = @"messageCell";
self.refreshControl = [UIRefreshControl new];
[self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
[self refreshData];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newMessage:) name:NewMessageNotificationName object:nil];
}
- (void) composePressed {
@@ -174,4 +175,9 @@ NSString* const messageCellIdentifier = @"messageCell";
[self.navigationController pushViewController:threadVC animated:YES];
}
+-(void) newMessage:(NSNotification *)obj {
+ Message *msg = (Message *)[obj object];
+ [self viewThreadForMessage:msg mid:msg.mid scrollTo:0];
+}
+
@end
diff --git a/Juick/ViewControllers/NewPostViewController.h b/Juick/ViewControllers/NewPostViewController.h
index 7a1dfac..05e3c73 100644
--- a/Juick/ViewControllers/NewPostViewController.h
+++ b/Juick/ViewControllers/NewPostViewController.h
@@ -9,6 +9,9 @@
#import <UIKit/UIKit.h>
#import "Message.h"
+extern NSString * const NewMessageNotificationName;
+extern NSString * const ReplyPostedNotificationName;
+
@interface NewPostViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
diff --git a/Juick/ViewControllers/NewPostViewController.m b/Juick/ViewControllers/NewPostViewController.m
index 65172f1..afa14a9 100644
--- a/Juick/ViewControllers/NewPostViewController.m
+++ b/Juick/ViewControllers/NewPostViewController.m
@@ -10,6 +10,10 @@
#import "MessagesViewController.h"
#import "QuoteView.h"
#import "APIClient.h"
+#import "AppDelegate.h"
+
+NSString * const NewMessageNotificationName = @"NewMessage";
+NSString * const ReplyPostedNotificationName = @"ReplyPosted";
@interface NewPostViewController ()
@@ -42,17 +46,28 @@
- (IBAction)sendAction:(id)sender {
self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
if (_replyTo == nil) {
+ self.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
[[APIClient sharedClient] postMessage:self.textView.text result:^(Message *msg, NSError *err) {
- self.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
- [self.navigationController popViewControllerAnimated:YES];
- [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToUnreadOnRefresh:YES];
+ if (!err) {
+ [self dismissViewControllerAnimated:YES completion:^{
+ [[NSNotificationCenter defaultCenter] postNotificationName:NewMessageNotificationName object:msg];
+ }];
+ } else {
+ self.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
+ // TODO: display error
+ }
}];
} else {
+ self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
[[APIClient sharedClient] postReplyToThread:_replyTo.mid inReplyTo:_replyTo.rid text:self.textView.text result:^(Message *msg, NSError *err) {
- self.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
- [self.navigationController popViewControllerAnimated:YES];
- [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToUnreadOnRefresh:YES];
- [(MessagesViewController *)self.navigationController.visibleViewController refreshData];
+ if (!err) {
+ [self dismissViewControllerAnimated:YES completion:^{
+ [[NSNotificationCenter defaultCenter] postNotificationName:ReplyPostedNotificationName object:msg];
+ }];
+ } else {
+ self.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
+ // TODO: display error
+ }
}];
}
}
diff --git a/Juick/ViewControllers/ThreadViewController.m b/Juick/ViewControllers/ThreadViewController.m
index 3ea64f7..af56bc3 100644
--- a/Juick/ViewControllers/ThreadViewController.m
+++ b/Juick/ViewControllers/ThreadViewController.m
@@ -19,6 +19,7 @@
[self setPath:[APIClient threadUrl]];
[super viewDidLoad];
self.messagesDelegate = self;
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(replyPosted:) name:ReplyPostedNotificationName object:nil];
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -41,4 +42,9 @@
[self refreshData];
}
+- (void)replyPosted:(NSNotification *) notification {
+ [self setShouldScrollToUnreadOnRefresh:YES];
+ [self refreshData];
+}
+
@end