vibes-react-native 1.0.0 → 1.1.1
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 +114 -1
- package/android/.gradle/6.8/executionHistory/executionHistory.lock +0 -0
- 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/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +42 -40
- package/android/src/main/AndroidManifest.xml +6 -4
- package/android/src/main/java/com/vibes/push/rn/plugin/VibesAppHelper.java +170 -84
- package/android/src/main/java/com/vibes/push/rn/plugin/VibesModule.java +466 -303
- package/android/src/main/java/com/vibes/push/rn/plugin/notifications/Fms.java +95 -82
- package/android/src/main/java/com/vibes/push/rn/plugin/notifications/VibesPushReceiver.java +9 -7
- package/ios/Vibes.m +25 -0
- package/ios/Vibes.swift +143 -1
- package/lib/commonjs/index.js +117 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +113 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +115 -6
- package/package.json +1 -1
- package/src/index.tsx +149 -15
- package/vibes-react-native.podspec +1 -1
|
@@ -1,114 +1,127 @@
|
|
|
1
1
|
package com.vibes.push.rn.plugin.notifications;
|
|
2
2
|
|
|
3
|
-
import
|
|
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
|
+
|
|
4
9
|
import android.content.SharedPreferences;
|
|
10
|
+
import android.content.pm.ApplicationInfo;
|
|
11
|
+
import android.content.pm.PackageManager;
|
|
5
12
|
import android.os.Bundle;
|
|
6
|
-
import android.preference.PreferenceManager;
|
|
7
|
-
import android.util.Log;
|
|
8
13
|
import android.os.Handler;
|
|
9
14
|
import android.os.Looper;
|
|
15
|
+
import android.preference.PreferenceManager;
|
|
16
|
+
import android.util.Log;
|
|
10
17
|
|
|
18
|
+
import com.facebook.react.ReactApplication;
|
|
19
|
+
import com.facebook.react.ReactInstanceManager;
|
|
20
|
+
import com.facebook.react.bridge.ReactContext;
|
|
11
21
|
import com.google.firebase.messaging.FirebaseMessagingService;
|
|
12
22
|
import com.google.firebase.messaging.RemoteMessage;
|
|
13
|
-
import com.vibes.
|
|
23
|
+
import com.vibes.push.rn.plugin.PushEvtEmitter;
|
|
24
|
+
import com.vibes.push.rn.plugin.VibesModule;
|
|
14
25
|
import com.vibes.vibes.PushPayloadParser;
|
|
15
26
|
import com.vibes.vibes.Vibes;
|
|
16
|
-
|
|
17
|
-
import com.facebook.react.ReactApplication;
|
|
18
|
-
import com.facebook.react.ReactInstanceManager;
|
|
19
|
-
import com.facebook.react.bridge.ReactContext;
|
|
27
|
+
import com.vibes.vibes.VibesConfig;
|
|
20
28
|
|
|
21
29
|
import java.util.Map;
|
|
22
|
-
import com.vibes.push.rn.plugin.VibesModule;
|
|
23
|
-
import com.vibes.push.rn.plugin.PushEvtEmitter;
|
|
24
|
-
import static com.vibes.push.rn.plugin.VibesModule.TAG;
|
|
25
|
-
import static com.vibes.push.rn.plugin.VibesModule.TOKEN_KEY;
|
|
26
|
-
import static com.vibes.push.rn.plugin.VibesModule.DEVICE_REGISTERED;
|
|
27
30
|
|
|
28
31
|
public class Fms extends FirebaseMessagingService {
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
@Override
|
|
34
|
+
public void onMessageReceived(RemoteMessage message) {
|
|
35
|
+
Log.d(TAG, "Push message received. Processing");
|
|
36
|
+
PushPayloadParser pushModel = createPushPayloadParser(message.getData());
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if (!initializeVibes()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
handleNotification(pushModel, message);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Override
|
|
46
|
+
public void onNewToken(String pushToken) {
|
|
47
|
+
super.onNewToken(pushToken);
|
|
48
|
+
Log.d(TAG, "Firebase token obtained from Fms as " + pushToken);
|
|
49
|
+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
50
|
+
preferences.edit().putString(TOKEN_KEY, pushToken).apply();
|
|
51
|
+
|
|
52
|
+
if (preferences.getBoolean(DEVICE_REGISTERED, false)) {
|
|
53
|
+
VibesModule.registerPush(pushToken);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private boolean initializeVibes() {
|
|
58
|
+
try {
|
|
59
|
+
Vibes.getInstance();
|
|
60
|
+
return true;
|
|
61
|
+
} catch (Exception e) {
|
|
62
|
+
initializeVibesAsync();
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private void initializeVibesAsync() {
|
|
68
|
+
ApplicationInfo ai;
|
|
69
|
+
try {
|
|
70
|
+
ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
|
|
71
|
+
} catch (PackageManager.NameNotFoundException e) {
|
|
72
|
+
Log.e(TAG, "Failed to get application info", e);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Bundle bundle = ai.metaData;
|
|
77
|
+
new Handler(Looper.getMainLooper()).post(() -> {
|
|
78
|
+
String appId = bundle.getString(VIBES_APPID_KEY);
|
|
79
|
+
String apiUrl = bundle.getString(VIBES_APIURL_KEY);
|
|
80
|
+
|
|
81
|
+
VibesConfig config = new VibesConfig.Builder()
|
|
82
|
+
.setAppId(appId)
|
|
83
|
+
.setApiUrl(apiUrl != null && !apiUrl.isEmpty() ? apiUrl : null)
|
|
84
|
+
.build();
|
|
85
|
+
Log.d(TAG, "Initializing Vibes with appId=[" + appId + "] and apiUrl=[" + apiUrl + "]");
|
|
86
|
+
Vibes.initialize(this, config);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private void handleNotification(PushPayloadParser pushModel, RemoteMessage message) {
|
|
91
|
+
new Thread(() -> {
|
|
41
92
|
try {
|
|
42
93
|
Vibes.getInstance().handleNotification(getApplicationContext(), message.getData());
|
|
43
94
|
if (!pushModel.isSilentPush()) {
|
|
44
95
|
emitPayload(pushModel);
|
|
45
96
|
}
|
|
46
|
-
} catch(
|
|
47
|
-
|
|
48
|
-
handler.post(new Runnable() {
|
|
49
|
-
public void run() {
|
|
50
|
-
Vibes.getInstance().handleNotification(getApplicationContext(), message.getData());
|
|
51
|
-
if (!pushModel.isSilentPush()) {
|
|
52
|
-
emitPayload(pushModel);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
97
|
+
} catch (Exception e) {
|
|
98
|
+
Log.e(TAG, "Error handling notification", e);
|
|
56
99
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
* This is invoked everytime the application generates a new Firebase push
|
|
60
|
-
* token, which is then sent to the Vibes server to be able to target this
|
|
61
|
-
* device with push messages.
|
|
62
|
-
*
|
|
63
|
-
* @param pushToken
|
|
64
|
-
*/
|
|
65
|
-
@Override
|
|
66
|
-
public void onNewToken(String pushToken) {
|
|
67
|
-
super.onNewToken(pushToken);
|
|
68
|
-
Log.d(TAG, "Firebase token obtained from Fms as " + pushToken);
|
|
69
|
-
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
70
|
-
SharedPreferences.Editor editor = preferences.edit();
|
|
71
|
-
editor.putString(TOKEN_KEY, pushToken);
|
|
72
|
-
editor.apply();
|
|
73
|
-
|
|
74
|
-
boolean registered = preferences.getBoolean(DEVICE_REGISTERED, false);
|
|
75
|
-
if (registered) {
|
|
76
|
-
VibesModule.registerPush(pushToken);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
100
|
+
}).start();
|
|
101
|
+
}
|
|
79
102
|
|
|
80
103
|
public PushPayloadParser createPushPayloadParser(Map<String, String> map) {
|
|
81
104
|
return new PushPayloadParser(map);
|
|
82
105
|
}
|
|
83
106
|
|
|
84
107
|
private void emitPayload(PushPayloadParser pushModel) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
mReactInstanceManager.
|
|
102
|
-
public void onReactContextInitialized(ReactContext context) {
|
|
103
|
-
PushEvtEmitter pushEmitter = new PushEvtEmitter(context);
|
|
104
|
-
pushEmitter.notifyPushReceived(pushModel);
|
|
105
|
-
mReactInstanceManager.removeReactInstanceEventListener(this);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
|
|
109
|
-
// Construct it in the background
|
|
110
|
-
mReactInstanceManager.createReactContextInBackground();
|
|
111
|
-
}
|
|
108
|
+
new Handler(Looper.getMainLooper()).post(() -> {
|
|
109
|
+
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost()
|
|
110
|
+
.getReactInstanceManager();
|
|
111
|
+
ReactContext context = mReactInstanceManager.getCurrentReactContext();
|
|
112
|
+
if (context != null) {
|
|
113
|
+
new PushEvtEmitter(context).notifyPushReceived(pushModel);
|
|
114
|
+
} else {
|
|
115
|
+
mReactInstanceManager
|
|
116
|
+
.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
|
|
117
|
+
@Override
|
|
118
|
+
public void onReactContextInitialized(ReactContext context) {
|
|
119
|
+
new PushEvtEmitter(context).notifyPushReceived(pushModel);
|
|
120
|
+
mReactInstanceManager.removeReactInstanceEventListener(this);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
|
|
124
|
+
mReactInstanceManager.createReactContextInBackground();
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
127
|
});
|
|
@@ -16,8 +16,8 @@ import com.vibes.vibes.VibesReceiver;
|
|
|
16
16
|
|
|
17
17
|
import static com.vibes.push.rn.plugin.VibesModule.TAG;
|
|
18
18
|
|
|
19
|
-
public class VibesPushReceiver extends VibesReceiver{
|
|
20
|
-
|
|
19
|
+
public class VibesPushReceiver extends VibesReceiver {
|
|
20
|
+
|
|
21
21
|
@Override
|
|
22
22
|
protected void onPushOpened(Context context, PushPayloadParser pushModel) {
|
|
23
23
|
super.onPushOpened(context, pushModel);
|
|
@@ -25,16 +25,18 @@ public class VibesPushReceiver extends VibesReceiver{
|
|
|
25
25
|
emitPayload(context, pushModel);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
// Namely, DevServerHelper constructs a Handler() without a Looper, which
|
|
28
|
+
public static void emitPayload(Context context, PushPayloadParser pushModel) {
|
|
29
|
+
// We need to run this on the main thread, as the React code assumes that is
|
|
30
|
+
// true.
|
|
31
|
+
// Namely, DevServerHelper constructs a Handler() without a Looper, which
|
|
32
|
+
// triggers:
|
|
32
33
|
// "Can't create handler inside thread that has not called Looper.prepare()"
|
|
33
34
|
Handler handler = new Handler(Looper.getMainLooper());
|
|
34
35
|
handler.post(new Runnable() {
|
|
35
36
|
public void run() {
|
|
36
37
|
// Construct and load our normal React JS code bundle
|
|
37
|
-
final ReactInstanceManager mReactInstanceManager = ((ReactApplication) context.getApplicationContext())
|
|
38
|
+
final ReactInstanceManager mReactInstanceManager = ((ReactApplication) context.getApplicationContext())
|
|
39
|
+
.getReactNativeHost().getReactInstanceManager();
|
|
38
40
|
ReactContext context = mReactInstanceManager.getCurrentReactContext();
|
|
39
41
|
// If it's constructed, send a notification
|
|
40
42
|
if (context != null) {
|
package/ios/Vibes.m
CHANGED
|
@@ -27,5 +27,30 @@ RCT_EXTERN_METHOD(updateDevice: (BOOL ) updateCredentials
|
|
|
27
27
|
resolver:(RCTPromiseResolveBlock *)resolve
|
|
28
28
|
rejecter:(RCTPromiseRejectBlock *)reject)
|
|
29
29
|
|
|
30
|
+
RCT_EXTERN_METHOD(getPerson: (RCTPromiseResolveBlock *)resolve
|
|
31
|
+
rejecter:(RCTPromiseRejectBlock *)reject)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
RCT_EXTERN_METHOD(fetchInboxMessages: (RCTPromiseResolveBlock *)resolve
|
|
35
|
+
rejecter:(RCTPromiseRejectBlock *)reject)
|
|
36
|
+
|
|
37
|
+
RCT_EXTERN_METHOD(fetchInboxMessage: (NSString *) messageUID
|
|
38
|
+
resolve:(RCTPromiseResolveBlock *)resolve
|
|
39
|
+
reject:(RCTPromiseRejectBlock *)reject)
|
|
40
|
+
|
|
41
|
+
RCT_EXTERN_METHOD(markInboxMessageAsRead: (NSString *) messageUID
|
|
42
|
+
resolve:(RCTPromiseResolveBlock *)resolve
|
|
43
|
+
reject:(RCTPromiseRejectBlock *)reject)
|
|
44
|
+
|
|
45
|
+
RCT_EXTERN_METHOD(expireInboxMessage: (NSString *) messageUID
|
|
46
|
+
resolve:(RCTPromiseResolveBlock *)resolve
|
|
47
|
+
reject:(RCTPromiseRejectBlock *)reject)
|
|
48
|
+
|
|
49
|
+
RCT_EXTERN_METHOD(onInboxMessageOpen: (NSDictionary *) message
|
|
50
|
+
resolve:(RCTPromiseResolveBlock *)resolve
|
|
51
|
+
reject:(RCTPromiseRejectBlock *)reject)
|
|
52
|
+
|
|
53
|
+
RCT_EXTERN_METHOD(onInboxMessagesFetched: (RCTPromiseResolveBlock *)resolve
|
|
54
|
+
reject:(RCTPromiseRejectBlock *)reject)
|
|
30
55
|
@end
|
|
31
56
|
|
package/ios/Vibes.swift
CHANGED
|
@@ -7,6 +7,8 @@ class Vibes: NSObject, RCTBridgeModule, VibesPush.VibesAPIDelegate {
|
|
|
7
7
|
static func moduleName() -> String! {
|
|
8
8
|
return "Vibes"
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
public typealias JSONDictionary = [String: Any]
|
|
10
12
|
|
|
11
13
|
let userDefaults = UserDefaults.standard
|
|
12
14
|
|
|
@@ -136,7 +138,7 @@ class Vibes: NSObject, RCTBridgeModule, VibesPush.VibesAPIDelegate {
|
|
|
136
138
|
@objc
|
|
137
139
|
/// Get Vibes Device Info
|
|
138
140
|
/// - Parameters:
|
|
139
|
-
/// - resolve:
|
|
141
|
+
/// - resolve: promise resolver
|
|
140
142
|
/// - reject: promise rejector
|
|
141
143
|
func getVibesDeviceInfo(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
142
144
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
@@ -148,7 +150,147 @@ class Vibes: NSObject, RCTBridgeModule, VibesPush.VibesAPIDelegate {
|
|
|
148
150
|
resolve(["device_id": deviceId])
|
|
149
151
|
}
|
|
150
152
|
}
|
|
153
|
+
|
|
154
|
+
@objc
|
|
155
|
+
/// Get Person Info
|
|
156
|
+
/// - Parameters:
|
|
157
|
+
/// - resolve: promise resolver
|
|
158
|
+
/// - reject: promise rejector
|
|
159
|
+
func getPerson(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
160
|
+
rejecter reject: @escaping RCTPromiseRejectBlock ) -> Void {
|
|
161
|
+
vibes.getPerson { person, error in
|
|
162
|
+
if let error = error {
|
|
163
|
+
reject("GET_PERSON_ERROR", error.localizedDescription, error)
|
|
164
|
+
} else {
|
|
165
|
+
resolve(["external_person_id": person?.externalPersonId, "person_key": person?.personKey])
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@objc
|
|
171
|
+
/// Fetch Inbox Messages
|
|
172
|
+
///
|
|
173
|
+
/// - Parameters:
|
|
174
|
+
/// - resolve: promise resolver
|
|
175
|
+
/// - reject: promise rejector
|
|
176
|
+
func fetchInboxMessages(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
177
|
+
rejecter reject: @escaping RCTPromiseRejectBlock ) -> Void {
|
|
178
|
+
vibes.fetchInboxMessages({ messages, error in
|
|
179
|
+
if let error = error {
|
|
180
|
+
reject("FETCH_INBOX_MESSAGES_ERROR", error.localizedDescription, error)
|
|
181
|
+
} else {
|
|
182
|
+
var msgs: [JSONDictionary] = []
|
|
183
|
+
for msg in messages {
|
|
184
|
+
msgs.append(msg.encodeJSON())
|
|
185
|
+
}
|
|
186
|
+
resolve(msgs)
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
}
|
|
151
190
|
|
|
191
|
+
@objc
|
|
192
|
+
/// Fetch single Inbox Message
|
|
193
|
+
///
|
|
194
|
+
/// - Parameters:
|
|
195
|
+
/// - messageUid: The Message ID
|
|
196
|
+
/// - resolve: promise resolver
|
|
197
|
+
/// - reject: promise rejector
|
|
198
|
+
func fetchInboxMessage(_ messageUid: String,
|
|
199
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
200
|
+
reject: @escaping RCTPromiseRejectBlock ) -> Void {
|
|
201
|
+
vibes.fetchInboxMessage(messageUID: messageUid) {message, error in
|
|
202
|
+
|
|
203
|
+
if let error = error {
|
|
204
|
+
reject("FETCH_INBOX_MESSAGE_ERROR", error.localizedDescription, error)
|
|
205
|
+
} else {
|
|
206
|
+
if let message = message {
|
|
207
|
+
resolve(message.encodeJSON())
|
|
208
|
+
} else {
|
|
209
|
+
reject("FETCH_INBOX_MESSAGE_ERROR", "message encoding faild", "message encoding faild" as? Error)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@objc
|
|
216
|
+
/// Mark Inbox Message as Read
|
|
217
|
+
///
|
|
218
|
+
/// - Parameters:
|
|
219
|
+
/// - messageUid: The Message ID
|
|
220
|
+
/// - resolve: promise resolver
|
|
221
|
+
/// - reject: promise rejector
|
|
222
|
+
func markInboxMessageAsRead(_ messageUid: String,
|
|
223
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
224
|
+
reject: @escaping RCTPromiseRejectBlock ) -> Void {
|
|
225
|
+
vibes.markInboxMessageAsRead(messageUID: messageUid) {message, error in
|
|
226
|
+
|
|
227
|
+
if let error = error {
|
|
228
|
+
reject("MARK_INBOX_MESSAGE_AS_READ_ERROR", error.localizedDescription, error)
|
|
229
|
+
} else {
|
|
230
|
+
if let message = message {
|
|
231
|
+
resolve(message.encodeJSON())
|
|
232
|
+
} else {
|
|
233
|
+
reject("MARK_INBOX_MESSAGE_AS_READ_ERROR", "message encoding faild", "message encoding faild" as? Error)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@objc
|
|
240
|
+
/// Expire Inbox Message
|
|
241
|
+
///
|
|
242
|
+
/// - Parameters:
|
|
243
|
+
/// - messageUid: The Message ID
|
|
244
|
+
/// - resolve: promise resolver
|
|
245
|
+
/// - reject: promise rejector
|
|
246
|
+
func expireInboxMessage(_ messageUid: String,
|
|
247
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
248
|
+
reject: @escaping RCTPromiseRejectBlock ) -> Void {
|
|
249
|
+
vibes.expireInboxMessage(messageUID: messageUid) {message, error in
|
|
250
|
+
|
|
251
|
+
if let error = error {
|
|
252
|
+
reject("EXPIRE_INBOX_MESSAGE_ERROR", error.localizedDescription, error)
|
|
253
|
+
} else {
|
|
254
|
+
if let message = message {
|
|
255
|
+
resolve(message.encodeJSON())
|
|
256
|
+
} else {
|
|
257
|
+
reject("EXPIRE_INBOX_MESSAGE_ERROR", "message encoding faild", "message encoding faild" as? Error)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
@objc
|
|
264
|
+
/// Inbox Message Opened
|
|
265
|
+
///
|
|
266
|
+
/// - Parameters:
|
|
267
|
+
/// - message: The Inbox Message
|
|
268
|
+
/// - resolve: promise resolver
|
|
269
|
+
/// - reject: promise rejector
|
|
270
|
+
func onInboxMessageOpen(_ message: VibesJSONDictionary,
|
|
271
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
272
|
+
reject: @escaping RCTPromiseRejectBlock ) -> Void {
|
|
273
|
+
guard let inboxMessage = InboxMessage(attributes: message) else {
|
|
274
|
+
reject("INBOX_MESSAGE_OPEN_ERROR", "Could not create Inbox Message from payload", nil)
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
vibes.onInboxMessageOpen(inboxMessage: inboxMessage)
|
|
278
|
+
resolve("success")
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@objc
|
|
282
|
+
/// Inbox Messages Fetched
|
|
283
|
+
///
|
|
284
|
+
/// - Parameters:
|
|
285
|
+
/// - resolve: promise resolver
|
|
286
|
+
/// - reject: promise rejector
|
|
287
|
+
func onInboxMessagesFetched(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
288
|
+
reject: @escaping RCTPromiseRejectBlock ) -> Void {
|
|
289
|
+
|
|
290
|
+
vibes.onInboxMessagesFetched()
|
|
291
|
+
resolve("Success recording an inbox_fetch event")
|
|
292
|
+
}
|
|
293
|
+
|
|
152
294
|
func didRegisterDevice(deviceId: String?, error: Error?) {
|
|
153
295
|
if let error = error {
|
|
154
296
|
if let registerDeviceRejecter = registerDeviceRejecter {
|
package/lib/commonjs/index.js
CHANGED
|
@@ -5,14 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.associatePerson = associatePerson;
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
exports.expireInboxMessage = expireInboxMessage;
|
|
9
|
+
exports.fetchInboxMessage = fetchInboxMessage;
|
|
10
|
+
exports.fetchInboxMessages = fetchInboxMessages;
|
|
11
|
+
exports.getPerson = getPerson;
|
|
8
12
|
exports.getVibesDeviceInfo = getVibesDeviceInfo;
|
|
13
|
+
exports.markInboxMessageAsRead = markInboxMessageAsRead;
|
|
14
|
+
exports.onInboxMessageOpen = onInboxMessageOpen;
|
|
15
|
+
exports.onInboxMessagesFetched = onInboxMessagesFetched;
|
|
9
16
|
exports.registerDevice = registerDevice;
|
|
10
17
|
exports.registerPush = registerPush;
|
|
11
18
|
exports.unregisterDevice = unregisterDevice;
|
|
19
|
+
exports.unregisterPush = unregisterPush;
|
|
12
20
|
exports.updateDevice = updateDevice;
|
|
13
|
-
|
|
14
21
|
var _reactNative = require("react-native");
|
|
15
|
-
|
|
16
22
|
const LINKING_ERROR = `The package 'vibes-react-native' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
17
23
|
ios: "- You have run 'pod install'\n",
|
|
18
24
|
default: ''
|
|
@@ -21,33 +27,137 @@ const Vibes = _reactNative.NativeModules.Vibes ? _reactNative.NativeModules.Vibe
|
|
|
21
27
|
get() {
|
|
22
28
|
throw new Error(LINKING_ERROR);
|
|
23
29
|
}
|
|
24
|
-
|
|
25
30
|
});
|
|
26
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Register this device with the Vibes platform
|
|
33
|
+
*
|
|
34
|
+
* @return {Promise<DeviceResponse>}
|
|
35
|
+
*/
|
|
27
36
|
function registerDevice() {
|
|
28
37
|
return Vibes.registerDevice();
|
|
29
38
|
}
|
|
30
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Unregister this device with the Vibes platform
|
|
41
|
+
*
|
|
42
|
+
* @return {Promise<void>}
|
|
43
|
+
*/
|
|
31
44
|
function unregisterDevice() {
|
|
32
45
|
return Vibes.unregisterDevice();
|
|
33
46
|
}
|
|
34
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Register this device to receive push notifications
|
|
50
|
+
*
|
|
51
|
+
* @return {Promise<void>}
|
|
52
|
+
*/
|
|
35
53
|
function registerPush() {
|
|
36
54
|
return Vibes.registerPush();
|
|
37
55
|
}
|
|
38
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Unregister the device from receiving push notifications
|
|
59
|
+
*
|
|
60
|
+
* @return {Promise<void>}
|
|
61
|
+
*/
|
|
62
|
+
function unregisterPush() {
|
|
63
|
+
return Vibes.registerPush();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Fetches a DeviceInfoResponse with details about the Vibes Device ID and Push Token
|
|
68
|
+
*
|
|
69
|
+
* @return {Promise<DeviceInfoResponse>}
|
|
70
|
+
*/
|
|
39
71
|
function getVibesDeviceInfo() {
|
|
40
72
|
return Vibes.getVibesDeviceInfo();
|
|
41
73
|
}
|
|
42
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Updates the Vibes platform with changes to the device since the last time device information was submitted.
|
|
77
|
+
*
|
|
78
|
+
* @param updateCredential - if true, the authentication token will be refreshed. Unless required, pass false here.
|
|
79
|
+
* @param latitude - if you collect geolocation information, then pass the latitude here. Otherwise, pass 0
|
|
80
|
+
* @param longitude - if you collect geolocation information, then pass the latitude here. Otherwise, pass 0
|
|
81
|
+
* @returns {Promise<void>}
|
|
82
|
+
*/
|
|
43
83
|
function updateDevice(updateCredential, latitude, longitude) {
|
|
44
84
|
return Vibes.updateDevice(updateCredential, latitude, longitude);
|
|
45
85
|
}
|
|
46
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Associate an external ID with the current person.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} externalPersonId
|
|
91
|
+
* @return {Promise<void>}
|
|
92
|
+
*/
|
|
47
93
|
function associatePerson(externalPersonId) {
|
|
48
94
|
return Vibes.associatePerson(externalPersonId);
|
|
49
95
|
}
|
|
50
96
|
|
|
51
|
-
|
|
52
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Fetches the PersonResponse associated with this device currently
|
|
99
|
+
*
|
|
100
|
+
* @return {Promise<PersonResponse>}
|
|
101
|
+
*/
|
|
102
|
+
function getPerson() {
|
|
103
|
+
return Vibes.getPerson();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Fetches an array of inbox messages for the person associated with this device.
|
|
107
|
+
*
|
|
108
|
+
* @return {Promise<InboxMessage[]>}
|
|
109
|
+
*/
|
|
110
|
+
function fetchInboxMessages() {
|
|
111
|
+
return Vibes.fetchInboxMessages();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Fetches a single inbox message by it's id.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} message_uid
|
|
118
|
+
* @return {Promise<InboxMessage>}
|
|
119
|
+
*/
|
|
120
|
+
function fetchInboxMessage(message_uid) {
|
|
121
|
+
return Vibes.fetchInboxMessage(message_uid);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Marks an inbox message as read.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} message_uid
|
|
128
|
+
* @return {Promise<InboxMessage>} an updated version of the InboxMessage with read field updated
|
|
129
|
+
*/
|
|
130
|
+
function markInboxMessageAsRead(message_uid) {
|
|
131
|
+
return Vibes.markInboxMessageAsRead(message_uid);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Marks an inbox message as expired using message_uid and the expiry date supplied. Uses current date as expiry date
|
|
136
|
+
*
|
|
137
|
+
* @param {string} message_uid
|
|
138
|
+
* @return {Promise<InboxMessage>} an updated version of the InboxMessage with expires_at date updated
|
|
139
|
+
*/
|
|
140
|
+
function expireInboxMessage(message_uid) {
|
|
141
|
+
return Vibes.expireInboxMessage(message_uid);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Records an event for when the user opens an inbox message.
|
|
146
|
+
*
|
|
147
|
+
* @param inboxMap json map of the InboxMessage
|
|
148
|
+
* @return {Promise<void>}
|
|
149
|
+
*/
|
|
150
|
+
function onInboxMessageOpen(inboxMap) {
|
|
151
|
+
return Vibes.onInboxMessageOpen(inboxMap);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Records an event for when the user fetches a list of inbox messages.
|
|
156
|
+
*
|
|
157
|
+
* @return {Promise<void>}
|
|
158
|
+
*/
|
|
159
|
+
function onInboxMessagesFetched() {
|
|
160
|
+
return Vibes.onInboxMessagesFetched();
|
|
161
|
+
}
|
|
162
|
+
var _default = exports.default = Vibes;
|
|
53
163
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","Vibes","NativeModules","Proxy","get","Error","registerDevice","unregisterDevice","registerPush","getVibesDeviceInfo","updateDevice","updateCredential","latitude","longitude","associatePerson","externalPersonId"],"sources":["index.tsx"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\n\nconst LINKING_ERROR =\n `The package 'vibes-react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst Vibes = NativeModules.Vibes\n ? NativeModules.Vibes\n : new Proxy(\n
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","Vibes","NativeModules","Proxy","get","Error","registerDevice","unregisterDevice","registerPush","unregisterPush","getVibesDeviceInfo","updateDevice","updateCredential","latitude","longitude","associatePerson","externalPersonId","getPerson","fetchInboxMessages","fetchInboxMessage","message_uid","markInboxMessageAsRead","expireInboxMessage","onInboxMessageOpen","inboxMap","onInboxMessagesFetched","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\n\nconst LINKING_ERROR =\n `The package 'vibes-react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst Vibes = NativeModules.Vibes\n ? NativeModules.Vibes\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nexport interface DeviceResponse {\n device_id?: string;\n}\nexport interface DeviceInfoResponse extends DeviceResponse {\n push_token?: string;\n}\n\nexport interface PersonResponse {\n person_key?: string;\n external_person_id?: string;\n}\n\nexport interface InboxMessage {\n content?: string;\n created_at?: string;\n expires_at?: string;\n message_uid?: string;\n read?: boolean;\n subject?: string;\n detail?: string;\n collapse_key?: string;\n apprefdata?: any;\n images?: any;\n inbox_custom_data: any;\n}\n\n/**\n * Register this device with the Vibes platform\n *\n * @return {Promise<DeviceResponse>}\n */\nexport function registerDevice(): Promise<DeviceResponse> {\n return Vibes.registerDevice();\n}\n/**\n * Unregister this device with the Vibes platform\n *\n * @return {Promise<void>}\n */\nexport function unregisterDevice(): Promise<void> {\n return Vibes.unregisterDevice();\n}\n\n/**\n * Register this device to receive push notifications\n *\n * @return {Promise<void>}\n */\nexport function registerPush(): Promise<void> {\n return Vibes.registerPush();\n}\n\n/**\n* Unregister the device from receiving push notifications\n*\n* @return {Promise<void>}\n*/\nexport function unregisterPush(): Promise<void> {\n return Vibes.registerPush();\n}\n\n/**\n * Fetches a DeviceInfoResponse with details about the Vibes Device ID and Push Token\n *\n * @return {Promise<DeviceInfoResponse>}\n */\nexport function getVibesDeviceInfo(): Promise<DeviceInfoResponse> {\n return Vibes.getVibesDeviceInfo();\n}\n\n/**\n * Updates the Vibes platform with changes to the device since the last time device information was submitted.\n *\n * @param updateCredential - if true, the authentication token will be refreshed. Unless required, pass false here.\n * @param latitude - if you collect geolocation information, then pass the latitude here. Otherwise, pass 0\n * @param longitude - if you collect geolocation information, then pass the latitude here. Otherwise, pass 0\n * @returns {Promise<void>}\n */\nexport function updateDevice(\n updateCredential: boolean,\n latitude: number,\n longitude: number\n): Promise<void> {\n return Vibes.updateDevice(updateCredential, latitude, longitude);\n}\n\n/**\n * Associate an external ID with the current person.\n *\n * @param {string} externalPersonId\n * @return {Promise<void>}\n */\nexport function associatePerson(externalPersonId: string): Promise<void> {\n return Vibes.associatePerson(externalPersonId);\n}\n\n/**\n * Fetches the PersonResponse associated with this device currently\n *\n * @return {Promise<PersonResponse>}\n */\nexport function getPerson(): Promise<PersonResponse> {\n return Vibes.getPerson();\n}\n/**\n * Fetches an array of inbox messages for the person associated with this device.\n *\n * @return {Promise<InboxMessage[]>}\n */\nexport function fetchInboxMessages(): Promise<InboxMessage[]> {\n return Vibes.fetchInboxMessages();\n}\n\n/**\n * Fetches a single inbox message by it's id.\n *\n * @param {string} message_uid\n * @return {Promise<InboxMessage>}\n */\nexport function fetchInboxMessage(message_uid: string): Promise<InboxMessage> {\n return Vibes.fetchInboxMessage(message_uid);\n}\n\n/**\n * Marks an inbox message as read.\n *\n * @param {string} message_uid\n * @return {Promise<InboxMessage>} an updated version of the InboxMessage with read field updated\n */\nexport function markInboxMessageAsRead(message_uid: string): Promise<InboxMessage> {\n return Vibes.markInboxMessageAsRead(message_uid);\n}\n\n/**\n * Marks an inbox message as expired using message_uid and the expiry date supplied. Uses current date as expiry date\n *\n * @param {string} message_uid\n * @return {Promise<InboxMessage>} an updated version of the InboxMessage with expires_at date updated\n */\nexport function expireInboxMessage(message_uid: string): Promise<InboxMessage> {\n return Vibes.expireInboxMessage(message_uid);\n}\n\n/**\n * Records an event for when the user opens an inbox message.\n *\n * @param inboxMap json map of the InboxMessage\n * @return {Promise<void>}\n */\nexport function onInboxMessageOpen(inboxMap: InboxMessage): Promise<void> {\n return Vibes.onInboxMessageOpen(inboxMap);\n}\n\n/**\n * Records an event for when the user fetches a list of inbox messages.\n *\n * @return {Promise<void>}\n */\nexport function onInboxMessagesFetched(): Promise<void> {\n return Vibes.onInboxMessagesFetched();\n}\n\nexport default Vibes;\n"],"mappings":"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"}
|