summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers/FeedViewController.m
blob: da1b914d30197076ddf7131fa59ea3ca42c7f265 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
//  DiscoverViewController.m
//  Juick
//
//  Created by Vitaly Takmazov on 03/12/2017.
//  Copyright © 2017 com.juick. All rights reserved.
//

#import "FeedViewController.h"
#import "ThreadViewController.h"
#import "BlogViewController.h"
#import "MessageCell.h"
#import "APIClient.h"
#import "AppDelegate.h"
#import "LoginViewController.h"

NSString * const UserNotAuthenticatedNotificationName = @"UserNotAuthenticated";

@interface FeedViewController ()

@property NSString *selectedUser;
@end

@implementation FeedViewController

-(void) viewDidLoad {
    self.messagesDelegate = self;
    [self refreshPath];
    [self setShouldScrollToUnreadOnRefresh:NO];
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidSignedIn:) name:UserSignedInNotificationName object:nil];
}

-(void)avatarClicked:(NSString *)uname {
    self.selectedUser = uname;
    [self performSegueWithIdentifier:@"profileSegue" sender:self];
}

-(void) loadMore {
    Message *lastMsg = [self.messages lastObject];
    if (lastMsg != nil) {
        NSNumber *lastMid = lastMsg.mid;
        self.params = [@{@"before_mid":lastMid} mutableCopy];
        [self setShouldScrollToUnreadOnRefresh:NO];
        [self refreshData];
    }
}



- (void)didReceiveChallenge {
    
}

-(void) refreshPath {
    if ([[APIClient sharedClient] isAuthenticated]) {
        self.path = [APIClient feedUrl];
    } else {
        self.path = [APIClient messagesUrl];
        self.params = @{@"popular": @1};
    }
}

- (void)userDidSignedIn:(NSNotification *) notification {
    [self refreshPath];
    [self refreshData];
}

@end