@trycourier/courier-react-native 5.2.2 → 5.3.0
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/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +46 -43
- package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +1 -1
- package/android/src/main/java/com/courierreactnative/Utils.kt +1 -1
- package/courier-react-native.podspec +1 -1
- package/ios/CourierReactNativeDelegate.m +2 -6
- package/ios/CourierReactNativeEventEmitter.swift +1 -1
- package/ios/CourierReactNativeModule.m +53 -19
- package/ios/CourierSharedModule.swift +298 -267
- package/ios/Utils.swift +3 -1
- package/lib/commonjs/Broadcaster.js +3 -1
- package/lib/commonjs/Broadcaster.js.map +1 -1
- package/lib/commonjs/index.js +52 -50
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierAuthenticationListener.js +2 -2
- package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +2 -2
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/module/Broadcaster.js +3 -1
- package/lib/module/Broadcaster.js.map +1 -1
- package/lib/module/index.js +52 -50
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierAuthenticationListener.js +2 -2
- package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +2 -2
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/typescript/src/Broadcaster.d.ts +1 -1
- package/lib/typescript/src/Broadcaster.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +21 -20
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierAuthenticationListener.d.ts +1 -1
- package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInboxListener.d.ts +1 -1
- package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Broadcaster.tsx +4 -1
- package/src/index.tsx +68 -62
- package/src/models/CourierAuthenticationListener.tsx +2 -2
- package/src/models/CourierInboxListener.tsx +2 -2
|
@@ -8,68 +8,90 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
8
8
|
private var inboxListeners: [String: CourierInboxListener] = [:]
|
|
9
9
|
|
|
10
10
|
override func stopObserving() {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
removeAuthListeners()
|
|
12
|
+
removeInboxListeners()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@objc(attachEmitter:withResolver:withRejecter:)
|
|
16
|
+
func attachEmitter(emitterId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
17
|
+
|
|
18
|
+
nativeEmitters.append(emitterId)
|
|
19
|
+
resolve(emitterId)
|
|
20
|
+
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
// MARK: Client
|
|
16
|
-
|
|
17
|
-
@objc
|
|
24
|
+
|
|
25
|
+
@objc(getClient:withRejecter:)
|
|
26
|
+
func getClient(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
return nil
|
|
21
|
-
}
|
|
28
|
+
Task {
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"jwt": options.jwt as Any,
|
|
27
|
-
"clientKey": options.clientKey as Any,
|
|
28
|
-
"userId": options.userId as Any,
|
|
29
|
-
"connectionId": options.connectionId as Any,
|
|
30
|
-
"tenantId": options.tenantId as Any,
|
|
31
|
-
"showLogs": options.showLogs as Any
|
|
32
|
-
]
|
|
33
|
-
.compactMapValues { $0 }
|
|
34
|
-
|
|
35
|
-
let jsonData = try JSONSerialization.data(
|
|
36
|
-
withJSONObject: dictionary,
|
|
37
|
-
options: .prettyPrinted
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
guard let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
41
|
-
return nil
|
|
30
|
+
guard let options = await Courier.shared.client?.options else {
|
|
31
|
+
resolve(nil)
|
|
32
|
+
return
|
|
42
33
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
|
|
35
|
+
do {
|
|
36
|
+
|
|
37
|
+
let dictionary = [
|
|
38
|
+
"jwt": options.jwt as Any,
|
|
39
|
+
"clientKey": options.clientKey as Any,
|
|
40
|
+
"userId": options.userId as Any,
|
|
41
|
+
"connectionId": options.connectionId as Any,
|
|
42
|
+
"tenantId": options.tenantId as Any,
|
|
43
|
+
"showLogs": options.showLogs as Any
|
|
44
|
+
]
|
|
45
|
+
.compactMapValues { $0 }
|
|
46
|
+
|
|
47
|
+
let jsonData = try JSONSerialization.data(
|
|
48
|
+
withJSONObject: dictionary,
|
|
49
|
+
options: .prettyPrinted
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
guard let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
53
|
+
resolve(nil)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
resolve(jsonString)
|
|
58
|
+
|
|
59
|
+
} catch {
|
|
60
|
+
resolve(nil)
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
// MARK: Authentication
|
|
53
68
|
|
|
54
|
-
@objc
|
|
55
|
-
|
|
69
|
+
@objc(getUserId:withRejecter:)
|
|
70
|
+
func getUserId(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
71
|
+
Task {
|
|
72
|
+
let userId = await Courier.shared.userId
|
|
73
|
+
resolve(userId)
|
|
74
|
+
}
|
|
56
75
|
}
|
|
57
76
|
|
|
58
|
-
@objc
|
|
59
|
-
|
|
77
|
+
@objc(getTenantId:withRejecter:)
|
|
78
|
+
func getTenantId(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
79
|
+
Task {
|
|
80
|
+
let tenantId = await Courier.shared.tenantId
|
|
81
|
+
resolve(tenantId)
|
|
82
|
+
}
|
|
60
83
|
}
|
|
61
84
|
|
|
62
|
-
@objc
|
|
63
|
-
|
|
85
|
+
@objc(getIsUserSignedIn:withRejecter:)
|
|
86
|
+
func getIsUserSignedIn(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
87
|
+
Task {
|
|
88
|
+
let isUserSignedIn = await String(Courier.shared.isUserSignedIn)
|
|
89
|
+
resolve(isUserSignedIn)
|
|
90
|
+
}
|
|
64
91
|
}
|
|
65
92
|
|
|
66
93
|
@objc(signIn:withClientKey:withUserId:withTenantId:withShowLogs:withResolver:withRejecter:)
|
|
67
|
-
func signIn(accessToken:
|
|
68
|
-
|
|
69
|
-
let userId = userId as String
|
|
70
|
-
let tenantId = tenantId as? String
|
|
71
|
-
let accessToken = accessToken as String
|
|
72
|
-
let clientKey = clientKey as? String
|
|
94
|
+
func signIn(accessToken: String, clientKey: String?, userId: String, tenantId: String?, showLogs: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
73
95
|
|
|
74
96
|
Task {
|
|
75
97
|
|
|
@@ -89,94 +111,91 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
89
111
|
|
|
90
112
|
@objc(signOut:withRejecter:)
|
|
91
113
|
func signOut(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
92
|
-
|
|
93
114
|
Task {
|
|
94
115
|
await Courier.shared.signOut()
|
|
95
116
|
resolve(nil)
|
|
96
117
|
}
|
|
97
|
-
|
|
98
118
|
}
|
|
99
119
|
|
|
100
|
-
@objc(addAuthenticationListener:)
|
|
101
|
-
func addAuthenticationListener(listenerId: String) ->
|
|
120
|
+
@objc(addAuthenticationListener:withResolver:withRejecter:)
|
|
121
|
+
func addAuthenticationListener(listenerId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
102
122
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
Task {
|
|
124
|
+
|
|
125
|
+
let listener = await Courier.shared.addAuthenticationListener { [weak self] userId in
|
|
126
|
+
self?.broadcast(
|
|
127
|
+
name: listenerId,
|
|
128
|
+
body: userId
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
authenticationListeners[listenerId] = listener
|
|
133
|
+
|
|
134
|
+
resolve(listenerId)
|
|
135
|
+
|
|
110
136
|
}
|
|
111
137
|
|
|
112
|
-
authenticationListeners[listenerId] = listener
|
|
113
|
-
|
|
114
|
-
return listenerId
|
|
115
|
-
|
|
116
138
|
}
|
|
117
139
|
|
|
118
|
-
@objc(removeAuthenticationListener:)
|
|
119
|
-
func removeAuthenticationListener(listenerId:
|
|
120
|
-
|
|
121
|
-
let id = listenerId as String
|
|
122
|
-
|
|
123
|
-
let listener = authenticationListeners[id]
|
|
140
|
+
@objc(removeAuthenticationListener:withResolver:withRejecter:)
|
|
141
|
+
func removeAuthenticationListener(listenerId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
124
142
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
Task {
|
|
144
|
+
|
|
145
|
+
let listener = authenticationListeners[listenerId]
|
|
146
|
+
|
|
147
|
+
// Disable the listener
|
|
148
|
+
listener?.remove()
|
|
149
|
+
|
|
150
|
+
// Remove the id from the map
|
|
151
|
+
authenticationListeners.removeValue(forKey: listenerId)
|
|
152
|
+
|
|
153
|
+
resolve(listenerId)
|
|
154
|
+
|
|
155
|
+
}
|
|
132
156
|
|
|
133
157
|
}
|
|
134
158
|
|
|
135
|
-
@
|
|
136
|
-
|
|
159
|
+
@objc(removeAllAuthenticationListeners:withRejecter:)
|
|
160
|
+
func removeAllAuthenticationListeners(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
161
|
+
Task {
|
|
162
|
+
removeAuthListeners()
|
|
163
|
+
resolve(nil)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private func removeAuthListeners() {
|
|
168
|
+
|
|
137
169
|
for value in authenticationListeners.values {
|
|
138
170
|
value.remove()
|
|
139
171
|
}
|
|
140
|
-
|
|
172
|
+
|
|
141
173
|
authenticationListeners.removeAll()
|
|
142
|
-
|
|
143
|
-
return nil
|
|
144
|
-
|
|
174
|
+
|
|
145
175
|
}
|
|
146
176
|
|
|
147
177
|
// MARK: Push
|
|
148
178
|
|
|
149
179
|
@objc(getAllTokens:withRejecter:)
|
|
150
180
|
func getAllTokens(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
151
|
-
|
|
152
181
|
Task {
|
|
153
|
-
|
|
154
182
|
let tokens = await Courier.shared.tokens
|
|
155
183
|
resolve(tokens)
|
|
156
|
-
|
|
157
184
|
}
|
|
158
|
-
|
|
159
185
|
}
|
|
160
186
|
|
|
161
187
|
@objc(getToken:withResolver:withRejecter:)
|
|
162
|
-
func getToken(provider:
|
|
163
|
-
|
|
164
|
-
let provider = provider as String
|
|
188
|
+
func getToken(provider: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
165
189
|
|
|
166
190
|
Task {
|
|
167
|
-
|
|
168
191
|
let token = await Courier.shared.getToken(for: provider)
|
|
169
192
|
resolve(token)
|
|
170
|
-
|
|
171
193
|
}
|
|
172
194
|
|
|
173
195
|
}
|
|
174
196
|
|
|
175
197
|
@objc(setToken:withToken:withResolver:withRejecter:)
|
|
176
|
-
func setToken(provider:
|
|
177
|
-
|
|
178
|
-
let provider = provider as String
|
|
179
|
-
let token = token as String
|
|
198
|
+
func setToken(provider: String, token: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
180
199
|
|
|
181
200
|
Task {
|
|
182
201
|
do {
|
|
@@ -194,24 +213,29 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
194
213
|
|
|
195
214
|
// MARK: Inbox
|
|
196
215
|
|
|
197
|
-
@objc
|
|
198
|
-
|
|
216
|
+
@objc(getInboxPaginationLimit:withRejecter:)
|
|
217
|
+
func getInboxPaginationLimit(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
218
|
+
Task {
|
|
219
|
+
let limit = await String(describing: Courier.shared.inboxPaginationLimit)
|
|
220
|
+
resolve(limit)
|
|
221
|
+
}
|
|
199
222
|
}
|
|
200
223
|
|
|
201
|
-
@objc(setInboxPaginationLimit:)
|
|
202
|
-
func setInboxPaginationLimit(limit: Double) ->
|
|
203
|
-
|
|
204
|
-
|
|
224
|
+
@objc(setInboxPaginationLimit:withResolver:withRejecter:)
|
|
225
|
+
func setInboxPaginationLimit(limit: Double, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
226
|
+
Task {
|
|
227
|
+
await Courier.shared.setPaginationLimit(Int(limit))
|
|
228
|
+
let limit = await String(describing: Courier.shared.inboxPaginationLimit)
|
|
229
|
+
resolve(limit)
|
|
230
|
+
}
|
|
205
231
|
}
|
|
206
232
|
|
|
207
233
|
@objc(openMessage:withResolver:withRejecter:)
|
|
208
|
-
func openMessage(messageId:
|
|
209
|
-
|
|
210
|
-
let id = messageId as String
|
|
234
|
+
func openMessage(messageId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
211
235
|
|
|
212
236
|
Task {
|
|
213
237
|
do {
|
|
214
|
-
try await Courier.shared.openMessage(
|
|
238
|
+
try await Courier.shared.openMessage(messageId)
|
|
215
239
|
resolve(nil)
|
|
216
240
|
} catch {
|
|
217
241
|
Rejections.sharedError(reject, error: error)
|
|
@@ -221,13 +245,11 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
221
245
|
}
|
|
222
246
|
|
|
223
247
|
@objc(archiveMessage:withResolver:withRejecter:)
|
|
224
|
-
func archiveMessage(messageId:
|
|
225
|
-
|
|
226
|
-
let id = messageId as String
|
|
248
|
+
func archiveMessage(messageId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
227
249
|
|
|
228
250
|
Task {
|
|
229
251
|
do {
|
|
230
|
-
try await Courier.shared.archiveMessage(
|
|
252
|
+
try await Courier.shared.archiveMessage(messageId)
|
|
231
253
|
resolve(nil)
|
|
232
254
|
} catch {
|
|
233
255
|
Rejections.sharedError(reject, error: error)
|
|
@@ -237,13 +259,11 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
237
259
|
}
|
|
238
260
|
|
|
239
261
|
@objc(clickMessage:withResolver:withRejecter:)
|
|
240
|
-
func clickMessage(messageId:
|
|
241
|
-
|
|
242
|
-
let id = messageId as String
|
|
262
|
+
func clickMessage(messageId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
243
263
|
|
|
244
264
|
Task {
|
|
245
265
|
do {
|
|
246
|
-
try await Courier.shared.clickMessage(
|
|
266
|
+
try await Courier.shared.clickMessage(messageId)
|
|
247
267
|
resolve(nil)
|
|
248
268
|
} catch {
|
|
249
269
|
Rejections.sharedError(reject, error: error)
|
|
@@ -253,13 +273,11 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
253
273
|
}
|
|
254
274
|
|
|
255
275
|
@objc(readMessage:withResolver:withRejecter:)
|
|
256
|
-
func readMessage(messageId:
|
|
257
|
-
|
|
258
|
-
let id = messageId as String
|
|
276
|
+
func readMessage(messageId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
259
277
|
|
|
260
278
|
Task {
|
|
261
279
|
do {
|
|
262
|
-
try await Courier.shared.readMessage(
|
|
280
|
+
try await Courier.shared.readMessage(messageId)
|
|
263
281
|
resolve(nil)
|
|
264
282
|
} catch {
|
|
265
283
|
Rejections.sharedError(reject, error: error)
|
|
@@ -269,13 +287,11 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
269
287
|
}
|
|
270
288
|
|
|
271
289
|
@objc(unreadMessage:withResolver:withRejecter:)
|
|
272
|
-
func unreadMessage(messageId:
|
|
273
|
-
|
|
274
|
-
let id = messageId as String
|
|
290
|
+
func unreadMessage(messageId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
275
291
|
|
|
276
292
|
Task {
|
|
277
293
|
do {
|
|
278
|
-
try await Courier.shared.unreadMessage(
|
|
294
|
+
try await Courier.shared.unreadMessage(messageId)
|
|
279
295
|
resolve(nil)
|
|
280
296
|
} catch {
|
|
281
297
|
Rejections.sharedError(reject, error: error)
|
|
@@ -298,182 +314,197 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
298
314
|
|
|
299
315
|
}
|
|
300
316
|
|
|
301
|
-
@objc(addInboxListener:withErrorId:withUnreadCountId:withFeedId:withArchiveId:withPageAddedId:withMessageChangedId:withMessageAddedId:withMessageRemovedId:)
|
|
302
|
-
func addInboxListener(loadingId: String, errorId: String, unreadCountId: String, feedId: String, archiveId: String, pageAddedId: String, messageChangedId: String, messageAddedId: String, messageRemovedId: String) ->
|
|
317
|
+
@objc(addInboxListener:withLoadingId:withErrorId:withUnreadCountId:withFeedId:withArchiveId:withPageAddedId:withMessageChangedId:withMessageAddedId:withMessageRemovedId:withResolver:withRejecter:)
|
|
318
|
+
func addInboxListener(listenerId: String, loadingId: String, errorId: String, unreadCountId: String, feedId: String, archiveId: String, pageAddedId: String, messageChangedId: String, messageAddedId: String, messageRemovedId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
303
319
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
320
|
+
Task {
|
|
321
|
+
|
|
322
|
+
// Create the new listener
|
|
323
|
+
let listener = await Courier.shared.addInboxListener(
|
|
324
|
+
onLoading: { [weak self] in
|
|
325
|
+
self?.broadcast(
|
|
326
|
+
name: loadingId,
|
|
327
|
+
body: nil
|
|
328
|
+
)
|
|
329
|
+
},
|
|
330
|
+
onError: { [weak self] error in
|
|
331
|
+
self?.broadcast(
|
|
332
|
+
name: errorId,
|
|
333
|
+
body: String(describing: error)
|
|
334
|
+
)
|
|
335
|
+
},
|
|
336
|
+
onUnreadCountChanged: { [weak self] unreadCount in
|
|
337
|
+
self?.broadcast(
|
|
338
|
+
name: unreadCountId,
|
|
339
|
+
body: unreadCount
|
|
340
|
+
)
|
|
341
|
+
},
|
|
342
|
+
onFeedChanged: { [weak self] set in
|
|
343
|
+
do {
|
|
344
|
+
let json: [String: Any] = [
|
|
345
|
+
"messages": try set.messages.map { try $0.toJson() ?? "" },
|
|
346
|
+
"totalMessageCount": set.totalCount,
|
|
347
|
+
"canPaginate": set.canPaginate
|
|
348
|
+
]
|
|
349
|
+
self?.broadcast(
|
|
350
|
+
name: feedId,
|
|
351
|
+
body: json
|
|
352
|
+
)
|
|
353
|
+
} catch {
|
|
354
|
+
Task {
|
|
355
|
+
await Courier.shared.client?.error(error.localizedDescription)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
onArchiveChanged: { [weak self] set in
|
|
360
|
+
do {
|
|
361
|
+
let json: [String: Any] = [
|
|
362
|
+
"messages": try set.messages.map { try $0.toJson() ?? "" },
|
|
363
|
+
"totalMessageCount": set.totalCount,
|
|
364
|
+
"canPaginate": set.canPaginate
|
|
365
|
+
]
|
|
366
|
+
self?.broadcast(
|
|
367
|
+
name: archiveId,
|
|
368
|
+
body: json
|
|
369
|
+
)
|
|
370
|
+
} catch {
|
|
371
|
+
Task {
|
|
372
|
+
await Courier.shared.client?.error(error.localizedDescription)
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
onPageAdded: { [weak self] feed, set in
|
|
377
|
+
do {
|
|
378
|
+
let json: [String: Any] = [
|
|
379
|
+
"feed": feed == .archived ? "archived" : "feed",
|
|
380
|
+
"messages": try set.messages.map { try $0.toJson() ?? "" },
|
|
381
|
+
"totalMessageCount": set.totalCount,
|
|
382
|
+
"canPaginate": set.canPaginate
|
|
383
|
+
]
|
|
384
|
+
self?.broadcast(
|
|
385
|
+
name: pageAddedId,
|
|
386
|
+
body: json
|
|
387
|
+
)
|
|
388
|
+
} catch {
|
|
389
|
+
Task {
|
|
390
|
+
await Courier.shared.client?.error(error.localizedDescription)
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
onMessageChanged: { [weak self] feed, index, message in
|
|
395
|
+
do {
|
|
396
|
+
let json: [String: Any] = [
|
|
397
|
+
"feed": feed == .archived ? "archived" : "feed",
|
|
398
|
+
"index": index,
|
|
399
|
+
"message": try message.toJson() ?? "",
|
|
400
|
+
]
|
|
401
|
+
self?.broadcast(
|
|
402
|
+
name: messageChangedId,
|
|
403
|
+
body: json
|
|
404
|
+
)
|
|
405
|
+
} catch {
|
|
406
|
+
Task {
|
|
407
|
+
await Courier.shared.client?.error(error.localizedDescription)
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
onMessageAdded: { [weak self] feed, index, message in
|
|
412
|
+
do {
|
|
413
|
+
let json: [String: Any] = [
|
|
414
|
+
"feed": feed == .archived ? "archived" : "feed",
|
|
415
|
+
"index": index,
|
|
416
|
+
"message": try message.toJson() ?? "",
|
|
417
|
+
]
|
|
418
|
+
self?.broadcast(
|
|
419
|
+
name: messageAddedId,
|
|
420
|
+
body: json
|
|
421
|
+
)
|
|
422
|
+
} catch {
|
|
423
|
+
Task {
|
|
424
|
+
await Courier.shared.client?.error(error.localizedDescription)
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
onMessageRemoved: { [weak self] feed, index, message in
|
|
429
|
+
do {
|
|
430
|
+
let json: [String: Any] = [
|
|
431
|
+
"feed": feed == .archived ? "archived" : "feed",
|
|
432
|
+
"index": index,
|
|
433
|
+
"message": try message.toJson() ?? "",
|
|
434
|
+
]
|
|
435
|
+
self?.broadcast(
|
|
436
|
+
name: messageRemovedId,
|
|
437
|
+
body: json
|
|
438
|
+
)
|
|
439
|
+
} catch {
|
|
440
|
+
Task {
|
|
441
|
+
await Courier.shared.client?.error(error.localizedDescription)
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
325
445
|
)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
"canPaginate": set.canPaginate
|
|
333
|
-
]
|
|
334
|
-
self?.broadcast(
|
|
335
|
-
name: feedId,
|
|
336
|
-
body: json
|
|
337
|
-
)
|
|
338
|
-
} catch {
|
|
339
|
-
Courier.shared.client?.error(error.localizedDescription)
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
onArchiveChanged: { [weak self] set in
|
|
343
|
-
do {
|
|
344
|
-
let json: [String: Any] = [
|
|
345
|
-
"messages": try set.messages.map { try $0.toJson() ?? "" },
|
|
346
|
-
"totalMessageCount": set.totalCount,
|
|
347
|
-
"canPaginate": set.canPaginate
|
|
348
|
-
]
|
|
349
|
-
self?.broadcast(
|
|
350
|
-
name: archiveId,
|
|
351
|
-
body: json
|
|
352
|
-
)
|
|
353
|
-
} catch {
|
|
354
|
-
Courier.shared.client?.error(error.localizedDescription)
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
onPageAdded: { [weak self] feed, set in
|
|
358
|
-
do {
|
|
359
|
-
let json: [String: Any] = [
|
|
360
|
-
"feed": feed == .archived ? "archived" : "feed",
|
|
361
|
-
"messages": try set.messages.map { try $0.toJson() ?? "" },
|
|
362
|
-
"totalMessageCount": set.totalCount,
|
|
363
|
-
"canPaginate": set.canPaginate
|
|
364
|
-
]
|
|
365
|
-
self?.broadcast(
|
|
366
|
-
name: pageAddedId,
|
|
367
|
-
body: json
|
|
368
|
-
)
|
|
369
|
-
} catch {
|
|
370
|
-
Courier.shared.client?.error(error.localizedDescription)
|
|
371
|
-
}
|
|
372
|
-
},
|
|
373
|
-
onMessageChanged: { [weak self] feed, index, message in
|
|
374
|
-
do {
|
|
375
|
-
let json: [String: Any] = [
|
|
376
|
-
"feed": feed == .archived ? "archived" : "feed",
|
|
377
|
-
"index": index,
|
|
378
|
-
"message": try message.toJson() ?? "",
|
|
379
|
-
]
|
|
380
|
-
self?.broadcast(
|
|
381
|
-
name: messageChangedId,
|
|
382
|
-
body: json
|
|
383
|
-
)
|
|
384
|
-
} catch {
|
|
385
|
-
Courier.shared.client?.error(error.localizedDescription)
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
onMessageAdded: { [weak self] feed, index, message in
|
|
389
|
-
do {
|
|
390
|
-
let json: [String: Any] = [
|
|
391
|
-
"feed": feed == .archived ? "archived" : "feed",
|
|
392
|
-
"index": index,
|
|
393
|
-
"message": try message.toJson() ?? "",
|
|
394
|
-
]
|
|
395
|
-
self?.broadcast(
|
|
396
|
-
name: messageAddedId,
|
|
397
|
-
body: json
|
|
398
|
-
)
|
|
399
|
-
} catch {
|
|
400
|
-
Courier.shared.client?.error(error.localizedDescription)
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
onMessageRemoved: { [weak self] feed, index, message in
|
|
404
|
-
do {
|
|
405
|
-
let json: [String: Any] = [
|
|
406
|
-
"feed": feed == .archived ? "archived" : "feed",
|
|
407
|
-
"index": index,
|
|
408
|
-
"message": try message.toJson() ?? "",
|
|
409
|
-
]
|
|
410
|
-
self?.broadcast(
|
|
411
|
-
name: messageRemovedId,
|
|
412
|
-
body: json
|
|
413
|
-
)
|
|
414
|
-
} catch {
|
|
415
|
-
Courier.shared.client?.error(error.localizedDescription)
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
)
|
|
419
|
-
|
|
420
|
-
let id = UUID().uuidString
|
|
421
|
-
inboxListeners[id] = listener
|
|
422
|
-
|
|
423
|
-
return id
|
|
446
|
+
|
|
447
|
+
inboxListeners[listenerId] = listener
|
|
448
|
+
|
|
449
|
+
resolve(listenerId)
|
|
450
|
+
|
|
451
|
+
}
|
|
424
452
|
|
|
425
453
|
}
|
|
426
454
|
|
|
427
|
-
@objc(removeInboxListener:)
|
|
428
|
-
func removeInboxListener(listenerId:
|
|
429
|
-
|
|
430
|
-
let id = listenerId as String
|
|
455
|
+
@objc(removeInboxListener:withResolver:withRejecter:)
|
|
456
|
+
func removeInboxListener(listenerId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
431
457
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
458
|
+
Task {
|
|
459
|
+
|
|
460
|
+
let listener = inboxListeners[listenerId]
|
|
461
|
+
|
|
462
|
+
// Disable the listener
|
|
463
|
+
listener?.remove()
|
|
464
|
+
|
|
465
|
+
// Remove the id from the map
|
|
466
|
+
inboxListeners.removeValue(forKey: listenerId)
|
|
467
|
+
|
|
468
|
+
resolve(listenerId)
|
|
469
|
+
|
|
470
|
+
}
|
|
441
471
|
|
|
442
472
|
}
|
|
443
473
|
|
|
444
|
-
@
|
|
445
|
-
|
|
474
|
+
@objc(removeAllInboxListeners:withRejecter:)
|
|
475
|
+
func removeAllInboxListeners(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
476
|
+
Task {
|
|
477
|
+
removeInboxListeners()
|
|
478
|
+
resolve(nil)
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
private func removeInboxListeners() {
|
|
446
483
|
for value in inboxListeners.values {
|
|
447
484
|
value.remove()
|
|
448
485
|
}
|
|
449
|
-
|
|
450
486
|
inboxListeners.removeAll()
|
|
451
|
-
|
|
452
|
-
return nil
|
|
453
|
-
|
|
454
487
|
}
|
|
455
488
|
|
|
456
489
|
@objc(refreshInbox: withRejecter:)
|
|
457
490
|
func refreshInbox(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
458
|
-
|
|
459
491
|
Task {
|
|
460
492
|
await Courier.shared.refreshInbox()
|
|
461
493
|
resolve(nil)
|
|
462
494
|
}
|
|
463
|
-
|
|
464
495
|
}
|
|
465
496
|
|
|
466
497
|
@objc(fetchNextPageOfMessages:withResolver:withRejecter:)
|
|
467
|
-
func fetchNextPageOfMessages(inboxMessageFeed:
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
498
|
+
func fetchNextPageOfMessages(inboxMessageFeed: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
499
|
+
Task {
|
|
500
|
+
do {
|
|
501
|
+
let value: InboxMessageFeed = inboxMessageFeed == "archived" ? .feed : .archived
|
|
502
|
+
let messages = try await Courier.shared.fetchNextInboxPage(value)
|
|
503
|
+
resolve(try messages.map { try $0.toJson() ?? "" })
|
|
504
|
+
} catch {
|
|
505
|
+
Rejections.sharedError(reject, error: error)
|
|
506
|
+
}
|
|
475
507
|
}
|
|
476
|
-
}
|
|
477
508
|
}
|
|
478
509
|
|
|
479
510
|
override func supportedEvents() -> [String]! {
|