summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers/FeedViewController.m
blob: b6b578f1d30486ace8de33502b8b400f6b867493 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
//  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"

@interface FeedViewController ()

@property NSString *selectedUser;
@end

@implementation FeedViewController

-(void) viewDidLoad {
    self.messagesDelegate = self;
    self.title = @"Today";
    self.path = [APIClient feedUrl];
    [self setShouldScrollToBottomOnRefresh:NO];
    [super viewDidLoad];
}

-(void)avatarClicked:(NSString *)uname {
    self.selectedUser = uname;
    [self performSegueWithIdentifier:@"profileSegue" sender:self];
}
/*
- (IBAction)filterAction:(id)sender {
    if (![[APIClient sharedClient] isAuthenticated]) {
        [self.navigationController performSegueWithIdentifier:@"loginSegue" sender:self.navigationController];
        return;
    }
    UIAlertController *filterAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    [filterAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
    [filterAlert addAction:[UIAlertAction actionWithTitle:@"My feed" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.path = [APIClient feedUrl];
        self.navigationController.visibleViewController.navigationItem.title = @"My feed";
        self.params = nil;
        [self.messages removeAllObjects];
        [self.tableView reloadData];
        [self setShouldScrollToBottomOnRefresh:NO];
    }]];
    [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discover" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.path = [APIClient messagesUrl];
        self.navigationController.visibleViewController.navigationItem.title = @"Discover";
        self.params = nil;
        [self.messages removeAllObjects];
        [self.tableView reloadData];
        [self setShouldScrollToBottomOnRefresh:NO];
    }]];
    [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discussions" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.path = [APIClient discussionsUrl];
        self.navigationController.visibleViewController.navigationItem.title = @"Discussions";
        self.params = nil;
        [self.messages removeAllObjects];
        [self.tableView reloadData];
        [self setShouldScrollToBottomOnRefresh:NO];
    }]];
    [filterAlert.view setTintColor:[ColorScheme linkColor]];
    UIPopoverPresentationController *popover = [filterAlert popoverPresentationController];
    if (popover) {
        popover.sourceView = self.view;
        popover.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds), 0, 0);
        popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
    }
    [self presentViewController:filterAlert animated:YES completion:nil];
}*/

-(void) loadMore {
    Message *lastMsg = [self.messages lastObject];
    if (lastMsg != nil) {
        if ([self.path isEqualToString:[APIClient discussionsUrl]]) {
            NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp];
            self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy];
        } else if (![self.path isEqualToString:[APIClient threadUrl]]) {
            NSNumber *lastMid = lastMsg.mid;
            self.params = [@{@"before_mid":lastMid} mutableCopy];
        }
        [self setShouldScrollToBottomOnRefresh:NO];
    }
}

@end