@trycourier/courier-react-native 4.1.0 → 5.0.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/build.gradle +1 -1
- package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +131 -2
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +6 -4
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +71 -20
- package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +1 -2
- package/android/src/main/java/com/courierreactnative/Utils.kt +37 -144
- package/courier-react-native.podspec +1 -1
- package/ios/CourierInboxReactNativeManager.m +2 -0
- package/ios/CourierInboxReactNativeManager.swift +165 -0
- package/ios/CourierReactNativeDelegate.m +1 -1
- package/ios/CourierReactNativeEventEmitter.swift +1 -1
- package/ios/CourierReactNativeModule.m +9 -2
- package/ios/CourierSharedModule.swift +121 -50
- package/ios/Utils.swift +1 -2
- package/lib/commonjs/Modules.js +5 -0
- package/lib/commonjs/Modules.js.map +1 -1
- package/lib/commonjs/index.js +84 -22
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/commonjs/models/InboxMessageFeed.js +2 -0
- package/lib/commonjs/models/InboxMessageFeed.js.map +1 -0
- package/lib/commonjs/views/CourierInboxView.js +3 -8
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/commonjs/views/CourierPreferencesView.js +2 -8
- package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
- package/lib/module/Modules.js +6 -1
- package/lib/module/Modules.js.map +1 -1
- package/lib/module/index.js +84 -22
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/module/models/InboxMessageFeed.js +2 -0
- package/lib/module/models/InboxMessageFeed.js.map +1 -0
- package/lib/module/views/CourierInboxView.js +4 -9
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/module/views/CourierPreferencesView.js +3 -9
- package/lib/module/views/CourierPreferencesView.js.map +1 -1
- package/lib/typescript/src/Modules.d.ts +1 -0
- package/lib/typescript/src/Modules.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +20 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInboxListener.d.ts +7 -0
- package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInboxTheme.d.ts +27 -0
- package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxMessageFeed.d.ts +2 -0
- package/lib/typescript/src/models/InboxMessageFeed.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierInboxView.d.ts +1 -0
- package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -1
- package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Modules.tsx +9 -1
- package/src/index.tsx +100 -27
- package/src/models/CourierInboxListener.tsx +8 -1
- package/src/models/CourierInboxTheme.tsx +33 -0
- package/src/models/InboxMessageFeed.tsx +1 -0
- package/src/views/CourierInboxView.tsx +5 -15
- package/src/views/CourierPreferencesView.tsx +3 -15
|
@@ -14,6 +14,12 @@ class CourierInboxViewManager: RCTViewManager {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
class CourierInboxView : UIView {
|
|
17
|
+
|
|
18
|
+
@objc var canSwipePages: Bool = false {
|
|
19
|
+
didSet {
|
|
20
|
+
refresh()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
@objc var theme: NSDictionary? = [:] {
|
|
19
25
|
didSet {
|
|
@@ -39,6 +45,7 @@ class CourierInboxView : UIView {
|
|
|
39
45
|
let darkTheme = theme?["dark"] as? NSDictionary
|
|
40
46
|
|
|
41
47
|
let courierInbox = CourierInbox(
|
|
48
|
+
canSwipePages: self.canSwipePages,
|
|
42
49
|
lightTheme: lightTheme?.toInboxTheme() ?? .defaultLight,
|
|
43
50
|
darkTheme: darkTheme?.toInboxTheme() ?? .defaultDark,
|
|
44
51
|
didClickInboxMessageAtIndex: { [weak self] message, index in
|
|
@@ -85,10 +92,160 @@ class CourierInboxView : UIView {
|
|
|
85
92
|
UIView.setAnimationsEnabled(true)
|
|
86
93
|
|
|
87
94
|
}
|
|
95
|
+
|
|
96
|
+
internal static func defaultTabStyle() -> CourierStyles.Inbox.TabStyle {
|
|
97
|
+
return CourierStyles.Inbox.TabStyle(
|
|
98
|
+
selected: CourierStyles.Inbox.TabItemStyle(
|
|
99
|
+
font: CourierStyles.Font(
|
|
100
|
+
font: UIFont.boldSystemFont(ofSize: UIFont.labelFontSize),
|
|
101
|
+
color: .label
|
|
102
|
+
),
|
|
103
|
+
indicator: CourierStyles.Inbox.TabIndicatorStyle(
|
|
104
|
+
font: CourierStyles.Font(
|
|
105
|
+
font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize),
|
|
106
|
+
color: .white
|
|
107
|
+
),
|
|
108
|
+
color: .systemBlue
|
|
109
|
+
)
|
|
110
|
+
),
|
|
111
|
+
unselected: CourierStyles.Inbox.TabItemStyle(
|
|
112
|
+
font: CourierStyles.Font(
|
|
113
|
+
font: UIFont.boldSystemFont(ofSize: UIFont.labelFontSize),
|
|
114
|
+
color: .secondaryLabel
|
|
115
|
+
),
|
|
116
|
+
indicator: CourierStyles.Inbox.TabIndicatorStyle(
|
|
117
|
+
font: CourierStyles.Font(
|
|
118
|
+
font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize),
|
|
119
|
+
color: .label
|
|
120
|
+
),
|
|
121
|
+
color: .lightGray
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
internal static func defaultReadingStyle() -> CourierStyles.Inbox.ReadingSwipeActionStyle {
|
|
128
|
+
return CourierStyles.Inbox.ReadingSwipeActionStyle(
|
|
129
|
+
read: CourierStyles.Inbox.SwipeActionStyle(
|
|
130
|
+
icon: UIImage(systemName: "envelope.fill"),
|
|
131
|
+
color: .systemGray
|
|
132
|
+
),
|
|
133
|
+
unread: CourierStyles.Inbox.SwipeActionStyle(
|
|
134
|
+
icon: UIImage(systemName: "envelope.open.fill"),
|
|
135
|
+
color: .systemBlue
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
internal static func defaultArchivingStyle() -> CourierStyles.Inbox.ArchivingSwipeActionStyle {
|
|
141
|
+
return CourierStyles.Inbox.ArchivingSwipeActionStyle(
|
|
142
|
+
archive: CourierStyles.Inbox.SwipeActionStyle(
|
|
143
|
+
icon: UIImage(systemName: "archivebox.fill"),
|
|
144
|
+
color: .systemRed
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
}
|
|
88
148
|
|
|
89
149
|
}
|
|
90
150
|
|
|
91
151
|
internal extension NSDictionary {
|
|
152
|
+
|
|
153
|
+
func toTabStyle() -> CourierStyles.Inbox.TabStyle? {
|
|
154
|
+
|
|
155
|
+
guard let selectedDict = self["selected"] as? NSDictionary, let unselectedDict = self["unselected"] as? NSDictionary else {
|
|
156
|
+
return nil
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
guard let selected = selectedDict.toTabItemStyle(), let unselected = unselectedDict.toTabItemStyle() else {
|
|
160
|
+
return nil
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return CourierStyles.Inbox.TabStyle(
|
|
164
|
+
selected: selected,
|
|
165
|
+
unselected: unselected
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
func toTabItemStyle() -> CourierStyles.Inbox.TabItemStyle? {
|
|
171
|
+
|
|
172
|
+
guard let fontDict = self["font"] as? NSDictionary, let indicatorDict = self["indicator"] as? NSDictionary else {
|
|
173
|
+
return nil
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let font = fontDict.toFont()
|
|
177
|
+
guard let indicator = indicatorDict.toTabIndicatorStyle() else {
|
|
178
|
+
return nil
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return CourierStyles.Inbox.TabItemStyle(font: font, indicator: indicator)
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
func toTabIndicatorStyle() -> CourierStyles.Inbox.TabIndicatorStyle? {
|
|
186
|
+
|
|
187
|
+
guard let fontDict = self["font"] as? NSDictionary, let colorString = self["color"] as? String else {
|
|
188
|
+
return nil
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let font = fontDict.toFont()
|
|
192
|
+
guard let color = colorString.toColor() else {
|
|
193
|
+
return nil
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return CourierStyles.Inbox.TabIndicatorStyle(
|
|
197
|
+
font: font,
|
|
198
|
+
color: color
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
func toReadingSwipeActionStyle() -> CourierStyles.Inbox.ReadingSwipeActionStyle? {
|
|
204
|
+
|
|
205
|
+
guard let readDict = self["read"] as? NSDictionary, let unreadDict = self["unread"] as? NSDictionary else {
|
|
206
|
+
return nil
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
guard let read = readDict.toSwipeActionStyle(), let unread = unreadDict.toSwipeActionStyle() else {
|
|
210
|
+
return nil
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return CourierStyles.Inbox.ReadingSwipeActionStyle(
|
|
214
|
+
read: read,
|
|
215
|
+
unread: unread
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
func toArchivingSwipeActionStyle() -> CourierStyles.Inbox.ArchivingSwipeActionStyle? {
|
|
221
|
+
|
|
222
|
+
// TODO: Icon
|
|
223
|
+
|
|
224
|
+
guard let archiveDict = self["archive"] as? NSDictionary else {
|
|
225
|
+
return nil
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
guard let archive = archiveDict.toSwipeActionStyle() else {
|
|
229
|
+
return nil
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return CourierStyles.Inbox.ArchivingSwipeActionStyle(archive: archive)
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
func toSwipeActionStyle() -> CourierStyles.Inbox.SwipeActionStyle? {
|
|
237
|
+
|
|
238
|
+
// TODO: Icon
|
|
239
|
+
|
|
240
|
+
guard let colorString = self["color"] as? String else {
|
|
241
|
+
return nil
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
let color = colorString.toColor() ?? .systemBlue
|
|
245
|
+
|
|
246
|
+
return CourierStyles.Inbox.SwipeActionStyle(icon: nil, color: color)
|
|
247
|
+
|
|
248
|
+
}
|
|
92
249
|
|
|
93
250
|
func toUnreadIndicatorStyle() -> CourierStyles.Inbox.UnreadIndicatorStyle {
|
|
94
251
|
|
|
@@ -137,6 +294,10 @@ internal extension NSDictionary {
|
|
|
137
294
|
let defaultTheme = CourierInboxTheme()
|
|
138
295
|
|
|
139
296
|
let brandId = self["brandId"] as? String
|
|
297
|
+
let tabIndicatorColor = self["tabIndicatorColor"] as? String
|
|
298
|
+
let tabStyle = self["tabStyle"] as? NSDictionary
|
|
299
|
+
let readingSwipeActionStyle = self["readingSwipeActionStyle"] as? NSDictionary
|
|
300
|
+
let archivingSwipeActionStyle = self["archivingSwipeActionStyle"] as? NSDictionary
|
|
140
301
|
let unreadIndicatorStyle = self["unreadIndicatorStyle"] as? NSDictionary
|
|
141
302
|
let loadingIndicatorColor = self["loadingIndicatorColor"] as? String
|
|
142
303
|
let titleStyle = self["titleStyle"] as? NSDictionary
|
|
@@ -151,6 +312,10 @@ internal extension NSDictionary {
|
|
|
151
312
|
|
|
152
313
|
return CourierInboxTheme(
|
|
153
314
|
brandId: brandId,
|
|
315
|
+
tabIndicatorColor: tabIndicatorColor?.toColor(),
|
|
316
|
+
tabStyle: tabStyle?.toTabStyle() ?? CourierInboxView.defaultTabStyle(),
|
|
317
|
+
readingSwipeActionStyle: readingSwipeActionStyle?.toReadingSwipeActionStyle() ?? CourierInboxView.defaultReadingStyle(),
|
|
318
|
+
archivingSwipeActionStyle: archivingSwipeActionStyle?.toArchivingSwipeActionStyle() ?? CourierInboxView.defaultArchivingStyle(),
|
|
154
319
|
messageAnimationStyle: messageAnimationStyle?.toRowAnimation() ?? .left,
|
|
155
320
|
loadingIndicatorColor: loadingIndicatorColor?.toColor(),
|
|
156
321
|
unreadIndicatorStyle: unreadIndicatorStyle?.toUnreadIndicatorStyle() ?? defaultTheme.unreadIndicatorStyle,
|
|
@@ -22,7 +22,7 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
|
|
|
22
22
|
if (self) {
|
|
23
23
|
|
|
24
24
|
// Set the user agent
|
|
25
|
-
Courier.agent = [CourierAgent reactNativeIOS:@"
|
|
25
|
+
Courier.agent = [CourierAgent reactNativeIOS:@"5.0.0"];
|
|
26
26
|
|
|
27
27
|
// Register for remote notifications
|
|
28
28
|
UIApplication *app = [UIApplication sharedApplication];
|
|
@@ -14,7 +14,7 @@ internal class CourierReactNativeEventEmitter: RCTEventEmitter {
|
|
|
14
14
|
|
|
15
15
|
// Set the user agent
|
|
16
16
|
// Used to know the platform performing requests
|
|
17
|
-
Courier.agent = CourierAgent.reactNativeIOS("
|
|
17
|
+
Courier.agent = CourierAgent.reactNativeIOS("5.0.0")
|
|
18
18
|
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -109,7 +109,13 @@ RCT_EXTERN_METHOD(
|
|
|
109
109
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
110
110
|
addInboxListener: (NSString*)loadingId
|
|
111
111
|
withErrorId: (NSString*)errorId
|
|
112
|
-
|
|
112
|
+
withUnreadCountId: (NSString*)unreadCountId
|
|
113
|
+
withFeedId: (NSString*)feedId
|
|
114
|
+
withArchiveId: (NSString*)archiveId
|
|
115
|
+
withPageAddedId: (NSString*)pageAddedId
|
|
116
|
+
withMessageChangedId: (NSString*)messageChangedId
|
|
117
|
+
withMessageAddedId: (NSString*)messageAddedId
|
|
118
|
+
withMessageRemovedId: (NSString*)messageRemovedId
|
|
113
119
|
)
|
|
114
120
|
|
|
115
121
|
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
@@ -126,7 +132,8 @@ RCT_EXTERN_METHOD(
|
|
|
126
132
|
)
|
|
127
133
|
|
|
128
134
|
RCT_EXTERN_METHOD(
|
|
129
|
-
fetchNextPageOfMessages: (
|
|
135
|
+
fetchNextPageOfMessages: (NSString*)inboxMessageFeed
|
|
136
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
130
137
|
withRejecter: (RCTPromiseRejectBlock)reject
|
|
131
138
|
)
|
|
132
139
|
|
|
@@ -298,49 +298,123 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
298
298
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
@objc(addInboxListener:
|
|
302
|
-
func addInboxListener(loadingId: String, errorId: String,
|
|
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) -> String {
|
|
303
303
|
|
|
304
304
|
// Add the events
|
|
305
|
-
nativeEmitters.append(contentsOf: [loadingId, errorId,
|
|
305
|
+
nativeEmitters.append(contentsOf: [loadingId, errorId, unreadCountId, feedId, archiveId, pageAddedId, messageChangedId, messageAddedId, messageRemovedId])
|
|
306
306
|
|
|
307
307
|
// Create the new listener
|
|
308
308
|
let listener = Courier.shared.addInboxListener(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
309
|
+
onLoading: { [weak self] in
|
|
310
|
+
self?.broadcast(
|
|
311
|
+
name: loadingId,
|
|
312
|
+
body: nil
|
|
313
|
+
)
|
|
314
|
+
},
|
|
315
|
+
onError: { [weak self] error in
|
|
316
|
+
self?.broadcast(
|
|
317
|
+
name: errorId,
|
|
318
|
+
body: String(describing: error)
|
|
319
|
+
)
|
|
320
|
+
},
|
|
321
|
+
onUnreadCountChanged: { [weak self] unreadCount in
|
|
322
|
+
self?.broadcast(
|
|
323
|
+
name: unreadCountId,
|
|
324
|
+
body: unreadCount
|
|
325
|
+
)
|
|
326
|
+
},
|
|
327
|
+
onFeedChanged: { [weak self] set in
|
|
328
|
+
do {
|
|
329
|
+
let json: [String: Any] = [
|
|
330
|
+
"messages": try set.messages.map { try $0.toJson() ?? "" },
|
|
331
|
+
"totalMessageCount": set.totalCount,
|
|
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)
|
|
343
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
|
+
}
|
|
344
418
|
)
|
|
345
419
|
|
|
346
420
|
let id = UUID().uuidString
|
|
@@ -389,20 +463,17 @@ class CourierSharedModule: CourierReactNativeEventEmitter {
|
|
|
389
463
|
|
|
390
464
|
}
|
|
391
465
|
|
|
392
|
-
@objc(fetchNextPageOfMessages:
|
|
393
|
-
func fetchNextPageOfMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
Rejections.sharedError(reject, error: error)
|
|
402
|
-
}
|
|
403
|
-
|
|
466
|
+
@objc(fetchNextPageOfMessages:withResolver:withRejecter:)
|
|
467
|
+
func fetchNextPageOfMessages(inboxMessageFeed: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
468
|
+
Task {
|
|
469
|
+
do {
|
|
470
|
+
let value: InboxMessageFeed = inboxMessageFeed == "archived" ? .feed : .archived
|
|
471
|
+
let messages = try await Courier.shared.fetchNextInboxPage(value)
|
|
472
|
+
resolve(try messages.map { try $0.toJson() ?? "" })
|
|
473
|
+
} catch {
|
|
474
|
+
Rejections.sharedError(reject, error: error)
|
|
404
475
|
}
|
|
405
|
-
|
|
476
|
+
}
|
|
406
477
|
}
|
|
407
478
|
|
|
408
479
|
override func supportedEvents() -> [String]! {
|
package/ios/Utils.swift
CHANGED
|
@@ -51,7 +51,6 @@ internal extension String {
|
|
|
51
51
|
switch self.lowercased() {
|
|
52
52
|
case "none": return .none
|
|
53
53
|
case "singleLine": return .singleLine
|
|
54
|
-
case "singleLineEtched": return .singleLineEtched
|
|
55
54
|
default: return .singleLine
|
|
56
55
|
}
|
|
57
56
|
|
|
@@ -60,7 +59,7 @@ internal extension String {
|
|
|
60
59
|
func toSelectionStyle() -> UITableViewCell.SelectionStyle? {
|
|
61
60
|
|
|
62
61
|
switch self.lowercased() {
|
|
63
|
-
case "none": return .none
|
|
62
|
+
case "none": return UITableViewCell.SelectionStyle.none
|
|
64
63
|
case "blue": return .blue
|
|
65
64
|
case "gray": return .gray
|
|
66
65
|
case "default": return .default
|
package/lib/commonjs/Modules.js
CHANGED
|
@@ -20,6 +20,11 @@ class Modules {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
static getNativeComponent(componentName) {
|
|
24
|
+
return _reactNative.UIManager.getViewManagerConfig(componentName) != null ? (0, _reactNative.requireNativeComponent)(componentName) : () => {
|
|
25
|
+
throw new Error(Modules.LINKING_ERROR);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
29
|
exports.Modules = Modules;
|
|
25
30
|
//# sourceMappingURL=Modules.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","Modules","LINKING_ERROR","Platform","select","ios","default","Client","getNativeModule","NativeModules","CourierClientModule","Shared","CourierSharedModule","System","CourierSystemModule","nativeModule","Proxy","get","Error","exports"],"sourceRoot":"../../src","sources":["Modules.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,OAAO,CAAC;EAEnB,OAAgBC,aAAa,GAC7B,2FAA2F,GAC3FC,qBAAQ,CAACC,MAAM,CAAC;IAAEC,GAAG,EAAE,gCAAgC;IAAEC,OAAO,EAAE;EAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;EAE/B,OAAgBC,MAAM,GAAGN,OAAO,CAACO,eAAe,CAACC,0BAAa,CAACC,mBAAmB,CAAC;EACnF,OAAgBC,MAAM,GAAGV,OAAO,CAACO,eAAe,CAACC,0BAAa,CAACG,mBAAmB,CAAC;EACnF,OAAgBC,MAAM,GAAGZ,OAAO,CAACO,eAAe,CAACC,0BAAa,CAACK,mBAAmB,CAAC;EAEnF,OAAON,eAAeA,CAAIO,YAA2B,EAAK;IACxD,OAAOA,YAAY,GACfA,YAAY,GACZ,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIC,KAAK,CAACjB,OAAO,CAACC,aAAa,CAAC;MACxC;IACF,CACF,CAAM;EACZ;AAEF;
|
|
1
|
+
{"version":3,"names":["_reactNative","require","Modules","LINKING_ERROR","Platform","select","ios","default","Client","getNativeModule","NativeModules","CourierClientModule","Shared","CourierSharedModule","System","CourierSystemModule","nativeModule","Proxy","get","Error","getNativeComponent","componentName","UIManager","getViewManagerConfig","requireNativeComponent","exports"],"sourceRoot":"../../src","sources":["Modules.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,OAAO,CAAC;EAEnB,OAAgBC,aAAa,GAC7B,2FAA2F,GAC3FC,qBAAQ,CAACC,MAAM,CAAC;IAAEC,GAAG,EAAE,gCAAgC;IAAEC,OAAO,EAAE;EAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;EAE/B,OAAgBC,MAAM,GAAGN,OAAO,CAACO,eAAe,CAACC,0BAAa,CAACC,mBAAmB,CAAC;EACnF,OAAgBC,MAAM,GAAGV,OAAO,CAACO,eAAe,CAACC,0BAAa,CAACG,mBAAmB,CAAC;EACnF,OAAgBC,MAAM,GAAGZ,OAAO,CAACO,eAAe,CAACC,0BAAa,CAACK,mBAAmB,CAAC;EAEnF,OAAON,eAAeA,CAAIO,YAA2B,EAAK;IACxD,OAAOA,YAAY,GACfA,YAAY,GACZ,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIC,KAAK,CAACjB,OAAO,CAACC,aAAa,CAAC;MACxC;IACF,CACF,CAAM;EACZ;EAEA,OAAOiB,kBAAkBA,CAACC,aAAqB,EAAE;IAC/C,OAAOC,sBAAS,CAACC,oBAAoB,CAACF,aAAa,CAAC,IAAI,IAAI,GACxD,IAAAG,mCAAsB,EAAMH,aAAa,CAAC,GAC1C,MAAM;MACJ,MAAM,IAAIF,KAAK,CAACjB,OAAO,CAACC,aAAa,CAAC;IACxC,CAAC;EACP;AAEF;AAACsB,OAAA,CAAAvB,OAAA,GAAAA,OAAA","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -617,18 +617,30 @@ class Courier {
|
|
|
617
617
|
* @param {Object} props - The properties object.
|
|
618
618
|
* @param {Function} [props.onInitialLoad] - Callback function called when the inbox is initially loaded.
|
|
619
619
|
* @param {Function} [props.onError] - Callback function called when an error occurs. Receives the error message as a parameter.
|
|
620
|
-
* @param {Function} [props.
|
|
620
|
+
* @param {Function} [props.onUnreadCountChanged] - Callback function called when the unread count changes.
|
|
621
|
+
* @param {Function} [props.onFeedChanged] - Callback function called when the feed changes.
|
|
622
|
+
* @param {Function} [props.onArchiveChanged] - Callback function called when the archive changes.
|
|
623
|
+
* @param {Function} [props.onPageAdded] - Callback function called when a new page is added.
|
|
624
|
+
* @param {Function} [props.onMessageChanged] - Callback function called when a message changes.
|
|
625
|
+
* @param {Function} [props.onMessageAdded] - Callback function called when a new message is added.
|
|
626
|
+
* @param {Function} [props.onMessageRemoved] - Callback function called when a message is removed.
|
|
621
627
|
* @returns {CourierInboxListener} A listener object that can be used to remove the listener later.
|
|
622
628
|
*/
|
|
623
629
|
addInboxListener(props) {
|
|
624
630
|
const listenerIds = {
|
|
625
631
|
loading: `inbox_loading_${_utils.Utils.generateUUID()}`,
|
|
626
632
|
error: `inbox_error_${_utils.Utils.generateUUID()}`,
|
|
627
|
-
|
|
633
|
+
unreadCount: `inbox_unread_count_${_utils.Utils.generateUUID()}`,
|
|
634
|
+
feed: `inbox_feed_${_utils.Utils.generateUUID()}`,
|
|
635
|
+
archive: `inbox_archive_${_utils.Utils.generateUUID()}`,
|
|
636
|
+
pageAdded: `inbox_page_added_${_utils.Utils.generateUUID()}`,
|
|
637
|
+
messageChanged: `inbox_message_changed_${_utils.Utils.generateUUID()}`,
|
|
638
|
+
messageAdded: `inbox_message_added_${_utils.Utils.generateUUID()}`,
|
|
639
|
+
messageRemoved: `inbox_message_removed_${_utils.Utils.generateUUID()}`
|
|
628
640
|
};
|
|
629
641
|
|
|
630
642
|
// Set the listener id
|
|
631
|
-
const id = _Modules.Modules.Shared.addInboxListener(listenerIds.loading, listenerIds.error, listenerIds.
|
|
643
|
+
const id = _Modules.Modules.Shared.addInboxListener(listenerIds.loading, listenerIds.error, listenerIds.unreadCount, listenerIds.feed, listenerIds.archive, listenerIds.pageAdded, listenerIds.messageChanged, listenerIds.messageAdded, listenerIds.messageRemoved);
|
|
632
644
|
|
|
633
645
|
// Create the initial listeners
|
|
634
646
|
const listener = new _CourierInboxListener.CourierInboxListener(id);
|
|
@@ -640,25 +652,63 @@ class Courier {
|
|
|
640
652
|
var _props$onError;
|
|
641
653
|
(_props$onError = props.onError) === null || _props$onError === void 0 ? void 0 : _props$onError.call(props, event);
|
|
642
654
|
});
|
|
643
|
-
listener.
|
|
644
|
-
var _props$
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
(_props$
|
|
655
|
+
listener.onUnreadCountChanged = this.sharedBroadcaster.addListener(listenerIds.unreadCount, event => {
|
|
656
|
+
var _props$onUnreadCountC;
|
|
657
|
+
(_props$onUnreadCountC = props.onUnreadCountChanged) === null || _props$onUnreadCountC === void 0 ? void 0 : _props$onUnreadCountC.call(props, event);
|
|
658
|
+
});
|
|
659
|
+
listener.onFeedChanged = this.sharedBroadcaster.addListener(listenerIds.feed, event => {
|
|
660
|
+
var _props$onFeedChanged;
|
|
661
|
+
const convertedMessages = this.convertMessages(event.messages);
|
|
662
|
+
(_props$onFeedChanged = props.onFeedChanged) === null || _props$onFeedChanged === void 0 ? void 0 : _props$onFeedChanged.call(props, convertedMessages, event.totalMessageCount, event.canPaginate);
|
|
663
|
+
});
|
|
664
|
+
listener.onArchiveChanged = this.sharedBroadcaster.addListener(listenerIds.archive, event => {
|
|
665
|
+
var _props$onArchiveChang;
|
|
666
|
+
const convertedMessages = this.convertMessages(event.messages);
|
|
667
|
+
(_props$onArchiveChang = props.onArchiveChanged) === null || _props$onArchiveChang === void 0 ? void 0 : _props$onArchiveChang.call(props, convertedMessages, event.totalMessageCount, event.canPaginate);
|
|
668
|
+
});
|
|
669
|
+
listener.onPageAdded = this.sharedBroadcaster.addListener(listenerIds.pageAdded, event => {
|
|
670
|
+
var _props$onPageAdded;
|
|
671
|
+
const convertedMessages = this.convertMessages(event.messages);
|
|
672
|
+
(_props$onPageAdded = props.onPageAdded) === null || _props$onPageAdded === void 0 ? void 0 : _props$onPageAdded.call(props, event.feed === 'archived' ? 'archived' : 'feed', convertedMessages, event.totalMessageCount, event.canPaginate);
|
|
673
|
+
});
|
|
674
|
+
listener.onMessageChanged = this.sharedBroadcaster.addListener(listenerIds.messageChanged, event => {
|
|
675
|
+
var _props$onMessageChang;
|
|
676
|
+
const convertedMessage = this.convertMessage(event.message);
|
|
677
|
+
(_props$onMessageChang = props.onMessageChanged) === null || _props$onMessageChang === void 0 ? void 0 : _props$onMessageChang.call(props, event.feed === 'archived' ? 'archived' : 'feed', event.index, convertedMessage);
|
|
678
|
+
});
|
|
679
|
+
listener.onMessageAdded = this.sharedBroadcaster.addListener(listenerIds.messageAdded, event => {
|
|
680
|
+
var _props$onMessageAdded;
|
|
681
|
+
const convertedMessage = this.convertMessage(event.message);
|
|
682
|
+
(_props$onMessageAdded = props.onMessageAdded) === null || _props$onMessageAdded === void 0 ? void 0 : _props$onMessageAdded.call(props, event.feed === 'archived' ? 'archived' : 'feed', event.index, convertedMessage);
|
|
683
|
+
});
|
|
684
|
+
listener.onMessageRemoved = this.sharedBroadcaster.addListener(listenerIds.messageRemoved, event => {
|
|
685
|
+
var _props$onMessageRemov;
|
|
686
|
+
const convertedMessage = this.convertMessage(event.message);
|
|
687
|
+
(_props$onMessageRemov = props.onMessageRemoved) === null || _props$onMessageRemov === void 0 ? void 0 : _props$onMessageRemov.call(props, event.feed === 'archived' ? 'archived' : 'feed', event.index, convertedMessage);
|
|
656
688
|
});
|
|
657
689
|
|
|
658
690
|
// Add listener to manager
|
|
659
691
|
this.inboxListeners.set(id, listener);
|
|
660
692
|
return listener;
|
|
661
693
|
}
|
|
694
|
+
convertMessages(messages) {
|
|
695
|
+
return messages.map(jsonString => {
|
|
696
|
+
try {
|
|
697
|
+
return JSON.parse(jsonString);
|
|
698
|
+
} catch (error) {
|
|
699
|
+
Courier.log(`Error parsing message: ${error}`);
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
}).filter(message => message !== null);
|
|
703
|
+
}
|
|
704
|
+
convertMessage(message) {
|
|
705
|
+
try {
|
|
706
|
+
return JSON.parse(message);
|
|
707
|
+
} catch (error) {
|
|
708
|
+
Courier.log(`Error parsing message: ${error}`);
|
|
709
|
+
throw error;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
662
712
|
|
|
663
713
|
/**
|
|
664
714
|
* Removes a specific inbox listener.
|
|
@@ -672,12 +722,18 @@ class Courier {
|
|
|
672
722
|
|
|
673
723
|
// Remove the listener
|
|
674
724
|
if (this.inboxListeners.has(props.listenerId)) {
|
|
675
|
-
var _listener$onInitialLo, _listener$onError, _listener$
|
|
725
|
+
var _listener$onInitialLo, _listener$onError, _listener$onUnreadCou, _listener$onFeedChang, _listener$onArchiveCh, _listener$onPageAdded, _listener$onMessageCh, _listener$onMessageAd, _listener$onMessageRe;
|
|
676
726
|
// Remove emitters
|
|
677
727
|
const listener = this.inboxListeners.get(props.listenerId);
|
|
678
728
|
listener === null || listener === void 0 || (_listener$onInitialLo = listener.onInitialLoad) === null || _listener$onInitialLo === void 0 ? void 0 : _listener$onInitialLo.remove();
|
|
679
729
|
listener === null || listener === void 0 || (_listener$onError = listener.onError) === null || _listener$onError === void 0 ? void 0 : _listener$onError.remove();
|
|
680
|
-
listener === null || listener === void 0 || (_listener$
|
|
730
|
+
listener === null || listener === void 0 || (_listener$onUnreadCou = listener.onUnreadCountChanged) === null || _listener$onUnreadCou === void 0 ? void 0 : _listener$onUnreadCou.remove();
|
|
731
|
+
listener === null || listener === void 0 || (_listener$onFeedChang = listener.onFeedChanged) === null || _listener$onFeedChang === void 0 ? void 0 : _listener$onFeedChang.remove();
|
|
732
|
+
listener === null || listener === void 0 || (_listener$onArchiveCh = listener.onArchiveChanged) === null || _listener$onArchiveCh === void 0 ? void 0 : _listener$onArchiveCh.remove();
|
|
733
|
+
listener === null || listener === void 0 || (_listener$onPageAdded = listener.onPageAdded) === null || _listener$onPageAdded === void 0 ? void 0 : _listener$onPageAdded.remove();
|
|
734
|
+
listener === null || listener === void 0 || (_listener$onMessageCh = listener.onMessageChanged) === null || _listener$onMessageCh === void 0 ? void 0 : _listener$onMessageCh.remove();
|
|
735
|
+
listener === null || listener === void 0 || (_listener$onMessageAd = listener.onMessageAdded) === null || _listener$onMessageAd === void 0 ? void 0 : _listener$onMessageAd.remove();
|
|
736
|
+
listener === null || listener === void 0 || (_listener$onMessageRe = listener.onMessageRemoved) === null || _listener$onMessageRe === void 0 ? void 0 : _listener$onMessageRe.remove();
|
|
681
737
|
|
|
682
738
|
// Remove the listener
|
|
683
739
|
this.inboxListeners.delete(props.listenerId);
|
|
@@ -694,10 +750,16 @@ class Courier {
|
|
|
694
750
|
|
|
695
751
|
// Remove all items from inboxListeners
|
|
696
752
|
this.inboxListeners.forEach(listener => {
|
|
697
|
-
var _listener$onInitialLo2, _listener$onError2, _listener$
|
|
753
|
+
var _listener$onInitialLo2, _listener$onError2, _listener$onUnreadCou2, _listener$onFeedChang2, _listener$onArchiveCh2, _listener$onPageAdded2, _listener$onMessageCh2, _listener$onMessageAd2, _listener$onMessageRe2;
|
|
698
754
|
listener === null || listener === void 0 || (_listener$onInitialLo2 = listener.onInitialLoad) === null || _listener$onInitialLo2 === void 0 ? void 0 : _listener$onInitialLo2.remove();
|
|
699
755
|
listener === null || listener === void 0 || (_listener$onError2 = listener.onError) === null || _listener$onError2 === void 0 ? void 0 : _listener$onError2.remove();
|
|
700
|
-
listener === null || listener === void 0 || (_listener$
|
|
756
|
+
listener === null || listener === void 0 || (_listener$onUnreadCou2 = listener.onUnreadCountChanged) === null || _listener$onUnreadCou2 === void 0 ? void 0 : _listener$onUnreadCou2.remove();
|
|
757
|
+
listener === null || listener === void 0 || (_listener$onFeedChang2 = listener.onFeedChanged) === null || _listener$onFeedChang2 === void 0 ? void 0 : _listener$onFeedChang2.remove();
|
|
758
|
+
listener === null || listener === void 0 || (_listener$onArchiveCh2 = listener.onArchiveChanged) === null || _listener$onArchiveCh2 === void 0 ? void 0 : _listener$onArchiveCh2.remove();
|
|
759
|
+
listener === null || listener === void 0 || (_listener$onPageAdded2 = listener.onPageAdded) === null || _listener$onPageAdded2 === void 0 ? void 0 : _listener$onPageAdded2.remove();
|
|
760
|
+
listener === null || listener === void 0 || (_listener$onMessageCh2 = listener.onMessageChanged) === null || _listener$onMessageCh2 === void 0 ? void 0 : _listener$onMessageCh2.remove();
|
|
761
|
+
listener === null || listener === void 0 || (_listener$onMessageAd2 = listener.onMessageAdded) === null || _listener$onMessageAd2 === void 0 ? void 0 : _listener$onMessageAd2.remove();
|
|
762
|
+
listener === null || listener === void 0 || (_listener$onMessageRe2 = listener.onMessageRemoved) === null || _listener$onMessageRe2 === void 0 ? void 0 : _listener$onMessageRe2.remove();
|
|
701
763
|
});
|
|
702
764
|
this.inboxListeners.clear();
|
|
703
765
|
}
|
|
@@ -715,8 +777,8 @@ class Courier {
|
|
|
715
777
|
* Fetches the next page of inbox messages.
|
|
716
778
|
* @returns {Promise<InboxMessage[]>} A promise that resolves with an array of fetched inbox messages.
|
|
717
779
|
*/
|
|
718
|
-
async fetchNextPageOfMessages() {
|
|
719
|
-
const messages = await _Modules.Modules.Shared.fetchNextPageOfMessages();
|
|
780
|
+
async fetchNextPageOfMessages(props) {
|
|
781
|
+
const messages = await _Modules.Modules.Shared.fetchNextPageOfMessages(props.inboxMessageFeed);
|
|
720
782
|
return messages.map(message => JSON.parse(message));
|
|
721
783
|
}
|
|
722
784
|
}
|