vibes-react-native 1.1.3 → 1.1.6
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/README.md +2 -392
- package/android/.gradle/6.8/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.8/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.8/gc.properties +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/nb-cache/trust/0FE3017D1D91C06BBB23B2D967E1CF942770CADF1DE28563D6C5A7D96E872CFD +1 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +51 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +30 -0
- package/android/src/main/java/com/vibes/push/rn/plugin/PushEvtEmitter.java +65 -0
- package/android/src/main/java/com/vibes/push/rn/plugin/VibesAppHelper.java +186 -0
- package/android/src/main/java/com/vibes/push/rn/plugin/VibesModule.java +490 -0
- package/android/src/main/java/com/vibes/push/rn/plugin/VibesPackage.java +28 -0
- package/android/src/main/java/com/vibes/push/rn/plugin/notifications/Fms.java +132 -0
- package/android/src/main/java/com/vibes/push/rn/plugin/notifications/PayloadWrapper.java +23 -0
- package/android/src/main/java/com/vibes/push/rn/plugin/notifications/VibesPushReceiver.java +62 -0
- package/ios/Configuration.swift +68 -0
- package/ios/Notifications.swift +72 -0
- package/ios/Vibes-Bridging-Header.h +2 -0
- package/ios/Vibes.m +56 -0
- package/ios/Vibes.swift +378 -0
- package/ios/Vibes.xcodeproj/project.pbxproj +293 -0
- package/ios/Vibes.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/Vibes.xcodeproj/project.xcworkspace/xcuserdata/ed.lafoy.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Vibes.xcodeproj/xcuserdata/ed.lafoy.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/VibesClient.swift +35 -0
- package/ios/VibesPluginLogger.swift +160 -0
- package/lib/commonjs/index.js +163 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +143 -0
- package/lib/module/index.js.map +1 -0
- package/package.json +11 -17
- package/src/index.tsx +182 -0
- /package/{ib → lib}/typescript/index.d.ts +0 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
package com.vibes.push.rn.plugin;
|
|
2
|
+
|
|
3
|
+
import android.app.Application;
|
|
4
|
+
import android.content.pm.ApplicationInfo;
|
|
5
|
+
import android.content.pm.PackageManager;
|
|
6
|
+
import android.os.Bundle;
|
|
7
|
+
import android.util.Log;
|
|
8
|
+
import androidx.annotation.NonNull;
|
|
9
|
+
import com.facebook.react.bridge.*;
|
|
10
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
11
|
+
import com.google.android.gms.tasks.OnFailureListener;
|
|
12
|
+
import com.google.android.gms.tasks.OnSuccessListener;
|
|
13
|
+
import com.google.firebase.iid.FirebaseInstanceId;
|
|
14
|
+
import com.google.firebase.iid.InstanceIdResult;
|
|
15
|
+
import com.google.gson.Gson;
|
|
16
|
+
import com.vibes.vibes.*;
|
|
17
|
+
import org.json.JSONException;
|
|
18
|
+
import org.json.JSONObject;
|
|
19
|
+
|
|
20
|
+
import java.util.Collection;
|
|
21
|
+
|
|
22
|
+
@ReactModule(name = VibesModule.NAME)
|
|
23
|
+
public class VibesModule extends ReactContextBaseJavaModule {
|
|
24
|
+
public static final String NAME = "Vibes";
|
|
25
|
+
public static final String DEVICE_REGISTERED = "DEVICE_REGISTERED";
|
|
26
|
+
public static final String TOKEN_REGISTERED = "TOKEN_REGISTERED";
|
|
27
|
+
public static final String TAG = "VibesRN";
|
|
28
|
+
public static final String TOKEN_KEY = "VibesRN.PushToken";
|
|
29
|
+
public static final String DEVICE_ID = "VibesRN.Device_Id";
|
|
30
|
+
public static final String VIBES_APPID_KEY = "com.vibes.push.rn.plugin.appId";
|
|
31
|
+
public static final String VIBES_APIURL_KEY = "com.vibes.push.rn.plugin.apiUrl";
|
|
32
|
+
public static final String REGISTER_DEVICE_ERROR_KEY = "REGISTER_DEVICE_ERROR";
|
|
33
|
+
public static final String UNREGISTER_DEVICE_ERROR_KEY = "UNREGISTER_DEVICE_ERROR";
|
|
34
|
+
public static final String PLUGIN_ERROR_KEY = "PLUGIN_ERROR";
|
|
35
|
+
public static final String REGISTER_PUSH_ERROR_KEY = "REGISTER_PUSH_ERROR";
|
|
36
|
+
public static final String GET_PERSON_ERROR = "GET_PERSON_ERROR";
|
|
37
|
+
public static final String FETCH_INBOX_MESSAGES_ERROR = "FETCH_INBOX_MESSAGES_ERROR";
|
|
38
|
+
public static final String FETCH_SINGLE_INBOX_MESSAGE_ERROR = "FETCH_SINGLE_INBOX_MESSAGE_ERROR";
|
|
39
|
+
public static final String PERSON_KEY = "PERSON_KEY";
|
|
40
|
+
public static final String EXTERNAL_PERSON_ID_KEY = "EXTERNAL_PERSON_ID_KEY";
|
|
41
|
+
public static final String MARK_INBOX_MESSAGE_AS_READ_ERROR = "MARK_INBOX_MESSAGE_AS_READ_ERROR";
|
|
42
|
+
public static final String INBOX_MESSAGE_OPEN_ERROR = "INBOX_MESSAGE_OPEN_ERROR";
|
|
43
|
+
public static final String EXPIRE_INBOX_MESSAGE_ERROR = "EXPIRE_INBOX_MESSAGE_ERROR";
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
private VibesAppHelper appHelper;
|
|
47
|
+
|
|
48
|
+
public VibesModule(ReactApplicationContext reactContext) {
|
|
49
|
+
super(reactContext);
|
|
50
|
+
appHelper = new VibesAppHelper((Application) reactContext.getApplicationContext());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Override
|
|
54
|
+
@NonNull
|
|
55
|
+
public String getName() {
|
|
56
|
+
return NAME;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Override
|
|
60
|
+
public void initialize() {
|
|
61
|
+
FirebaseInstanceId.getInstance().getInstanceId()
|
|
62
|
+
.addOnSuccessListener(
|
|
63
|
+
new OnSuccessListener<InstanceIdResult>() {
|
|
64
|
+
@Override
|
|
65
|
+
public void onSuccess(InstanceIdResult instanceIdResult) {
|
|
66
|
+
String instanceToken = instanceIdResult.getToken();
|
|
67
|
+
if (instanceToken != null) {
|
|
68
|
+
appHelper.saveString(VibesModule.TOKEN_KEY, instanceToken);
|
|
69
|
+
Log.d(TAG, "Push token obtained from FirebaseInstanceId --> " + instanceToken);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
.addOnFailureListener(
|
|
74
|
+
new OnFailureListener() {
|
|
75
|
+
@Override
|
|
76
|
+
public void onFailure(Exception e) {
|
|
77
|
+
Log.d(TAG, "Failed to fetch token from FirebaseInstanceId: " + e.getLocalizedMessage());
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (BuildConfig.DEBUG)
|
|
82
|
+
Log.d(TAG, "Initializing Vibes SDK");
|
|
83
|
+
|
|
84
|
+
String env = null;
|
|
85
|
+
String appId = null;
|
|
86
|
+
String apiUrl = null;
|
|
87
|
+
try {
|
|
88
|
+
ApplicationInfo ai = getReactApplicationContext().getPackageManager()
|
|
89
|
+
.getApplicationInfo(getReactApplicationContext().getPackageName(), PackageManager.GET_META_DATA);
|
|
90
|
+
Bundle bundle = ai.metaData;
|
|
91
|
+
appId = bundle.getString(VIBES_APPID_KEY);
|
|
92
|
+
apiUrl = bundle.getString(VIBES_APIURL_KEY);
|
|
93
|
+
|
|
94
|
+
} catch (PackageManager.NameNotFoundException ex) {
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
if (appId == null || appId.isEmpty()) {
|
|
98
|
+
throw new IllegalStateException("No appId provided in manifest under name [" + VIBES_APPID_KEY + "]");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
VibesConfig config = null;
|
|
102
|
+
if (apiUrl == null || apiUrl.isEmpty()) {
|
|
103
|
+
config = new VibesConfig.Builder().setAppId(appId).build();
|
|
104
|
+
Log.d(TAG, "Initializing the plugin with appId=[" + appId + "]. Will use default apiUrl");
|
|
105
|
+
} else {
|
|
106
|
+
config = new VibesConfig.Builder().setApiUrl(apiUrl).setAppId(appId).build();
|
|
107
|
+
Log.d(TAG, "Initializing the plugin with appId=[" + appId + "] and apiUrl=[" + apiUrl + "]");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
Vibes.initialize(getReactApplicationContext(), config);
|
|
111
|
+
this.registerDeviceAtStartup();
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@ReactMethod
|
|
116
|
+
public void registerDevice(final Promise promise) {
|
|
117
|
+
Log.d(TAG, "Plugin called to register device");
|
|
118
|
+
VibesListener<Credential> listener = getRegisterDeviceListener(promise);
|
|
119
|
+
Vibes.getInstance().registerDevice(listener);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@ReactMethod
|
|
123
|
+
public void getVibesDeviceInfo(final Promise promise) {
|
|
124
|
+
Log.d(TAG, "Plugin called to return device info");
|
|
125
|
+
WritableMap map = appHelper.getDeviceInfo();
|
|
126
|
+
promise.resolve(map);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@ReactMethod
|
|
130
|
+
public void registerPush(final Promise promise) {
|
|
131
|
+
Log.d(TAG, "Plugin called to register push token with platform");
|
|
132
|
+
VibesListener<Void> listener = getRegisterPushListener(promise);
|
|
133
|
+
String pushToken = appHelper.getPushToken();
|
|
134
|
+
if (pushToken == null) {
|
|
135
|
+
FirebaseInstanceId.getInstance().getInstanceId()
|
|
136
|
+
.addOnSuccessListener(
|
|
137
|
+
new OnSuccessListener<InstanceIdResult>() {
|
|
138
|
+
@Override
|
|
139
|
+
public void onSuccess(InstanceIdResult instanceIdResult) {
|
|
140
|
+
String instanceToken = instanceIdResult.getToken();
|
|
141
|
+
if (instanceToken == null) {
|
|
142
|
+
promise.reject(REGISTER_PUSH_ERROR_KEY, "No push token available for registration yet");
|
|
143
|
+
} else {
|
|
144
|
+
appHelper.saveString(VibesModule.TOKEN_KEY, instanceToken);
|
|
145
|
+
Log.d(TAG, "Push token obtianed from FirebaseInstanceId --> " + instanceToken);
|
|
146
|
+
VibesListener<Void> listener = getRegisterPushListener(promise);
|
|
147
|
+
registerPush(instanceToken, listener);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
.addOnFailureListener(
|
|
152
|
+
new OnFailureListener() {
|
|
153
|
+
@Override
|
|
154
|
+
public void onFailure(Exception e) {
|
|
155
|
+
Log.d(TAG, "Failed to fetch token from FirebaseInstanceId: " + e.getLocalizedMessage());
|
|
156
|
+
promise.reject(REGISTER_DEVICE_ERROR_KEY, "No push token available for registration yet");
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
boolean tokenRegistered = appHelper.getBoolean(VibesModule.TOKEN_REGISTERED, false);
|
|
161
|
+
if (tokenRegistered) {
|
|
162
|
+
promise.resolve("Success");
|
|
163
|
+
} else {
|
|
164
|
+
registerPush(pushToken, listener);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@ReactMethod
|
|
170
|
+
public void unregisterDevice(final Promise promise) {
|
|
171
|
+
VibesListener<Void> listener = new VibesListener<Void>() {
|
|
172
|
+
public void onSuccess(Void credential) {
|
|
173
|
+
Log.d(TAG, "Unregister device successful");
|
|
174
|
+
appHelper.saveString(VibesModule.DEVICE_ID, null);
|
|
175
|
+
appHelper.saveBoolean(VibesModule.DEVICE_REGISTERED, false);
|
|
176
|
+
promise.resolve("Success");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public void onFailure(String errorText) {
|
|
180
|
+
Log.d(TAG, "Unregister device failed");
|
|
181
|
+
promise.reject(UNREGISTER_DEVICE_ERROR_KEY, errorText);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
Vibes.getInstance().unregisterDevice(listener);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private void registerDeviceAtStartup() {
|
|
188
|
+
VibesListener<Credential> listener = getRegisterDeviceListener(null);
|
|
189
|
+
Vibes.getInstance().registerDevice(listener);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private VibesListener<Credential> getRegisterDeviceListener(final Promise promise) {
|
|
193
|
+
return new VibesListener<Credential>() {
|
|
194
|
+
public void onSuccess(Credential credential) {
|
|
195
|
+
appHelper.saveBoolean(VibesModule.DEVICE_REGISTERED, true);
|
|
196
|
+
String deviceId = credential.getDeviceID();
|
|
197
|
+
appHelper.saveString(VibesModule.DEVICE_ID, deviceId);
|
|
198
|
+
Log.d(TAG, "Device id obtained is --> " + deviceId);
|
|
199
|
+
String pushToken = appHelper.getPushToken();
|
|
200
|
+
if (pushToken == null) {
|
|
201
|
+
Log.d(TAG, "Token not yet available. Skipping registerPush");
|
|
202
|
+
} else {
|
|
203
|
+
Log.d(TAG, "Token found after registering device. Attempting to register push token");
|
|
204
|
+
registerPush(pushToken);
|
|
205
|
+
}
|
|
206
|
+
WritableMap map = Arguments.createMap();
|
|
207
|
+
map.putString("device_id", credential.getDeviceID());
|
|
208
|
+
if (promise != null) {
|
|
209
|
+
promise.resolve(map);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public void onFailure(String errorText) {
|
|
214
|
+
Log.e(TAG, "Failure registering device with Vibes Push SDK: " + errorText);
|
|
215
|
+
if (promise != null) {
|
|
216
|
+
promise.reject(REGISTER_DEVICE_ERROR_KEY, errorText);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private VibesListener<Void> getRegisterPushListener(final Promise promise) {
|
|
223
|
+
return new VibesListener<Void>() {
|
|
224
|
+
public void onSuccess(Void credential) {
|
|
225
|
+
appHelper.saveBoolean(VibesModule.TOKEN_REGISTERED, true);
|
|
226
|
+
Log.d(TAG, "Push token registration successful");
|
|
227
|
+
if (promise != null) {
|
|
228
|
+
promise.resolve("Success");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public void onFailure(String errorText) {
|
|
233
|
+
appHelper.saveBoolean(VibesModule.TOKEN_REGISTERED, false);
|
|
234
|
+
Log.d(TAG, "Failure registering token with Vibes Push SDK: " + errorText);
|
|
235
|
+
if (promise != null) {
|
|
236
|
+
promise.reject(REGISTER_DEVICE_ERROR_KEY, errorText);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* To be able to target each device, we need to send the push token generated by
|
|
244
|
+
* the Firebase environment to the
|
|
245
|
+
* server-side via the SDK. However, ensure that {@link Vibes#registerDevice()}
|
|
246
|
+
* has been called before this is called.
|
|
247
|
+
*
|
|
248
|
+
* @param pushToken
|
|
249
|
+
*/
|
|
250
|
+
public static void registerPush(String pushToken) {
|
|
251
|
+
Log.d(TAG, "Registering push token with vibes");
|
|
252
|
+
VibesListener<Void> listener = new VibesListener<Void>() {
|
|
253
|
+
public void onSuccess(Void credential) {
|
|
254
|
+
Log.d(TAG, "Push token registration successful");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
public void onFailure(String errorText) {
|
|
258
|
+
Log.d(TAG, "Failure registering token with Vibes Push SDK: " + errorText);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
registerPush(pushToken, listener);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public static void registerPush(String pushToken, VibesListener<Void> listener) {
|
|
265
|
+
Vibes.getInstance().registerPush(pushToken, listener);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Unregisters a device from receiving further push notifications
|
|
270
|
+
*/
|
|
271
|
+
@ReactMethod
|
|
272
|
+
public void unregisterPush(final Promise promise) {
|
|
273
|
+
VibesListener<Void> listener = new VibesListener<Void>() {
|
|
274
|
+
public void onSuccess(Void credential) {
|
|
275
|
+
Log.d(TAG, "Unregister push successful");
|
|
276
|
+
appHelper.saveString(VibesModule.TOKEN_KEY, null);
|
|
277
|
+
appHelper.saveBoolean(VibesModule.TOKEN_REGISTERED, false);
|
|
278
|
+
promise.resolve("Success");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
public void onFailure(String errorText) {
|
|
282
|
+
Log.d(TAG, "Unregister push failed");
|
|
283
|
+
promise.reject("REGISTER_PUSH_ERROR", errorText);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
Vibes.getInstance().unregisterPush(listener);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param externalPersonId The id to associate with the logged-in person.
|
|
291
|
+
*/
|
|
292
|
+
@ReactMethod
|
|
293
|
+
public void associatePerson(final String externalPersonId, final Promise promise) {
|
|
294
|
+
Log.d(TAG, "Associating Person --> " + externalPersonId);
|
|
295
|
+
VibesListener<Void> listener = new VibesListener<Void>() {
|
|
296
|
+
public void onSuccess(Void value) {
|
|
297
|
+
promise.resolve("Success");
|
|
298
|
+
;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
public void onFailure(String errorText) {
|
|
302
|
+
promise.reject("ASSOCIATE_PERSON_ERROR", errorText);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
this.associatePerson(externalPersonId, listener);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
private void associatePerson(String externalPersonId, VibesListener<Void> listener) {
|
|
309
|
+
Vibes.getInstance().associatePerson(externalPersonId, listener);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Fetches details of a person associated with device
|
|
314
|
+
*/
|
|
315
|
+
@ReactMethod
|
|
316
|
+
public void getPerson(final Promise promise) {
|
|
317
|
+
VibesListener<Person> listener = new VibesListener<Person>() {
|
|
318
|
+
public void onSuccess(Person value) {
|
|
319
|
+
Log.d(TAG, "Get Person Successful");
|
|
320
|
+
appHelper.saveString(VibesModule.PERSON_KEY, value.getPersonKey());
|
|
321
|
+
appHelper.saveString(VibesModule.EXTERNAL_PERSON_ID_KEY, value.getExternalPersonId());
|
|
322
|
+
|
|
323
|
+
WritableMap map = Arguments.createMap();
|
|
324
|
+
map.putString("person_key", value.getPersonKey());
|
|
325
|
+
map.putString("external_person_id", value.getExternalPersonId());
|
|
326
|
+
if (promise != null) {
|
|
327
|
+
promise.resolve(map);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
public void onFailure(String errorText) {
|
|
332
|
+
Log.d(TAG, "Get Person Failed failed");
|
|
333
|
+
promise.reject(GET_PERSON_ERROR, errorText);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
Vibes.getInstance().getPerson(listener);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* React Native Plugin Method that updates client device information with Vibes.
|
|
341
|
+
*
|
|
342
|
+
* @param updateCredential a boolean indicating if it's a token update or device
|
|
343
|
+
* info update. Specify false if not certain
|
|
344
|
+
* @param latitude client device latitude
|
|
345
|
+
* @param longitude client device longitude
|
|
346
|
+
*/
|
|
347
|
+
@ReactMethod
|
|
348
|
+
public void updateDevice(final boolean updateCredential, Double latitude, Double longitude, final Promise promise) {
|
|
349
|
+
Log.d(TAG, "Plugin called to update");
|
|
350
|
+
VibesListener<Credential> listener = getRegisterDeviceListener(promise);
|
|
351
|
+
Vibes.getInstance().updateDevice(updateCredential, latitude, longitude, listener);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
@ReactMethod
|
|
355
|
+
public void fetchInboxMessages(final Promise promise) {
|
|
356
|
+
VibesListener<Collection<InboxMessage>> listener = new VibesListener<Collection<InboxMessage>>() {
|
|
357
|
+
public void onSuccess(Collection<InboxMessage> values) {
|
|
358
|
+
Log.d(TAG, "Fetch inbox messages success");
|
|
359
|
+
Gson gson = new Gson();
|
|
360
|
+
WritableArray array = Arguments.createArray();
|
|
361
|
+
for (InboxMessage message : values) {
|
|
362
|
+
try {
|
|
363
|
+
JSONObject jsonObject = new JSONObject(gson.toJson(message));
|
|
364
|
+
WritableMap writableMap = appHelper.convertJsonToMap(jsonObject);
|
|
365
|
+
array.pushMap(writableMap);
|
|
366
|
+
} catch (JSONException e) {
|
|
367
|
+
Log.e(TAG, e.getLocalizedMessage());
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (promise != null) {
|
|
371
|
+
promise.resolve(array);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
public void onFailure(String errorText) {
|
|
376
|
+
Log.d(TAG, "Fetch inbox messages failed: " + errorText);
|
|
377
|
+
promise.reject(FETCH_INBOX_MESSAGES_ERROR, errorText);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
Vibes.getInstance().fetchInboxMessages(listener);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
@ReactMethod
|
|
384
|
+
public void fetchInboxMessage(final String messageUid, final Promise promise) {
|
|
385
|
+
VibesListener<InboxMessage> listener = new VibesListener<InboxMessage>() {
|
|
386
|
+
public void onSuccess(InboxMessage message) {
|
|
387
|
+
Log.d(TAG, "Fetch single inbox message success");
|
|
388
|
+
Gson gson = new Gson();
|
|
389
|
+
try {
|
|
390
|
+
JSONObject jsonObject = new JSONObject(gson.toJson(message));
|
|
391
|
+
WritableMap writableMap = appHelper.convertJsonToMap(jsonObject);
|
|
392
|
+
if (promise != null) {
|
|
393
|
+
promise.resolve(writableMap);
|
|
394
|
+
}
|
|
395
|
+
} catch (JSONException e) {
|
|
396
|
+
Log.e(TAG, e.getLocalizedMessage());
|
|
397
|
+
promise.reject(FETCH_SINGLE_INBOX_MESSAGE_ERROR, e.getLocalizedMessage());
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
public void onFailure(String errorText) {
|
|
402
|
+
Log.d(TAG, "Fetch single inbox message failed: " + errorText);
|
|
403
|
+
promise.reject(FETCH_SINGLE_INBOX_MESSAGE_ERROR, errorText);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
Vibes.getInstance().fetchInboxMessage(messageUid, listener);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
@ReactMethod
|
|
410
|
+
public void markInboxMessageAsRead(final String messageUid, final Promise promise) {
|
|
411
|
+
VibesListener<InboxMessage> listener = new VibesListener<InboxMessage>() {
|
|
412
|
+
public void onSuccess(InboxMessage message) {
|
|
413
|
+
Log.d(TAG, "Mark inbox message as read");
|
|
414
|
+
Gson gson = new Gson();
|
|
415
|
+
try {
|
|
416
|
+
JSONObject jsonObject = new JSONObject(gson.toJson(message));
|
|
417
|
+
WritableMap writableMap = appHelper.convertJsonToMap(jsonObject);
|
|
418
|
+
if (promise != null) {
|
|
419
|
+
promise.resolve(writableMap);
|
|
420
|
+
}
|
|
421
|
+
} catch (JSONException e) {
|
|
422
|
+
Log.e(TAG, e.getLocalizedMessage());
|
|
423
|
+
promise.reject(MARK_INBOX_MESSAGE_AS_READ_ERROR, e.getLocalizedMessage());
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
public void onFailure(String errorText) {
|
|
428
|
+
Log.d(TAG, "Marking inbox message as read failed: " + errorText);
|
|
429
|
+
promise.reject(MARK_INBOX_MESSAGE_AS_READ_ERROR, errorText);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
Vibes.getInstance().markInboxMessageAsRead(messageUid, listener);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
@ReactMethod
|
|
436
|
+
public void expireInboxMessage(final String messageUid, final Promise promise) {
|
|
437
|
+
VibesListener<InboxMessage> listener = new VibesListener<InboxMessage>() {
|
|
438
|
+
public void onSuccess(InboxMessage message) {
|
|
439
|
+
Log.d(TAG, "Expiring inbox message successful");
|
|
440
|
+
Gson gson = new Gson();
|
|
441
|
+
try {
|
|
442
|
+
JSONObject jsonObject = new JSONObject(gson.toJson(message));
|
|
443
|
+
WritableMap writableMap = appHelper.convertJsonToMap(jsonObject);
|
|
444
|
+
if (promise != null) {
|
|
445
|
+
promise.resolve(writableMap);
|
|
446
|
+
}
|
|
447
|
+
} catch (JSONException e) {
|
|
448
|
+
Log.e(TAG, e.getLocalizedMessage());
|
|
449
|
+
promise.reject(EXPIRE_INBOX_MESSAGE_ERROR, e.getLocalizedMessage());
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
public void onFailure(String errorText) {
|
|
454
|
+
Log.d(TAG, "Expiring inbox message failed: " + errorText);
|
|
455
|
+
promise.reject(EXPIRE_INBOX_MESSAGE_ERROR, errorText);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
Vibes.getInstance().expireInboxMessage(messageUid, listener);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
@ReactMethod
|
|
462
|
+
public void onInboxMessageOpen(ReadableMap readableMap, final Promise promise) {
|
|
463
|
+
Log.d(TAG, "Recording an inbox_open event");
|
|
464
|
+
Gson gson = new Gson();
|
|
465
|
+
try {
|
|
466
|
+
JSONObject jsonObject = appHelper.convertMapToJson(readableMap);
|
|
467
|
+
InboxMessage inboxMessage = gson.fromJson(jsonObject.toString(), InboxMessage.class);
|
|
468
|
+
Vibes.getInstance().onInboxMessageOpen(inboxMessage);
|
|
469
|
+
if (promise != null) {
|
|
470
|
+
Log.d(TAG, "Success recording an inbox_open event");
|
|
471
|
+
promise.resolve("");
|
|
472
|
+
}
|
|
473
|
+
} catch (Exception e) {
|
|
474
|
+
Log.e(TAG, "Error recording inbox_open event: " + e.getLocalizedMessage());
|
|
475
|
+
promise.reject(INBOX_MESSAGE_OPEN_ERROR, e.getLocalizedMessage());
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
@ReactMethod
|
|
481
|
+
public void onInboxMessagesFetched(final Promise promise) {
|
|
482
|
+
Log.d(TAG, "Recording an inbox_fetch event");
|
|
483
|
+
Vibes.getInstance().onInboxMessagesFetched();
|
|
484
|
+
if (promise != null) {
|
|
485
|
+
Log.d(TAG, "Success recording an inbox_fetch event");
|
|
486
|
+
promise.resolve("");
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.vibes.push.rn.plugin;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
public class VibesPackage implements ReactPackage {
|
|
15
|
+
@NonNull
|
|
16
|
+
@Override
|
|
17
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
19
|
+
modules.add(new VibesModule(reactContext));
|
|
20
|
+
return modules;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@NonNull
|
|
24
|
+
@Override
|
|
25
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
26
|
+
return Collections.emptyList();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
package com.vibes.push.rn.plugin.notifications;
|
|
2
|
+
|
|
3
|
+
import static com.vibes.push.rn.plugin.VibesModule.DEVICE_REGISTERED;
|
|
4
|
+
import static com.vibes.push.rn.plugin.VibesModule.TAG;
|
|
5
|
+
import static com.vibes.push.rn.plugin.VibesModule.TOKEN_KEY;
|
|
6
|
+
import static com.vibes.push.rn.plugin.VibesModule.VIBES_APIURL_KEY;
|
|
7
|
+
import static com.vibes.push.rn.plugin.VibesModule.VIBES_APPID_KEY;
|
|
8
|
+
|
|
9
|
+
import android.content.SharedPreferences;
|
|
10
|
+
import android.content.pm.ApplicationInfo;
|
|
11
|
+
import android.content.pm.PackageManager;
|
|
12
|
+
import android.os.Bundle;
|
|
13
|
+
import android.os.Handler;
|
|
14
|
+
import android.os.Looper;
|
|
15
|
+
import android.preference.PreferenceManager;
|
|
16
|
+
import android.util.Log;
|
|
17
|
+
|
|
18
|
+
import com.facebook.react.ReactApplication;
|
|
19
|
+
import com.facebook.react.ReactInstanceManager;
|
|
20
|
+
import com.facebook.react.bridge.ReactContext;
|
|
21
|
+
import com.google.firebase.messaging.FirebaseMessagingService;
|
|
22
|
+
import com.google.firebase.messaging.RemoteMessage;
|
|
23
|
+
import com.vibes.push.rn.plugin.PushEvtEmitter;
|
|
24
|
+
import com.vibes.push.rn.plugin.VibesModule;
|
|
25
|
+
import com.vibes.vibes.PushPayloadParser;
|
|
26
|
+
import com.vibes.vibes.Vibes;
|
|
27
|
+
import com.vibes.vibes.VibesConfig;
|
|
28
|
+
|
|
29
|
+
import java.util.Map;
|
|
30
|
+
|
|
31
|
+
public class Fms extends FirebaseMessagingService {
|
|
32
|
+
private PushPayloadParser pushModel;
|
|
33
|
+
private RemoteMessage message;
|
|
34
|
+
|
|
35
|
+
@Override
|
|
36
|
+
public void onMessageReceived(RemoteMessage message) {
|
|
37
|
+
Log.d(TAG, "Push message received. Processing");
|
|
38
|
+
this.message = message;
|
|
39
|
+
this.pushModel = createPushPayloadParser(message.getData());
|
|
40
|
+
|
|
41
|
+
if (!initializeVibes()) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
handleNotification(pushModel, message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Override
|
|
48
|
+
public void onNewToken(String pushToken) {
|
|
49
|
+
super.onNewToken(pushToken);
|
|
50
|
+
Log.d(TAG, "Firebase token obtained from Fms as " + pushToken);
|
|
51
|
+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
52
|
+
preferences.edit().putString(TOKEN_KEY, pushToken).apply();
|
|
53
|
+
|
|
54
|
+
if (preferences.getBoolean(DEVICE_REGISTERED, false)) {
|
|
55
|
+
VibesModule.registerPush(pushToken);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private boolean initializeVibes() {
|
|
60
|
+
try {
|
|
61
|
+
Vibes.getInstance();
|
|
62
|
+
return true;
|
|
63
|
+
} catch (Exception e) {
|
|
64
|
+
initializeVibesAsync();
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private void initializeVibesAsync() {
|
|
70
|
+
ApplicationInfo ai;
|
|
71
|
+
try {
|
|
72
|
+
ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
|
|
73
|
+
} catch (PackageManager.NameNotFoundException e) {
|
|
74
|
+
Log.e(TAG, "Failed to get application info", e);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Bundle bundle = ai.metaData;
|
|
79
|
+
new Handler(Looper.getMainLooper()).post(() -> {
|
|
80
|
+
String appId = bundle.getString(VIBES_APPID_KEY);
|
|
81
|
+
String apiUrl = bundle.getString(VIBES_APIURL_KEY);
|
|
82
|
+
|
|
83
|
+
VibesConfig config = new VibesConfig.Builder()
|
|
84
|
+
.setAppId(appId)
|
|
85
|
+
.setApiUrl(apiUrl != null && !apiUrl.isEmpty() ? apiUrl : null)
|
|
86
|
+
.build();
|
|
87
|
+
Log.d(TAG, "Initializing Vibes with appId=[" + appId + "] and apiUrl=[" + apiUrl + "]");
|
|
88
|
+
Vibes.initialize(this, config);
|
|
89
|
+
handleNotification(pushModel, message);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private void handleNotification(PushPayloadParser pushModel, RemoteMessage message) {
|
|
94
|
+
new Thread(() -> {
|
|
95
|
+
try {
|
|
96
|
+
Vibes.getInstance().handleNotification(getApplicationContext(), message.getData());
|
|
97
|
+
if (!pushModel.isSilentPush()) {
|
|
98
|
+
emitPayload(pushModel);
|
|
99
|
+
}
|
|
100
|
+
} catch (Exception e) {
|
|
101
|
+
Log.e(TAG, "Error handling notification", e);
|
|
102
|
+
}
|
|
103
|
+
}).start();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public PushPayloadParser createPushPayloadParser(Map<String, String> map) {
|
|
107
|
+
return new PushPayloadParser(map);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private void emitPayload(PushPayloadParser pushModel) {
|
|
111
|
+
new Handler(Looper.getMainLooper()).post(() -> {
|
|
112
|
+
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost()
|
|
113
|
+
.getReactInstanceManager();
|
|
114
|
+
ReactContext context = mReactInstanceManager.getCurrentReactContext();
|
|
115
|
+
if (context != null) {
|
|
116
|
+
new PushEvtEmitter(context).notifyPushReceived(pushModel);
|
|
117
|
+
} else {
|
|
118
|
+
mReactInstanceManager
|
|
119
|
+
.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
|
|
120
|
+
@Override
|
|
121
|
+
public void onReactContextInitialized(ReactContext context) {
|
|
122
|
+
new PushEvtEmitter(context).notifyPushReceived(pushModel);
|
|
123
|
+
mReactInstanceManager.removeReactInstanceEventListener(this);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
|
|
127
|
+
mReactInstanceManager.createReactContextInBackground();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
package com.vibes.push.rn.plugin.notifications;
|
|
3
|
+
|
|
4
|
+
import com.vibes.vibes.PushPayloadParser;
|
|
5
|
+
|
|
6
|
+
public class PayloadWrapper {
|
|
7
|
+
|
|
8
|
+
private final PushPayloadParser payload;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
public PayloadWrapper(PushPayloadParser payload) {
|
|
12
|
+
this.payload = payload;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
public String toString() {
|
|
17
|
+
return "PayloadWrapper{" +
|
|
18
|
+
"title=" + payload.getTitle() +", body=" + payload.getBody()+", channel=" + payload.getChannel()+", notification_channel=" + payload.getNotificationChannel()
|
|
19
|
+
+", silent_push=" + payload.isSilentPush()+", sound=" + payload.getSound()+", rich_media_url=" + payload.getRichPushMediaURL()+", vibes_collapse_id=" + payload.getVibesCollapseId()
|
|
20
|
+
+", priority=" + payload.getPriority()+", custom_client_data=" + payload.getCustomClientData()+ '}';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|