-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChannelManager.m
59 lines (48 loc) · 1.61 KB
/
ChannelManager.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
#import "ChannelManager.h"
@interface ChannelManager ()
@property(nonatomic, strong) NSMutableSet<NSString *> *blockedChannelSet;
@end
@implementation ChannelManager
+ (instancetype)sharedInstance {
static ChannelManager *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; });
return instance;
}
- (instancetype)init {
self = [super init];
if (self) {
_blockedChannelSet =
[[[NSUserDefaults standardUserDefaults] arrayForKey:@"GonerinoBlockedChannels"] mutableCopy]
?: [NSMutableSet set];
}
return self;
}
- (NSArray<NSString *> *)blockedChannels {
return [self.blockedChannelSet allObjects];
}
- (void)addBlockedChannel:(NSString *)channelName {
if (channelName.length > 0) {
[self.blockedChannelSet addObject:channelName];
[self saveBlockedChannels];
}
}
- (void)removeBlockedChannel:(NSString *)channelName {
if (channelName) {
[self.blockedChannelSet removeObject:channelName];
[self saveBlockedChannels];
}
}
- (BOOL)isChannelBlocked:(NSString *)channelName {
return [self.blockedChannelSet containsObject:channelName];
}
- (void)saveBlockedChannels {
[[NSUserDefaults standardUserDefaults] setObject:[self.blockedChannelSet allObjects]
forKey:@"GonerinoBlockedChannels"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)setBlockedChannels:(NSArray<NSString *> *)channels {
self.blockedChannelSet = [NSMutableSet setWithArray:channels];
[self saveBlockedChannels];
}
@end