forked from levenon/ORObjectRelation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathORBadgeValueManager.m
More file actions
96 lines (74 loc) · 2.64 KB
/
ORBadgeValueManager.m
File metadata and controls
96 lines (74 loc) · 2.64 KB
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
92
93
94
95
96
//
// ORBadgeValueManager.m
// pyyx
//
// Created by xulinfeng on 2017/1/11.
// Copyright © 2017年 Chunlin Ma. All rights reserved.
//
#import "ORBadgeValueManager.h"
NSString * const ORObjectRelationRootName = @"com.pyyx.object.relation.root";
NSString * const ORObjectRelationNormalMessageDomainName = @"root.message.normal.messages";
@interface ORBadgeValueManager ()
@property (nonatomic, strong) ORCountObjectRelation *rootObjectRelation;
/**
* root.home
*/
@property (nonatomic, strong) ORCountObjectRelation *homeObjectRelation;
/**
* root.message
*/
@property (nonatomic, strong) ORCountObjectRelation *messageObjectRelation;
@end
@implementation ORBadgeValueManager
+ (void)load{
[super load];
[[self sharedManager] initialize];
}
+ (instancetype)sharedManager; {
static ORBadgeValueManager *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [self new];
});
return sharedManager;
}
- (void)initialize{
}
#pragma mark - accessor
- (ORCountObjectRelation *)rootObjectRelation{
if (!_rootObjectRelation) {
_rootObjectRelation = [ORCountObjectRelation relationWithName:ORObjectRelationRootName defaultCount:0];
}
return _rootObjectRelation;
}
- (ORCountObjectRelation *)homeObjectRelation{
if (!_homeObjectRelation) {
_homeObjectRelation = [ORCountObjectRelation relationWithName:@"root.home" defaultCount:0];
[[self rootObjectRelation] addSubRelation:_homeObjectRelation error:nil];
}
return _homeObjectRelation;
}
- (ORCountObjectRelation *)messageObjectRelation{
if (!_messageObjectRelation) {
_messageObjectRelation = [ORCountObjectRelation relationWithName:@"root.message" defaultCount:0];
[[self rootObjectRelation] addSubRelation:_messageObjectRelation error:nil];
}
return _messageObjectRelation;
}
- (ORMajorKeyCountObjectRelation *)normalMessageObjectRelationWithChatID:(NSString *)chatID;{
NSParameterAssert(chatID);
NSString *name = [ORMajorKeyCountObjectRelation nameWithObjectID:chatID domain:ORObjectRelationNormalMessageDomainName];
ORMajorKeyCountObjectRelation *relation = [[self messageObjectRelation] subRelationNamed:name];
if (!relation) {
relation = [ORMajorKeyCountObjectRelation relationWithObjectID:chatID domain:ORObjectRelationNormalMessageDomainName defaultCount:0];
NSError *error = nil;
[[self messageObjectRelation] addSubRelation:relation error:&error];
}
return relation;
}
@end
@implementation NSObject (BadgeValueObjectRelation)
- (ORCountObjectRelation *)badgeValueObjectRelation{
return nil;
}
@end