smartmessage-react-native 2.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNSmartMessage.podspec +30 -0
- package/android/build.gradle +65 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/tr/com/odc/RNSmartMessage/RNSmartMessageModule.java +774 -0
- package/android/src/main/java/tr/com/odc/RNSmartMessage/RNSmartMessagePackage.java +29 -0
- package/ios/RNSmartMessage-Bridging-Header.h +1 -0
- package/ios/RNSmartMessage.h +25 -0
- package/ios/RNSmartMessage.m +138 -0
- package/ios/RNSmartMessage.swift +660 -0
- package/package.json +38 -0
- package/readme.md +494 -0
- package/src/SMDataModels.js +457 -0
- package/src/SmartMessage.js +385 -0
- package/src/index.d.ts +238 -0
- package/src/index.js +8 -0
- package/src/types.d.ts +451 -0
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
package tr.com.odc.RNSmartMessage;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Promise;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
8
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
9
|
+
import com.google.gson.Gson;
|
|
10
|
+
import com.google.gson.reflect.TypeToken;
|
|
11
|
+
|
|
12
|
+
import java.lang.reflect.Type;
|
|
13
|
+
import java.util.ArrayList;
|
|
14
|
+
import java.util.HashMap;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
import java.util.Map;
|
|
17
|
+
import java.util.Objects;
|
|
18
|
+
|
|
19
|
+
import tr.com.odc.smartmessage.SmartMessage;
|
|
20
|
+
import tr.com.odc.smartmessage.push.model.AudioNotificationModel;
|
|
21
|
+
import tr.com.odc.smartmessage.push.model.BaseNotificationModel;
|
|
22
|
+
import tr.com.odc.smartmessage.push.model.BasicCarouselNotificationModel;
|
|
23
|
+
import tr.com.odc.smartmessage.push.model.BasicNotificationModel;
|
|
24
|
+
import tr.com.odc.smartmessage.push.model.CoverflowCarouselNotificationModel;
|
|
25
|
+
import tr.com.odc.smartmessage.push.model.FullscreenDialogModel;
|
|
26
|
+
import tr.com.odc.smartmessage.push.model.GifNotificationModel;
|
|
27
|
+
import tr.com.odc.smartmessage.push.model.HTMLDialogModel;
|
|
28
|
+
import tr.com.odc.smartmessage.push.model.HTMLNotificationModel;
|
|
29
|
+
import tr.com.odc.smartmessage.push.model.ImageNotificationModel;
|
|
30
|
+
import tr.com.odc.smartmessage.push.model.InteractiveDialogModel;
|
|
31
|
+
import tr.com.odc.smartmessage.push.model.MediumDialogModel;
|
|
32
|
+
import tr.com.odc.smartmessage.push.model.RotaryCarouselNotificationModel;
|
|
33
|
+
import tr.com.odc.smartmessage.push.model.SliderNotificationModel;
|
|
34
|
+
import tr.com.odc.smartmessage.push.model.SmallDialogModel;
|
|
35
|
+
import tr.com.odc.smartmessage.push.model.VideoNotificationModel;
|
|
36
|
+
import tr.com.odc.smartmessage.request.MatchContactDeviceRequestBody;
|
|
37
|
+
import tr.com.odc.smartmessage.request.MessageListRequestBody;
|
|
38
|
+
import tr.com.odc.smartmessage.request.model.UserInfo;
|
|
39
|
+
import tr.com.odc.smartmessage.response.BaseResponse;
|
|
40
|
+
import tr.com.odc.smartmessage.response.MessageListResponse;
|
|
41
|
+
import tr.com.odc.smartmessage.response.UserInfoResponse;
|
|
42
|
+
import tr.com.odc.smartmessage.sender.MessageListGetter;
|
|
43
|
+
import tr.com.odc.smartmessage.sender.ResponseListener;
|
|
44
|
+
import tr.com.odc.smartmessage.sender.StorageSender;
|
|
45
|
+
import tr.com.odc.smartmessage.sender.UserInfoGetter;
|
|
46
|
+
import tr.com.odc.smartmessage.storage.MessageDBListenerInterface;
|
|
47
|
+
import tr.com.odc.smartmessage.storage.MessageEntity;
|
|
48
|
+
import tr.com.odc.smartmessage.type.PermissionType;
|
|
49
|
+
import tr.com.odc.smartmessage.type.PushType;
|
|
50
|
+
import tr.com.odc.smartmessage.util.PermissionManager;
|
|
51
|
+
import tr.com.odc.smartmessage.util.SMLogger;
|
|
52
|
+
|
|
53
|
+
public class RNSmartMessageModule extends ReactContextBaseJavaModule {
|
|
54
|
+
|
|
55
|
+
private static final String TAG = "RNSmartMessageModule";
|
|
56
|
+
|
|
57
|
+
public RNSmartMessageModule(ReactApplicationContext reactContext) {
|
|
58
|
+
super(reactContext);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private final Map<PushType, Class<? extends BaseNotificationModel>> notificationTypes = new HashMap<PushType, Class<? extends BaseNotificationModel>>() {{
|
|
62
|
+
put(PushType.BASIC, BasicNotificationModel.class);
|
|
63
|
+
put(PushType.IMAGE, ImageNotificationModel.class);
|
|
64
|
+
put(PushType.HTML_PUSH, HTMLNotificationModel.class);
|
|
65
|
+
put(PushType.GIF, GifNotificationModel.class);
|
|
66
|
+
put(PushType.VIDEO, VideoNotificationModel.class);
|
|
67
|
+
put(PushType.AUDIO, AudioNotificationModel.class);
|
|
68
|
+
put(PushType.BASIC_CAROUSEL, BasicCarouselNotificationModel.class);
|
|
69
|
+
put(PushType.ROTARY_CAROUSEL, RotaryCarouselNotificationModel.class);
|
|
70
|
+
put(PushType.COVERFLOW_CAROUSEL, CoverflowCarouselNotificationModel.class);
|
|
71
|
+
put(PushType.SLIDER, SliderNotificationModel.class);
|
|
72
|
+
put(PushType.SMALL_DIALOG, SmallDialogModel.class);
|
|
73
|
+
put(PushType.MEDIUM_DIALOG, MediumDialogModel.class);
|
|
74
|
+
put(PushType.FULLSCREEN_DIALOG, FullscreenDialogModel.class);
|
|
75
|
+
put(PushType.INTERACTIVE_DIALOG, InteractiveDialogModel.class);
|
|
76
|
+
put(PushType.HTML_DIALOG, HTMLDialogModel.class);
|
|
77
|
+
}};
|
|
78
|
+
|
|
79
|
+
private BaseNotificationModel convertJSONToNotificationModel(String notificationString) throws Exception {
|
|
80
|
+
|
|
81
|
+
if (notificationString == null) {
|
|
82
|
+
throw (new Exception("notificationString is null.Request wont be completed"));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
|
|
87
|
+
BaseNotificationModel baseNotificationModel = new Gson().fromJson(notificationString, BaseNotificationModel.class);
|
|
88
|
+
|
|
89
|
+
if (baseNotificationModel == null || baseNotificationModel.getType() == null) {
|
|
90
|
+
throw (new Exception("notificationString string could not be converted into a BaseNotificationModel object."));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Class<? extends BaseNotificationModel> targetClass = notificationTypes.get(baseNotificationModel.getType());
|
|
94
|
+
|
|
95
|
+
if (targetClass == null) {
|
|
96
|
+
throw (new Exception("Unknown notification type : " + baseNotificationModel.getType()));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
final BaseNotificationModel notificationModel = new Gson().fromJson(notificationString, targetClass);
|
|
100
|
+
|
|
101
|
+
if (notificationModel == null) {
|
|
102
|
+
throw (new Exception("BaseNotificationModel object could not be converted into " + Objects.requireNonNull(notificationTypes.get(baseNotificationModel.getType())).getName() + " object."));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return notificationModel;
|
|
106
|
+
|
|
107
|
+
}catch (Exception e){
|
|
108
|
+
throw e;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//// ACTION EVENTS
|
|
113
|
+
|
|
114
|
+
@ReactMethod
|
|
115
|
+
public void displayDialog(String notificationString) {
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
|
|
119
|
+
BaseNotificationModel notificationModel = convertJSONToNotificationModel(notificationString);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
Objects.requireNonNull(getCurrentActivity()).runOnUiThread(() -> SmartMessage.getInstance().displayDialog(notificationModel));
|
|
123
|
+
} catch (Exception e) {
|
|
124
|
+
SMLogger.exception(e);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
SMLogger.info(TAG, "success", "displayDialog");
|
|
128
|
+
} catch (Exception e) {
|
|
129
|
+
SMLogger.error(TAG, e.getMessage(), "displayDialog");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@ReactMethod
|
|
135
|
+
public void displayDialogWithPromise(String notificationString, Promise promise) {
|
|
136
|
+
|
|
137
|
+
if ( promise == null) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
|
|
143
|
+
BaseNotificationModel baseNotificationModel = convertJSONToNotificationModel(notificationString);
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
Objects.requireNonNull(getCurrentActivity()).runOnUiThread(() -> SmartMessage.getInstance().displayDialog(baseNotificationModel));
|
|
147
|
+
} catch (Exception e) {
|
|
148
|
+
promise.reject(e);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
promise.resolve(true);
|
|
152
|
+
} catch (Exception e) {
|
|
153
|
+
promise.reject(e);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@ReactMethod
|
|
159
|
+
public void matchContactDevice(String matchContactRequestData){
|
|
160
|
+
|
|
161
|
+
try{
|
|
162
|
+
|
|
163
|
+
if(matchContactRequestData == null || matchContactRequestData.isEmpty()){
|
|
164
|
+
SMLogger.error(TAG, "matchContactRequest data is null or empty. Request won't be completed", "matchContactDevice");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
MatchContactDeviceRequestBody matchContactDeviceRequestBody = new Gson().fromJson(matchContactRequestData, MatchContactDeviceRequestBody.class);
|
|
168
|
+
|
|
169
|
+
if(matchContactDeviceRequestBody == null)
|
|
170
|
+
SMLogger.error(TAG, "matchContactRequestData could not be parsed into a request object properly. Request won't be completed", "matchContactDevice");
|
|
171
|
+
|
|
172
|
+
SmartMessage.getInstance().matchContactDevice(matchContactDeviceRequestBody, new ResponseListener() {
|
|
173
|
+
@Override
|
|
174
|
+
public void onSuccess(BaseResponse response) {
|
|
175
|
+
SMLogger.info(TAG, response.toJsonStr(), "matchContactDevice");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@Override
|
|
179
|
+
public void onError(String message) {
|
|
180
|
+
SMLogger.error(TAG, message, "matchContactDevice");
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
}catch (Exception e){
|
|
186
|
+
SMLogger.exception(e);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@ReactMethod
|
|
192
|
+
public void matchContactDeviceWithPromise(String matchContactRequestData, final Promise promise){
|
|
193
|
+
|
|
194
|
+
try{
|
|
195
|
+
|
|
196
|
+
if(matchContactRequestData == null || matchContactRequestData.isEmpty()){
|
|
197
|
+
promise.reject(new Exception("matchContactRequest data is null or empty. Request won't be completed"));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
MatchContactDeviceRequestBody matchContactDeviceRequestBody = new Gson().fromJson(matchContactRequestData, MatchContactDeviceRequestBody.class);
|
|
201
|
+
|
|
202
|
+
if(matchContactDeviceRequestBody == null)
|
|
203
|
+
promise.reject(new Exception("matchContactRequestData could not be parsed into a request object properly. Request won't be completed"));
|
|
204
|
+
|
|
205
|
+
SmartMessage.getInstance().matchContactDevice(matchContactDeviceRequestBody, new ResponseListener() {
|
|
206
|
+
@Override
|
|
207
|
+
public void onSuccess(BaseResponse response) {
|
|
208
|
+
promise.resolve(response.toJsonStr());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@Override
|
|
212
|
+
public void onError(String message) {
|
|
213
|
+
promise.reject(new Throwable(message));
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
}catch (Exception e){
|
|
219
|
+
promise.reject(e);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@ReactMethod
|
|
225
|
+
public void saveConfig(){
|
|
226
|
+
|
|
227
|
+
try{
|
|
228
|
+
SmartMessage.getInstance().saveConfig();
|
|
229
|
+
}catch(Exception e){
|
|
230
|
+
SMLogger.exception(e);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@ReactMethod
|
|
235
|
+
public void saveConfigWithPromise(final Promise promise){
|
|
236
|
+
|
|
237
|
+
try{
|
|
238
|
+
SmartMessage.getInstance().saveConfig();
|
|
239
|
+
BaseResponse baseResponseModel = new BaseResponse();
|
|
240
|
+
baseResponseModel.setExplanation("Config saved successfully");
|
|
241
|
+
baseResponseModel.setResponseCode(0);
|
|
242
|
+
baseResponseModel.setHttpStatusCode(0);
|
|
243
|
+
promise.resolve(baseResponseModel.toJsonStr());
|
|
244
|
+
}catch(Exception e){
|
|
245
|
+
promise.reject(e);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
//// GETTER EVENTS
|
|
250
|
+
|
|
251
|
+
@ReactMethod
|
|
252
|
+
public void getMessageList(String data, final Promise promise) {
|
|
253
|
+
|
|
254
|
+
if (data == null || promise == null) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
final MessageListRequestBody messageListRequestBody = new Gson().fromJson(data, MessageListRequestBody.class);
|
|
260
|
+
|
|
261
|
+
if (messageListRequestBody == null) {
|
|
262
|
+
promise.reject(new Exception("Data string could not be converted into MessageListRequestBody object."));
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
SmartMessage.getInstance().getMessageList(messageListRequestBody, new MessageListGetter.Listener() {
|
|
267
|
+
@Override
|
|
268
|
+
public void onSuccess(MessageListResponse messageListResponse) {
|
|
269
|
+
String messageListResponseString = new Gson().toJson(messageListResponse);
|
|
270
|
+
promise.resolve(messageListResponseString);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@Override
|
|
274
|
+
public void onError(String s) {
|
|
275
|
+
promise.reject(new Exception(s));
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
} catch (Exception e) {
|
|
280
|
+
promise.reject(e);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
@NonNull
|
|
285
|
+
@Override
|
|
286
|
+
public String getName() {
|
|
287
|
+
return "RNSmartMessage";
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@ReactMethod
|
|
291
|
+
public void getNotificationContent(String contentUrl,Promise promise) {
|
|
292
|
+
|
|
293
|
+
if (promise == null || contentUrl == null) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
try{
|
|
298
|
+
SmartMessage.getInstance().getNotificationDetail(contentUrl,new StorageSender.StorageListener() {
|
|
299
|
+
|
|
300
|
+
@Override
|
|
301
|
+
public void onSuccess(BaseNotificationModel baseNotificationModel) {
|
|
302
|
+
|
|
303
|
+
if(baseNotificationModel != null){
|
|
304
|
+
promise.resolve(baseNotificationModel.toJsonStr());
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
@Override
|
|
310
|
+
public void onError(String message) {
|
|
311
|
+
promise.reject(new Exception(message));
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}catch (Exception e){
|
|
315
|
+
promise.reject(e);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@ReactMethod
|
|
321
|
+
public void getToken(final Promise promise) {
|
|
322
|
+
|
|
323
|
+
if (promise == null) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
promise.resolve(SmartMessage.getInstance().getToken());
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
@ReactMethod
|
|
332
|
+
public void getUserInfo(final Promise promise) {
|
|
333
|
+
|
|
334
|
+
if (promise == null) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
try{
|
|
339
|
+
SmartMessage.getInstance().getUserInfo(new UserInfoGetter.Listener() {
|
|
340
|
+
@Override
|
|
341
|
+
public void onSuccess(UserInfoResponse userInfoResponse) {
|
|
342
|
+
try {
|
|
343
|
+
String userInfoString = new Gson().toJson(userInfoResponse.getUserInfo());
|
|
344
|
+
promise.resolve(userInfoString);
|
|
345
|
+
} catch (Exception e) {
|
|
346
|
+
promise.reject(e);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
@Override
|
|
351
|
+
public void onError(String message) {
|
|
352
|
+
promise.reject(new Exception(message));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
@Override
|
|
356
|
+
public void onSuccess(BaseResponse response) { }
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
}catch (Exception e){
|
|
361
|
+
promise.reject(e);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
////INBOX EVENTS
|
|
367
|
+
@ReactMethod
|
|
368
|
+
public void saveNotificationToDB(String baseNotificationJson,Boolean isSeen){
|
|
369
|
+
|
|
370
|
+
try{
|
|
371
|
+
BaseNotificationModel baseNotificationModel = convertJSONToNotificationModel(baseNotificationJson);
|
|
372
|
+
SmartMessage.getInstance().saveNotificationToDB(baseNotificationModel,isSeen);
|
|
373
|
+
}catch (Exception e){
|
|
374
|
+
SMLogger.exception(e);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
@ReactMethod
|
|
379
|
+
public void getMessageListFromDB(final Promise promise){
|
|
380
|
+
try{
|
|
381
|
+
|
|
382
|
+
if(promise == null){
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
SmartMessage.getInstance().getNotificationFromDB(new MessageDBListenerInterface() {
|
|
387
|
+
@Override
|
|
388
|
+
public void onReadSuccess(List<MessageEntity> messageEntityList) {
|
|
389
|
+
promise.resolve(new Gson().toJson(messageEntityList));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@Override
|
|
393
|
+
public void onReadFail() {
|
|
394
|
+
promise.reject(new Exception("There is no message or failed to get notification list from DB"));
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}catch (Exception e){
|
|
398
|
+
promise.reject(e);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
@ReactMethod
|
|
403
|
+
public void updateNotificationAsSeen(String notificationId) {
|
|
404
|
+
|
|
405
|
+
try {
|
|
406
|
+
|
|
407
|
+
if (notificationId == null) {
|
|
408
|
+
SMLogger.error(TAG, "notificationId is null.Request wont be completed", "updateNotificationAsSeen");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
SmartMessage.getInstance().updateNotificationAsSeen(notificationId);
|
|
412
|
+
} catch (Exception e) {
|
|
413
|
+
SMLogger.exception(e);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
@ReactMethod
|
|
419
|
+
public void updateNotificationContent(String notificationId,String notificationString) {
|
|
420
|
+
|
|
421
|
+
try {
|
|
422
|
+
|
|
423
|
+
if (notificationString == null) {
|
|
424
|
+
SMLogger.error(TAG, "notificationString is null.Request wont be completed", "uploadNotificationContent");
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
SmartMessage.getInstance().updateNotificationJsonString(notificationId,notificationString);
|
|
429
|
+
|
|
430
|
+
}catch (Exception e){
|
|
431
|
+
SMLogger.exception(e);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
//// SETTER EVENTS
|
|
437
|
+
@ReactMethod
|
|
438
|
+
public void setUserInfo(final String data) {
|
|
439
|
+
|
|
440
|
+
try{
|
|
441
|
+
UserInfo userInfo = new Gson().fromJson(data, UserInfo.class);
|
|
442
|
+
|
|
443
|
+
if (userInfo == null) {
|
|
444
|
+
SMLogger.error(TAG,"Data string could not be converted into UserInfo object.","setUserInfo");
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
SmartMessage.getInstance().setUserInfo(userInfo, new ResponseListener() {
|
|
449
|
+
@Override
|
|
450
|
+
public void onSuccess(BaseResponse response) {
|
|
451
|
+
SMLogger.info(TAG,response.toJsonStr(), "setUserInfo");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
@Override
|
|
455
|
+
public void onError(String message) {
|
|
456
|
+
SMLogger.error(TAG, message, "setUserInfo");
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
}catch (Exception exception){
|
|
460
|
+
SMLogger.exception(exception);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
@ReactMethod
|
|
466
|
+
public void setUserInfoWithPromise(final String data, final Promise promise) {
|
|
467
|
+
|
|
468
|
+
if (promise == null) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
try{
|
|
473
|
+
UserInfo userInfo = new Gson().fromJson(data, UserInfo.class);
|
|
474
|
+
|
|
475
|
+
if (userInfo == null) {
|
|
476
|
+
promise.reject(new Exception("Data string could not be converted into UserInfo object."));
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
SmartMessage.getInstance().setUserInfo(userInfo, new ResponseListener() {
|
|
481
|
+
@Override
|
|
482
|
+
public void onSuccess(BaseResponse response) {
|
|
483
|
+
promise.resolve(response.toJsonStr());
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
@Override
|
|
487
|
+
public void onError(String message) {
|
|
488
|
+
promise.reject(new Exception(message));
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
}catch (Exception exception){
|
|
493
|
+
promise.reject(exception);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
//// REPORTING EVENTS
|
|
499
|
+
@ReactMethod
|
|
500
|
+
public void reportCustomEvent(String eventIdentifier, String uniqueId, String parameters) {
|
|
501
|
+
|
|
502
|
+
if( eventIdentifier == null || parameters == null || uniqueId == null){
|
|
503
|
+
SMLogger.error(TAG,"eventIdentifier , uniqueId or parameters cannot be null", "reportCustomEvent");
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
try{
|
|
508
|
+
Type type = new TypeToken<HashMap<String, String>>() {}.getType();
|
|
509
|
+
HashMap<String, String> parametersMap = new Gson().fromJson(parameters, type);
|
|
510
|
+
SmartMessage.getInstance().reportCustomEvent(eventIdentifier, uniqueId, parametersMap, new ResponseListener() {
|
|
511
|
+
@Override
|
|
512
|
+
public void onSuccess(BaseResponse response) {
|
|
513
|
+
SMLogger.info(TAG,response.toJsonStr(), "reportCustomEvent");
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
@Override
|
|
517
|
+
public void onError(String message) {
|
|
518
|
+
SMLogger.error(TAG, message, "reportCustomEvent");
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}catch (Exception e){
|
|
522
|
+
SMLogger.exception(e);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
@ReactMethod
|
|
528
|
+
public void reportCustomEventWithPromise(String eventIdentifier, String uniqueId, String parameters,final Promise promise) {
|
|
529
|
+
|
|
530
|
+
if (promise == null ) {
|
|
531
|
+
return;
|
|
532
|
+
}else if( eventIdentifier == null || parameters == null || uniqueId == null){
|
|
533
|
+
promise.reject(new Exception("in reportCustomEvent : eventIdentifier , uniqueId or parameters cannot be null.Request wont be completed"));
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
try{
|
|
538
|
+
Type type = new TypeToken<HashMap<String, String>>() {}.getType();
|
|
539
|
+
HashMap<String, String> parametersMap = new Gson().fromJson(parameters, type);
|
|
540
|
+
SmartMessage.getInstance().reportCustomEvent(eventIdentifier, uniqueId, parametersMap, new ResponseListener() {
|
|
541
|
+
@Override
|
|
542
|
+
public void onSuccess(BaseResponse response) {
|
|
543
|
+
promise.resolve(response.toJsonStr());
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
@Override
|
|
547
|
+
public void onError(String message) {
|
|
548
|
+
promise.reject(new Exception(message));
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
}catch (Exception e){
|
|
552
|
+
promise.reject(e);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
@ReactMethod
|
|
558
|
+
public void reportLoggedInWithPromise(final Promise promise) {
|
|
559
|
+
|
|
560
|
+
if (promise == null) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
try{
|
|
565
|
+
SmartMessage.getInstance().reportLoggedIn(new ResponseListener() {
|
|
566
|
+
@Override
|
|
567
|
+
public void onSuccess(BaseResponse response) {
|
|
568
|
+
promise.resolve(response.toJsonStr());
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
@Override
|
|
572
|
+
public void onError(String message) {
|
|
573
|
+
promise.reject(new Exception(message));
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}catch (Exception e){
|
|
577
|
+
promise.reject(e);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
@ReactMethod
|
|
583
|
+
public void reportLoggedIn() {
|
|
584
|
+
|
|
585
|
+
try{
|
|
586
|
+
|
|
587
|
+
SmartMessage.getInstance().reportLoggedIn(new ResponseListener() {
|
|
588
|
+
@Override
|
|
589
|
+
public void onSuccess(BaseResponse response) {
|
|
590
|
+
SMLogger.info(TAG,response.toJsonStr(), "reportLoggedIn");
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
@Override
|
|
594
|
+
public void onError(String message) {
|
|
595
|
+
SMLogger.error(TAG,message, "reportLoggedIn");
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
}catch (Exception e){
|
|
600
|
+
SMLogger.exception(e);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
@ReactMethod
|
|
606
|
+
public void reportLoggedOut() {
|
|
607
|
+
|
|
608
|
+
try{
|
|
609
|
+
SmartMessage.getInstance().reportLoggedOut(new ResponseListener() {
|
|
610
|
+
@Override
|
|
611
|
+
public void onSuccess(BaseResponse response) {
|
|
612
|
+
SMLogger.info(TAG,response.toJsonStr(), "reportLoggedOut");
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
@Override
|
|
616
|
+
public void onError(String message) {
|
|
617
|
+
SMLogger.error(TAG,message, "reportLoggedOut");
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
}catch (Exception e){
|
|
621
|
+
SMLogger.exception(e);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
@ReactMethod
|
|
627
|
+
public void reportLoggedOutWithPromise(final Promise promise) {
|
|
628
|
+
|
|
629
|
+
if (promise == null) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
try{
|
|
634
|
+
SmartMessage.getInstance().reportLoggedOut(new ResponseListener() {
|
|
635
|
+
@Override
|
|
636
|
+
public void onSuccess(BaseResponse response) {
|
|
637
|
+
promise.resolve(response.toJsonStr());
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
@Override
|
|
641
|
+
public void onError(String message) {
|
|
642
|
+
promise.reject(new Exception(message));
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
}catch (Exception e){
|
|
646
|
+
promise.reject(e);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
//// PERMISSION EVENTS
|
|
652
|
+
@ReactMethod
|
|
653
|
+
public void permissionUpdate(String permissionType, boolean isGranted) {
|
|
654
|
+
|
|
655
|
+
if(permissionType == null || permissionType.isEmpty() ) {
|
|
656
|
+
SMLogger.error(TAG,"permissionType is null or empty.Request wont be completed","permissionUpdate");
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
try {
|
|
661
|
+
PermissionType type = PermissionType.fromString(permissionType);
|
|
662
|
+
SmartMessage.getInstance().permissionUpdate(type, isGranted, new ResponseListener() {
|
|
663
|
+
@Override
|
|
664
|
+
public void onSuccess(BaseResponse response) {
|
|
665
|
+
SMLogger.info(TAG, response.toJsonStr(),"permissionUpdate" );
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
@Override
|
|
669
|
+
public void onError(String message) {
|
|
670
|
+
SMLogger.error(TAG, message, "permissionUpdate");
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}catch (Exception e){
|
|
674
|
+
SMLogger.exception(e);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
@ReactMethod
|
|
680
|
+
public void permissionUpdateWithPromise(String permissionType, boolean isGranted,final Promise promise) {
|
|
681
|
+
|
|
682
|
+
if (promise == null ) {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if(permissionType == null || permissionType.isEmpty() ) {
|
|
687
|
+
promise.reject(new Exception("permissionType is null or empty.Request wont be completed"));
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
try {
|
|
692
|
+
PermissionType type = PermissionType.fromString(permissionType);
|
|
693
|
+
SmartMessage.getInstance().permissionUpdate(type, isGranted, new ResponseListener() {
|
|
694
|
+
@Override
|
|
695
|
+
public void onSuccess(BaseResponse response) {
|
|
696
|
+
promise.resolve(response.toJsonStr());
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
@Override
|
|
700
|
+
public void onError(String message) {
|
|
701
|
+
promise.reject(new Exception(message));
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
}catch (Exception e){
|
|
705
|
+
promise.reject(e);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
@ReactMethod
|
|
711
|
+
public void requestNotificationPermission() {
|
|
712
|
+
|
|
713
|
+
try{
|
|
714
|
+
SmartMessage.getInstance().requestNotificationPermissionWithActivity(isGranted -> SMLogger.info(TAG, isGranted ? "is granted" : "is denied", "requestNotificationPermission"));
|
|
715
|
+
}catch (Exception e){
|
|
716
|
+
SMLogger.exception(e);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
@ReactMethod
|
|
722
|
+
public void requestNotificationPermissionWithPromise(final Promise promise) {
|
|
723
|
+
|
|
724
|
+
try{
|
|
725
|
+
|
|
726
|
+
if(promise == null){
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
SmartMessage.getInstance().requestNotificationPermissionWithActivity(promise::resolve);
|
|
731
|
+
}catch (Exception e){
|
|
732
|
+
promise.reject(e);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
//// LOCATION EVENTS
|
|
738
|
+
@ReactMethod
|
|
739
|
+
public void requestLocationPermission() {
|
|
740
|
+
SmartMessage.getInstance().requestLocationPermissionWithActivity(isGranted -> SMLogger.info(TAG, isGranted ? "is granted" : "is denied", "requestLocationPermission"));
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
@ReactMethod
|
|
744
|
+
public void requestLocationPermissionWithPromise(final Promise promise) {
|
|
745
|
+
|
|
746
|
+
if(promise == null){
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
SmartMessage.getInstance().requestLocationPermissionWithActivity(promise::resolve);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
@ReactMethod
|
|
754
|
+
public void startLocationTracking() {
|
|
755
|
+
|
|
756
|
+
try{
|
|
757
|
+
SmartMessage.getInstance().startLocationTracking();
|
|
758
|
+
}catch (Exception e){
|
|
759
|
+
SMLogger.exception(e);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
@ReactMethod
|
|
765
|
+
public void stopLocationTracking() {
|
|
766
|
+
|
|
767
|
+
try{
|
|
768
|
+
SmartMessage.getInstance().stopLocationTracking();
|
|
769
|
+
}catch (Exception e){
|
|
770
|
+
SMLogger.exception(e);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
}
|