-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtMention.m
75 lines (53 loc) · 1.81 KB
/
AtMention.m
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
//
// AtMention.m
// Teamstory
//
// Created by Freddy Hidalgo-Monchez on 2014-12-19.
//
//
#import "AtMention.h"
@interface AtMention ()
@property PFQuery *userQuery;
@end
@implementation AtMention
#pragma mark Singleton Methods
+ (id)sharedAtMention {
static AtMention *atMention = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
atMention = [[self alloc] init];
});
return atMention;
}
- (id)init {
if (self = [super init]) {
self.userQuery = [PFUser query];
self.userQuery.limit = 1000;
[self.userQuery whereKeyExists:@"displayName"];
[self.userQuery orderByAscending:@"displayName"];
}
return self;
}
- (void)getAllUsers:(void (^)(NSArray *objects, BOOL succeeded, NSError *error))completionBlock {
// get all user objects in database
[self.userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// add objects to our user list
self.userList = [[NSMutableArray alloc]initWithArray:objects];
// get the next 1000, will have to refactor to auto skip based on user count
self.userQuery.skip = 1000;
[self.userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(!error){
// add objects to our user list
[self.userList addObjectsFromArray:objects];
return completionBlock(objects, YES, nil);
}else{
return completionBlock(nil, NO, error);
}
}];
}else{
return completionBlock(nil, NO, error);
}
}];
}
@end