|
@@ -110,29 +110,31 @@ export default class NotificationsManager {
|
110
|
110
|
|
111
|
111
|
static getMachineNotificationWatchlist(callback: Function) {
|
112
|
112
|
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
113
|
|
- if (token === '') {
|
114
|
|
- throw Error('Expo token not available');
|
115
|
|
- }
|
116
|
|
- let data = {
|
117
|
|
- function: 'get_machine_watchlist',
|
118
|
|
- password: passwords.expoNotifications,
|
119
|
|
- token: token,
|
120
|
|
- };
|
121
|
|
- fetch(EXPO_TOKEN_SERVER, {
|
122
|
|
- method: 'POST',
|
123
|
|
- headers: new Headers({
|
124
|
|
- Accept: 'application/json',
|
125
|
|
- 'Content-Type': 'application/json',
|
126
|
|
- }),
|
127
|
|
- body: JSON.stringify(data) // <-- Post parameters
|
128
|
|
- })
|
129
|
|
- .then((response) => response.json())
|
130
|
|
- .then((responseJson) => {
|
131
|
|
- callback(responseJson);
|
|
113
|
+ if (token !== '') {
|
|
114
|
+ let data = {
|
|
115
|
+ function: 'get_machine_watchlist',
|
|
116
|
+ password: passwords.expoNotifications,
|
|
117
|
+ token: token,
|
|
118
|
+ };
|
|
119
|
+ fetch(EXPO_TOKEN_SERVER, {
|
|
120
|
+ method: 'POST',
|
|
121
|
+ headers: new Headers({
|
|
122
|
+ Accept: 'application/json',
|
|
123
|
+ 'Content-Type': 'application/json',
|
|
124
|
+ }),
|
|
125
|
+ body: JSON.stringify(data) // <-- Post parameters
|
132
|
126
|
})
|
133
|
|
- .catch((error) => {
|
134
|
|
- console.log(error);
|
135
|
|
- });
|
|
127
|
+ .then((response) => response.json())
|
|
128
|
+ .then((responseJson) => {
|
|
129
|
+ callback(responseJson);
|
|
130
|
+ })
|
|
131
|
+ .catch((error) => {
|
|
132
|
+ console.log(error);
|
|
133
|
+ });
|
|
134
|
+ } else {
|
|
135
|
+ console.log('Expo token not available');
|
|
136
|
+ }
|
|
137
|
+
|
136
|
138
|
}
|
137
|
139
|
|
138
|
140
|
/**
|
|
@@ -143,32 +145,33 @@ export default class NotificationsManager {
|
143
|
145
|
*/
|
144
|
146
|
static setupMachineNotification(machineID: string, isEnabled: boolean) {
|
145
|
147
|
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
146
|
|
- if (token === '') {
|
147
|
|
- throw Error('Expo token not available');
|
148
|
|
- }
|
149
|
|
- let data = {
|
150
|
|
- function: 'setup_machine_notification',
|
151
|
|
- password: passwords.expoNotifications,
|
152
|
|
- locale: LocaleManager.getCurrentLocale(),
|
153
|
|
- token: token,
|
154
|
|
- machine_id: machineID,
|
155
|
|
- enabled: isEnabled
|
156
|
|
- };
|
157
|
|
- fetch(EXPO_TOKEN_SERVER, {
|
158
|
|
- method: 'POST',
|
159
|
|
- headers: new Headers({
|
160
|
|
- Accept: 'application/json',
|
161
|
|
- 'Content-Type': 'application/json',
|
162
|
|
- }),
|
163
|
|
- body: JSON.stringify(data) // <-- Post parameters
|
164
|
|
- })
|
165
|
|
- .then((response) => response.text())
|
166
|
|
- .then((responseText) => {
|
167
|
|
- console.log(responseText);
|
|
148
|
+ if (token !== '') {
|
|
149
|
+ let data = {
|
|
150
|
+ function: 'setup_machine_notification',
|
|
151
|
+ password: passwords.expoNotifications,
|
|
152
|
+ locale: LocaleManager.getCurrentLocale(),
|
|
153
|
+ token: token,
|
|
154
|
+ machine_id: machineID,
|
|
155
|
+ enabled: isEnabled
|
|
156
|
+ };
|
|
157
|
+ fetch(EXPO_TOKEN_SERVER, {
|
|
158
|
+ method: 'POST',
|
|
159
|
+ headers: new Headers({
|
|
160
|
+ Accept: 'application/json',
|
|
161
|
+ 'Content-Type': 'application/json',
|
|
162
|
+ }),
|
|
163
|
+ body: JSON.stringify(data) // <-- Post parameters
|
168
|
164
|
})
|
169
|
|
- .catch((error) => {
|
170
|
|
- console.log(error);
|
171
|
|
- });
|
|
165
|
+ .then((response) => response.text())
|
|
166
|
+ .then((responseText) => {
|
|
167
|
+ console.log(responseText);
|
|
168
|
+ })
|
|
169
|
+ .catch((error) => {
|
|
170
|
+ console.log(error);
|
|
171
|
+ });
|
|
172
|
+ } else {
|
|
173
|
+ console.log('Expo token not available');
|
|
174
|
+ }
|
172
|
175
|
}
|
173
|
176
|
|
174
|
177
|
/**
|
|
@@ -177,29 +180,30 @@ export default class NotificationsManager {
|
177
|
180
|
*/
|
178
|
181
|
static setMachineReminderNotificationTime(time: number) {
|
179
|
182
|
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
180
|
|
- if (token === '') {
|
181
|
|
- throw Error('Expo token not available');
|
182
|
|
- }
|
183
|
|
- let data = {
|
184
|
|
- function: 'set_machine_reminder',
|
185
|
|
- password: passwords.expoNotifications,
|
186
|
|
- token: token,
|
187
|
|
- time: time,
|
188
|
|
- };
|
189
|
|
- fetch(EXPO_TOKEN_SERVER, {
|
190
|
|
- method: 'POST',
|
191
|
|
- headers: new Headers({
|
192
|
|
- Accept: 'application/json',
|
193
|
|
- 'Content-Type': 'application/json',
|
194
|
|
- }),
|
195
|
|
- body: JSON.stringify(data) // <-- Post parameters
|
196
|
|
- })
|
197
|
|
- .then((response) => response.text())
|
198
|
|
- .then((responseText) => {
|
199
|
|
- console.log(responseText);
|
|
183
|
+ if (token !== '') {
|
|
184
|
+ let data = {
|
|
185
|
+ function: 'set_machine_reminder',
|
|
186
|
+ password: passwords.expoNotifications,
|
|
187
|
+ token: token,
|
|
188
|
+ time: time,
|
|
189
|
+ };
|
|
190
|
+ fetch(EXPO_TOKEN_SERVER, {
|
|
191
|
+ method: 'POST',
|
|
192
|
+ headers: new Headers({
|
|
193
|
+ Accept: 'application/json',
|
|
194
|
+ 'Content-Type': 'application/json',
|
|
195
|
+ }),
|
|
196
|
+ body: JSON.stringify(data) // <-- Post parameters
|
200
|
197
|
})
|
201
|
|
- .catch((error) => {
|
202
|
|
- console.log(error);
|
203
|
|
- });
|
|
198
|
+ .then((response) => response.text())
|
|
199
|
+ .then((responseText) => {
|
|
200
|
+ console.log(responseText);
|
|
201
|
+ })
|
|
202
|
+ .catch((error) => {
|
|
203
|
+ console.log(error);
|
|
204
|
+ });
|
|
205
|
+ } else {
|
|
206
|
+ console.log('Expo token not available');
|
|
207
|
+ }
|
204
|
208
|
}
|
205
|
209
|
}
|