forked from parse-community/Parse-SDK-Flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_core_data.dart
More file actions
133 lines (115 loc) · 3.78 KB
/
Copy pathparse_core_data.dart
File metadata and controls
133 lines (115 loc) · 3.78 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
part of flutter_parse_sdk;
/// Singleton class that defines all user keys and data
class ParseCoreData {
factory ParseCoreData() => _instance;
ParseCoreData._init(this.applicationId, this.serverUrl);
static ParseCoreData _instance;
static ParseCoreData get instance => _instance;
/// Creates an instance of Parse Server
///
/// This class should not be user unless switching servers during the app,
/// which is odd. Should only be user by Parse.init
static Future<void> init(
String appId,
String serverUrl, {
bool debug,
String appName,
String liveQueryUrl,
String masterKey,
String clientKey,
String sessionId,
bool autoSendSessionId,
SecurityContext securityContext,
CoreStore store,
Map<String, ParseObjectConstructor> registeredSubClassMap,
ParseUserConstructor parseUserConstructor,
ParseFileConstructor parseFileConstructor,
List<int> liveListRetryIntervals,
}) async {
_instance = ParseCoreData._init(appId, serverUrl);
_instance.storage ??=
store ?? await CoreStoreSharedPrefsImp.getInstance(password: masterKey);
if (debug != null) {
_instance.debug = debug;
}
if (appName != null) {
_instance.appName = appName;
}
if (liveQueryUrl != null) {
_instance.liveQueryURL = liveQueryUrl;
}
if (clientKey != null) {
_instance.clientKey = clientKey;
}
if (masterKey != null) {
_instance.masterKey = masterKey;
}
if (sessionId != null) {
_instance.sessionId = sessionId;
}
if (autoSendSessionId != null) {
_instance.autoSendSessionId = autoSendSessionId;
}
if (securityContext != null) {
_instance.securityContext = securityContext;
}
if (liveListRetryIntervals != null) {
_instance.liveListRetryIntervals = liveListRetryIntervals;
} else {
_instance.liveListRetryIntervals = kIsWeb
? <int>[0, 500, 1000, 2000, 5000]
: <int>[0, 500, 1000, 2000, 5000, 10000];
}
_instance._subClassHandler = ParseSubClassHandler(
registeredSubClassMap: registeredSubClassMap,
parseUserConstructor: parseUserConstructor,
parseFileConstructor: parseFileConstructor,
);
}
String appName;
String applicationId;
String serverUrl;
String liveQueryURL;
String masterKey;
String clientKey;
String sessionId;
bool autoSendSessionId;
SecurityContext securityContext;
bool debug;
CoreStore storage;
ParseSubClassHandler _subClassHandler;
List<int> liveListRetryIntervals;
void registerSubClass(
String className, ParseObjectConstructor objectConstructor) {
_subClassHandler.registerSubClass(className, objectConstructor);
}
void registerUserSubClass(ParseUserConstructor parseUserConstructor) {
_subClassHandler.registerUserSubClass(parseUserConstructor);
}
void registerFileSubClass(ParseFileConstructor parseFileConstructor) {
_subClassHandler.registerFileSubClass(parseFileConstructor);
}
ParseObject createObject(String classname) {
return _subClassHandler.createObject(classname);
}
ParseUser createParseUser(
String username, String password, String emailAddress,
{String sessionToken, bool debug, ParseHTTPClient client}) {
return _subClassHandler.createParseUser(username, password, emailAddress,
sessionToken: sessionToken, debug: debug, client: client);
}
ParseFileBase createFile({String url, String name}) =>
_subClassHandler.createFile(name: name, url: url);
/// Sets the current sessionId.
///
/// This is generated when a users logs in, or calls currentUser to update
/// their keys
void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
CoreStore getStore() {
return storage;
}
@override
String toString() => '$applicationId $masterKey';
}