This repository was archived by the owner on Oct 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathFriendsContributionLoader.swift
65 lines (57 loc) · 1.87 KB
/
FriendsContributionLoader.swift
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
//
// FriendsContributionLoader.swift
// Slide for Reddit
//
// Created by Carlos Crane on 9/8/18.
// Copyright © 2018 Haptic Apps. All rights reserved.
//
import CoreData
import Foundation
import reddift
class FriendsContributionLoader: ContributionLoader {
var content: [RedditObject]
var color: UIColor
var canGetMore: Bool
func reset() {
content = []
}
init() {
color = ColorUtil.getColorForUser(name: "")
paginator = Paginator()
content = []
canGetMore = false
}
var paginator: Paginator
weak var delegate: ContentListingViewController?
var paging = false
func getData(reload: Bool) {
if delegate != nil && (canGetMore || reload) {
do {
if reload {
paginator = Paginator()
}
try delegate?.session?.getFriends(paginator, limit: 50, completion: { (result) in
switch result {
case .failure(let error):
print(error.localizedDescription)
case .success(let listing):
if reload {
self.content = []
}
let before = self.content.count
for user in listing {
self.content.append(FriendObject.userToFriendObject(user: user))
}
// self.paginator = listing.paginator
// self.canGetMore = listing.paginator.hasMore()
DispatchQueue.main.async {
self.delegate?.doneLoading(before: before, filter: false)
}
}
})
} catch {
print(error)
}
}
}
}