@trycourier/courier-react-native 3.2.2 → 4.1.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.
Files changed (253) hide show
  1. package/README.md +14 -3
  2. package/android/build.gradle +4 -1
  3. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
  4. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
  5. package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +4 -0
  6. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
  7. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +312 -0
  8. package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
  9. package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
  10. package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
  11. package/courier-react-native.podspec +1 -1
  12. package/ios/CourierClientModule.swift +450 -0
  13. package/ios/CourierInboxReactNativeManager.swift +17 -9
  14. package/ios/CourierReactNativeDelegate.m +21 -35
  15. package/ios/CourierReactNativeEventEmitter.swift +25 -0
  16. package/ios/CourierReactNativeModule.m +192 -23
  17. package/ios/CourierSharedModule.swift +412 -0
  18. package/ios/CourierSystemModule.swift +136 -0
  19. package/ios/Utils.swift +103 -115
  20. package/lib/commonjs/Broadcaster.js +30 -0
  21. package/lib/commonjs/Broadcaster.js.map +1 -0
  22. package/lib/commonjs/Modules.js +25 -0
  23. package/lib/commonjs/Modules.js.map +1 -0
  24. package/lib/commonjs/client/BrandClient.js +25 -0
  25. package/lib/commonjs/client/BrandClient.js.map +1 -0
  26. package/lib/commonjs/client/ClientModule.js +21 -0
  27. package/lib/commonjs/client/ClientModule.js.map +1 -0
  28. package/lib/commonjs/client/CourierClient.js +33 -0
  29. package/lib/commonjs/client/CourierClient.js.map +1 -0
  30. package/lib/commonjs/client/InboxClient.js +116 -0
  31. package/lib/commonjs/client/InboxClient.js.map +1 -0
  32. package/lib/commonjs/client/PreferenceClient.js +73 -0
  33. package/lib/commonjs/client/PreferenceClient.js.map +1 -0
  34. package/lib/commonjs/client/TokenClient.js +36 -0
  35. package/lib/commonjs/client/TokenClient.js.map +1 -0
  36. package/lib/commonjs/client/TrackingClient.js +25 -0
  37. package/lib/commonjs/client/TrackingClient.js.map +1 -0
  38. package/lib/commonjs/index.js +418 -186
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
  41. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
  42. package/lib/commonjs/models/CourierBrand.js +2 -0
  43. package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  44. package/lib/commonjs/models/CourierButton.js.map +1 -1
  45. package/lib/commonjs/models/CourierDevice.js +2 -0
  46. package/lib/commonjs/models/CourierDevice.js.map +1 -0
  47. package/lib/commonjs/models/CourierFont.js.map +1 -1
  48. package/lib/commonjs/models/CourierInboxListener.js +2 -2
  49. package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
  50. package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
  51. package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
  52. package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
  53. package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
  54. package/lib/commonjs/models/CourierPaging.js.map +1 -1
  55. package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
  56. package/lib/commonjs/models/CourierPushListener.js +7 -3
  57. package/lib/commonjs/models/CourierPushListener.js.map +1 -1
  58. package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
  59. package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
  60. package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
  61. package/lib/commonjs/models/CourierUserPreferences.js +54 -0
  62. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
  63. package/lib/commonjs/models/InboxAction.js.map +1 -1
  64. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  65. package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
  66. package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
  67. package/lib/commonjs/utils.js +9 -17
  68. package/lib/commonjs/utils.js.map +1 -1
  69. package/lib/commonjs/views/CourierInboxView.js +3 -3
  70. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  71. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
  72. package/lib/module/Broadcaster.js +23 -0
  73. package/lib/module/Broadcaster.js.map +1 -0
  74. package/lib/module/Modules.js +18 -0
  75. package/lib/module/Modules.js.map +1 -0
  76. package/lib/module/client/BrandClient.js +18 -0
  77. package/lib/module/client/BrandClient.js.map +1 -0
  78. package/lib/module/client/ClientModule.js +14 -0
  79. package/lib/module/client/ClientModule.js.map +1 -0
  80. package/lib/module/client/CourierClient.js +26 -0
  81. package/lib/module/client/CourierClient.js.map +1 -0
  82. package/lib/module/client/InboxClient.js +109 -0
  83. package/lib/module/client/InboxClient.js.map +1 -0
  84. package/lib/module/client/PreferenceClient.js +66 -0
  85. package/lib/module/client/PreferenceClient.js.map +1 -0
  86. package/lib/module/client/TokenClient.js +29 -0
  87. package/lib/module/client/TokenClient.js.map +1 -0
  88. package/lib/module/client/TrackingClient.js +18 -0
  89. package/lib/module/client/TrackingClient.js.map +1 -0
  90. package/lib/module/index.js +383 -185
  91. package/lib/module/index.js.map +1 -1
  92. package/lib/module/models/Android_CourierSheet.js.map +1 -1
  93. package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
  94. package/lib/module/models/CourierBrand.js +2 -0
  95. package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  96. package/lib/module/models/CourierButton.js.map +1 -1
  97. package/lib/module/models/CourierDevice.js +2 -0
  98. package/lib/module/models/CourierDevice.js.map +1 -0
  99. package/lib/module/models/CourierFont.js.map +1 -1
  100. package/lib/module/models/CourierInboxListener.js +1 -1
  101. package/lib/module/models/CourierInboxListener.js.map +1 -1
  102. package/lib/module/models/CourierInboxMessages.js +2 -0
  103. package/lib/module/models/CourierInboxMessages.js.map +1 -0
  104. package/lib/module/models/CourierInboxTheme.js.map +1 -1
  105. package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
  106. package/lib/module/models/CourierPaging.js.map +1 -1
  107. package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
  108. package/lib/module/models/CourierPushListener.js +7 -3
  109. package/lib/module/models/CourierPushListener.js.map +1 -1
  110. package/lib/module/models/CourierPushProvider.js.map +1 -1
  111. package/lib/module/models/CourierTrackingEvent.js +9 -0
  112. package/lib/module/models/CourierTrackingEvent.js.map +1 -0
  113. package/lib/module/models/CourierUserPreferences.js +53 -1
  114. package/lib/module/models/CourierUserPreferences.js.map +1 -1
  115. package/lib/module/models/InboxAction.js.map +1 -1
  116. package/lib/module/models/InboxMessage.js.map +1 -1
  117. package/lib/module/models/iOS_CourierCell.js.map +1 -1
  118. package/lib/module/models/iOS_CourierSheet.js.map +1 -1
  119. package/lib/module/utils.js +7 -16
  120. package/lib/module/utils.js.map +1 -1
  121. package/lib/module/views/CourierInboxView.js +3 -3
  122. package/lib/module/views/CourierInboxView.js.map +1 -1
  123. package/lib/module/views/CourierPreferencesView.js.map +1 -1
  124. package/lib/typescript/src/Broadcaster.d.ts +14 -0
  125. package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
  126. package/lib/typescript/src/Modules.d.ts +8 -0
  127. package/lib/typescript/src/Modules.d.ts.map +1 -0
  128. package/lib/typescript/src/client/BrandClient.d.ts +15 -0
  129. package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
  130. package/lib/typescript/src/client/ClientModule.d.ts +8 -0
  131. package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
  132. package/lib/typescript/src/client/CourierClient.d.ts +31 -0
  133. package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
  134. package/lib/typescript/src/client/InboxClient.d.ts +94 -0
  135. package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
  136. package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
  137. package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
  138. package/lib/typescript/src/client/TokenClient.d.ts +28 -0
  139. package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
  140. package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
  141. package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
  142. package/lib/typescript/src/index.d.ts +300 -0
  143. package/lib/typescript/src/index.d.ts.map +1 -0
  144. package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
  145. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
  146. package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
  147. package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
  148. package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
  149. package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
  150. package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
  151. package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
  152. package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
  153. package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
  154. package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
  155. package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
  156. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
  157. package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
  158. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
  159. package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
  160. package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
  161. package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
  162. package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
  163. package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
  164. package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
  165. package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
  166. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
  167. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
  168. package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
  169. package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
  170. package/lib/typescript/src/utils.d.ts +14 -0
  171. package/lib/typescript/src/utils.d.ts.map +1 -0
  172. package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
  173. package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
  174. package/package.json +3 -3
  175. package/src/Broadcaster.tsx +32 -0
  176. package/src/Modules.tsx +28 -0
  177. package/src/client/BrandClient.tsx +23 -0
  178. package/src/client/ClientModule.tsx +21 -0
  179. package/src/client/CourierClient.tsx +49 -0
  180. package/src/client/InboxClient.tsx +114 -0
  181. package/src/client/PreferenceClient.tsx +77 -0
  182. package/src/client/TokenClient.tsx +34 -0
  183. package/src/client/TrackingClient.tsx +23 -0
  184. package/src/index.tsx +398 -205
  185. package/src/models/CourierBrand.tsx +24 -0
  186. package/src/models/CourierDevice.tsx +8 -0
  187. package/src/models/CourierInboxListener.tsx +1 -1
  188. package/src/models/CourierInboxMessages.tsx +28 -0
  189. package/src/models/CourierPushListener.tsx +11 -6
  190. package/src/models/CourierTrackingEvent.tsx +7 -0
  191. package/src/models/CourierUserPreferences.tsx +70 -3
  192. package/src/utils.tsx +7 -23
  193. package/src/views/CourierInboxView.tsx +3 -3
  194. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
  195. package/ios/CourierReactNativeModule.swift +0 -524
  196. package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
  197. package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
  198. package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
  199. package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
  200. package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
  201. package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
  202. package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
  203. package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
  204. package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
  205. package/lib/typescript/index.d.ts +0 -199
  206. package/lib/typescript/index.d.ts.map +0 -1
  207. package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
  208. package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
  209. package/lib/typescript/models/CourierButton.d.ts.map +0 -1
  210. package/lib/typescript/models/CourierFont.d.ts.map +0 -1
  211. package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
  212. package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
  213. package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
  214. package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
  215. package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
  216. package/lib/typescript/models/CourierPushListener.d.ts +0 -7
  217. package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
  218. package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
  219. package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
  220. package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
  221. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
  222. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
  223. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
  224. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
  225. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
  226. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
  227. package/lib/typescript/models/InboxAction.d.ts.map +0 -1
  228. package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
  229. package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
  230. package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
  231. package/lib/typescript/utils.d.ts +0 -21
  232. package/lib/typescript/utils.d.ts.map +0 -1
  233. package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
  234. package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
  235. package/src/models/CourierUserPreferencesChannel.tsx +0 -8
  236. package/src/models/CourierUserPreferencesStatus.tsx +0 -6
  237. package/src/models/CourierUserPreferencesTopic.tsx +0 -13
  238. /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
  239. /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
  240. /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
  241. /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
  242. /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
  243. /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
  244. /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
  245. /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
  246. /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
  247. /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
  248. /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
  249. /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
  250. /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
  251. /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
  252. /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
  253. /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
@@ -0,0 +1,312 @@
1
+ package com.courierreactnative
2
+
3
+ import com.courier.android.Courier
4
+ import com.courier.android.models.CourierAuthenticationListener
5
+ import com.courier.android.models.CourierInboxListener
6
+ import com.courier.android.models.InboxMessage
7
+ import com.courier.android.models.remove
8
+ import com.courier.android.modules.addAuthenticationListener
9
+ import com.courier.android.modules.addInboxListener
10
+ import com.courier.android.modules.archiveMessage
11
+ import com.courier.android.modules.clickMessage
12
+ import com.courier.android.modules.fetchNextInboxPage
13
+ import com.courier.android.modules.getToken
14
+ import com.courier.android.modules.inboxPaginationLimit
15
+ import com.courier.android.modules.isUserSignedIn
16
+ import com.courier.android.modules.openMessage
17
+ import com.courier.android.modules.readAllInboxMessages
18
+ import com.courier.android.modules.readMessage
19
+ import com.courier.android.modules.refreshInbox
20
+ import com.courier.android.modules.setToken
21
+ import com.courier.android.modules.signIn
22
+ import com.courier.android.modules.signOut
23
+ import com.courier.android.modules.tenantId
24
+ import com.courier.android.modules.tokens
25
+ import com.courier.android.modules.unreadMessage
26
+ import com.courier.android.modules.userId
27
+ import com.facebook.react.bridge.Arguments
28
+ import com.facebook.react.bridge.Promise
29
+ import com.facebook.react.bridge.ReactApplicationContext
30
+ import com.facebook.react.bridge.ReactMethod
31
+ import kotlinx.coroutines.CoroutineScope
32
+ import kotlinx.coroutines.Dispatchers
33
+ import kotlinx.coroutines.launch
34
+ import java.util.UUID
35
+
36
+
37
+ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Shared Instance Error", name = "CourierSharedModule", reactContext = reactContext) {
38
+
39
+ // Listeners
40
+ private var authenticationListeners = mutableMapOf<String, CourierAuthenticationListener>()
41
+ private var inboxListeners = mutableMapOf<String, CourierInboxListener>()
42
+
43
+ @ReactMethod
44
+ fun addListener(type: String?) {
45
+ // Keep: Required for RN built in Event Emitter Calls.
46
+ }
47
+
48
+ @ReactMethod
49
+ fun removeListeners(type: Int?) {
50
+ // Keep: Required for RN built in Event Emitter Calls.
51
+ }
52
+
53
+ // Client
54
+
55
+ @ReactMethod(isBlockingSynchronousMethod = true)
56
+ fun getClient(): String? {
57
+ val options = Courier.shared.client?.options ?: return null
58
+ return options.toJson()
59
+ }
60
+
61
+ // Authentication
62
+
63
+ @ReactMethod(isBlockingSynchronousMethod = true)
64
+ fun getUserId(): String? {
65
+ return Courier.shared.userId
66
+ }
67
+
68
+ @ReactMethod(isBlockingSynchronousMethod = true)
69
+ fun getTenantId(): String? {
70
+ return Courier.shared.tenantId
71
+ }
72
+
73
+ @ReactMethod(isBlockingSynchronousMethod = true)
74
+ fun getIsUserSignedIn(): String {
75
+ return Courier.shared.isUserSignedIn.toString()
76
+ }
77
+
78
+ @ReactMethod
79
+ fun signIn(accessToken: String, clientKey: String?, userId: String, tenantId: String?, showLogs: Boolean, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
80
+ Courier.shared.signIn(
81
+ userId = userId,
82
+ tenantId = tenantId,
83
+ accessToken = accessToken,
84
+ clientKey = clientKey,
85
+ showLogs = showLogs
86
+ )
87
+ promise.resolve(null)
88
+ }
89
+
90
+ @ReactMethod
91
+ fun signOut(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
92
+ Courier.shared.signOut()
93
+ promise.resolve(null)
94
+ }
95
+
96
+ @ReactMethod(isBlockingSynchronousMethod = true)
97
+ fun addAuthenticationListener(listenerId: String): String {
98
+
99
+ // Create the listener
100
+ val listener = Courier.shared.addAuthenticationListener { userId ->
101
+ reactApplicationContext.sendEvent(
102
+ eventName = listenerId,
103
+ value = userId
104
+ )
105
+ }
106
+
107
+ // Add the listener to the map
108
+ authenticationListeners[listenerId] = listener
109
+
110
+ return listenerId
111
+
112
+ }
113
+
114
+ @ReactMethod(isBlockingSynchronousMethod = true)
115
+ fun removeAuthenticationListener(listenerId: String): String {
116
+
117
+ val listener = authenticationListeners[listenerId]
118
+
119
+ // Disable the listener
120
+ listener?.remove()
121
+
122
+ // Remove the id from the map
123
+ authenticationListeners.remove(listenerId)
124
+
125
+ return listenerId
126
+
127
+ }
128
+
129
+ @ReactMethod(isBlockingSynchronousMethod = true)
130
+ fun removeAllAuthenticationListeners(): String? {
131
+ authenticationListeners.values.forEach { it.remove() }
132
+ authenticationListeners.clear()
133
+ return null
134
+ }
135
+
136
+ // Push
137
+
138
+ @ReactMethod
139
+ fun getAllTokens(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
140
+ val tokens = Courier.shared.tokens
141
+ val resultMap = Arguments.createMap()
142
+ tokens.forEach { (key, value) ->
143
+ resultMap.putString(key, value)
144
+ }
145
+ promise.resolve(resultMap)
146
+ }
147
+
148
+ @ReactMethod
149
+ fun getToken(provider: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
150
+ val token = Courier.shared.getToken(provider)
151
+ promise.resolve(token)
152
+ }
153
+
154
+ @ReactMethod
155
+ fun setToken(provider: String, token: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
156
+ try {
157
+ Courier.shared.setToken(provider, token)
158
+ promise.resolve(null)
159
+ } catch (e: Exception) {
160
+ promise.apiError(e)
161
+ }
162
+ }
163
+
164
+ // Inbox
165
+
166
+ @ReactMethod(isBlockingSynchronousMethod = true)
167
+ fun getInboxPaginationLimit(): String {
168
+ return Courier.shared.inboxPaginationLimit.toString()
169
+ }
170
+
171
+ @ReactMethod(isBlockingSynchronousMethod = true)
172
+ fun setInboxPaginationLimit(limit: Double): String {
173
+ Courier.shared.inboxPaginationLimit = limit.toInt()
174
+ return Courier.shared.inboxPaginationLimit.toString()
175
+ }
176
+
177
+ @ReactMethod
178
+ fun openMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
179
+ try {
180
+ Courier.shared.openMessage(messageId)
181
+ promise.resolve(null)
182
+ } catch (e: Exception) {
183
+ promise.apiError(e)
184
+ }
185
+ }
186
+
187
+ @ReactMethod
188
+ fun archiveMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
189
+ try {
190
+ Courier.shared.archiveMessage(messageId)
191
+ promise.resolve(null)
192
+ } catch (e: Exception) {
193
+ promise.apiError(e)
194
+ }
195
+ }
196
+
197
+ @ReactMethod
198
+ fun clickMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
199
+ try {
200
+ Courier.shared.clickMessage(messageId)
201
+ promise.resolve(null)
202
+ } catch (e: Exception) {
203
+ promise.apiError(e)
204
+ }
205
+ }
206
+
207
+ @ReactMethod
208
+ fun readMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
209
+ try {
210
+ Courier.shared.readMessage(messageId)
211
+ promise.resolve(null)
212
+ } catch (e: Exception) {
213
+ promise.apiError(e)
214
+ }
215
+ }
216
+
217
+ @ReactMethod
218
+ fun unreadMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
219
+ try {
220
+ Courier.shared.unreadMessage(messageId)
221
+ promise.resolve(null)
222
+ } catch (e: Exception) {
223
+ promise.apiError(e)
224
+ }
225
+ }
226
+
227
+ @ReactMethod
228
+ fun readAllInboxMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
229
+ try {
230
+ Courier.shared.readAllInboxMessages()
231
+ promise.resolve(null)
232
+ } catch (e: Exception) {
233
+ promise.apiError(e)
234
+ }
235
+ }
236
+
237
+ @ReactMethod(isBlockingSynchronousMethod = true)
238
+ fun addInboxListener(loadingId: String, errorId: String, messagesId: String): String {
239
+
240
+ val listener = Courier.shared.addInboxListener(
241
+ onInitialLoad = {
242
+
243
+ reactApplicationContext.sendEvent(
244
+ eventName = loadingId,
245
+ value = null
246
+ )
247
+
248
+ },
249
+ onError = { e ->
250
+
251
+ reactApplicationContext.sendEvent(
252
+ eventName = errorId,
253
+ value = e.message ?: "Courier Inbox Error"
254
+ )
255
+
256
+ },
257
+ onMessagesChanged = { messages: List<InboxMessage>, unreadMessageCount: Int, totalMessageCount: Int, canPaginate: Boolean ->
258
+
259
+ val json = Arguments.createMap()
260
+ json.putArray("messages", messages.toList().map { it.toJson() }.toWritableArray())
261
+ json.putInt("unreadMessageCount", unreadMessageCount)
262
+ json.putInt("totalMessageCount", totalMessageCount)
263
+ json.putBoolean("canPaginate", canPaginate)
264
+
265
+ reactApplicationContext.sendEvent(
266
+ eventName = messagesId,
267
+ value = json
268
+ )
269
+
270
+ }
271
+ )
272
+
273
+ // Add listener
274
+ val id = UUID.randomUUID().toString()
275
+ inboxListeners[id] = listener
276
+
277
+ return id
278
+
279
+ }
280
+
281
+ @ReactMethod(isBlockingSynchronousMethod = true)
282
+ fun removeInboxListener(listenerId: String): String {
283
+ val listener = inboxListeners[listenerId]
284
+ listener?.remove()
285
+ inboxListeners.remove(listenerId)
286
+ return listenerId
287
+ }
288
+
289
+ @ReactMethod(isBlockingSynchronousMethod = true)
290
+ fun removeAllInboxListeners(): String? {
291
+ inboxListeners.values.forEach { it.remove() }
292
+ inboxListeners.clear()
293
+ return null
294
+ }
295
+
296
+ @ReactMethod
297
+ fun refreshInbox(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
298
+ Courier.shared.refreshInbox()
299
+ promise.resolve(null)
300
+ }
301
+
302
+ @ReactMethod
303
+ fun fetchNextPageOfMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
304
+ try {
305
+ val messages = Courier.shared.fetchNextInboxPage()
306
+ promise.resolve(messages.map { it.toJson() }.toWritableArray())
307
+ } catch (e: Exception) {
308
+ promise.apiError(e)
309
+ }
310
+ }
311
+
312
+ }
@@ -0,0 +1,91 @@
1
+ package com.courierreactnative
2
+
3
+ import android.content.Intent
4
+ import android.provider.Settings
5
+ import com.courier.android.Courier
6
+ import com.courier.android.modules.isPushPermissionGranted
7
+ import com.courier.android.modules.requestNotificationPermission
8
+ import com.courier.android.utils.error
9
+ import com.courier.android.utils.pushNotification
10
+ import com.courier.android.utils.trackPushNotificationClick
11
+ import com.facebook.react.bridge.Promise
12
+ import com.facebook.react.bridge.ReactApplicationContext
13
+ import com.facebook.react.bridge.ReactMethod
14
+ import com.google.firebase.messaging.RemoteMessage
15
+ import org.json.JSONObject
16
+
17
+ class CourierSystemModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "System Error", name = "CourierSystemModule", reactContext = reactContext) {
18
+
19
+ @ReactMethod
20
+ fun addListener(type: String?) {
21
+ // Keep: Required for RN built in Event Emitter Calls.
22
+ }
23
+
24
+ @ReactMethod
25
+ fun removeListeners(type: Int?) {
26
+ // Keep: Required for RN built in Event Emitter Calls.
27
+ }
28
+
29
+ @ReactMethod
30
+ fun registerPushNotificationClickedOnKilledState() {
31
+ reactActivity?.let { activity ->
32
+ checkIntentForPushNotificationClick(activity.intent)
33
+ }
34
+ }
35
+
36
+ private fun checkIntentForPushNotificationClick(intent: Intent?) {
37
+ intent?.trackPushNotificationClick { message ->
38
+ postPushNotificationClicked(message)
39
+ }
40
+ }
41
+
42
+ private fun postPushNotificationClicked(message: RemoteMessage) {
43
+ reactApplicationContext.sendEvent(
44
+ eventName = CourierEvents.Push.CLICKED_EVENT,
45
+ value = JSONObject(message.pushNotification).toString()
46
+ )
47
+ }
48
+
49
+ @ReactMethod
50
+ fun requestNotificationPermission(promise: Promise) {
51
+
52
+ reactActivity?.let { activity ->
53
+ Courier.shared.requestNotificationPermission(activity)
54
+ }
55
+
56
+ promise.resolve("unknown")
57
+
58
+ }
59
+
60
+ @ReactMethod
61
+ fun getNotificationPermissionStatus(promise: Promise) {
62
+
63
+ reactActivity?.let { context ->
64
+
65
+ val isGranted = Courier.shared.isPushPermissionGranted(context)
66
+ val status = if (isGranted) "authorized" else "denied"
67
+ promise.resolve(status)
68
+ return
69
+
70
+ }
71
+
72
+ promise.resolve("unknown")
73
+
74
+ }
75
+
76
+ @ReactMethod(isBlockingSynchronousMethod = true)
77
+ fun openSettingsForApp(): String? {
78
+ // TODO: Move this to the native package in the future
79
+ val context = reactApplicationContext
80
+ try {
81
+ val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
82
+ intent.data = android.net.Uri.parse("package:" + context.packageName)
83
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
84
+ context.startActivity(intent)
85
+ } catch (e: Exception) {
86
+ Courier.shared.client?.error(e.toString())
87
+ }
88
+ return null
89
+ }
90
+
91
+ }
@@ -0,0 +1,36 @@
1
+ package com.courierreactnative
2
+
3
+ import com.courier.android.Courier
4
+ import com.courier.android.models.CourierAgent
5
+ import com.facebook.react.ReactActivity
6
+ import com.facebook.react.bridge.Promise
7
+ import com.facebook.react.bridge.ReactApplicationContext
8
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
9
+
10
+ abstract class ReactNativeModule(val tag: String, private val name: String, reactContext: ReactApplicationContext): ReactContextBaseJavaModule(reactContext) {
11
+
12
+ override fun getName() = name
13
+
14
+ val reactActivity: ReactActivity? get() = currentActivity as? ReactActivity
15
+
16
+ init {
17
+
18
+ // User Agent is used to ensure we know the SDK
19
+ // the requests come from
20
+ Courier.agent = CourierAgent.ReactNativeAndroid(version = "4.1.0")
21
+
22
+ }
23
+
24
+ internal fun Promise.rejectMissingContext() {
25
+ reject("Missing Context", tag, null)
26
+ }
27
+
28
+ internal fun Promise.rejectMissingClient() {
29
+ reject("Missing Client", tag, null)
30
+ }
31
+
32
+ internal fun Promise.apiError(throwable: Throwable) {
33
+ reject(throwable.message, tag, throwable)
34
+ }
35
+
36
+ }
@@ -16,6 +16,7 @@ import com.facebook.react.bridge.ReadableMap
16
16
  import com.facebook.react.bridge.WritableArray
17
17
  import com.facebook.react.bridge.WritableMap
18
18
  import com.facebook.react.modules.core.DeviceEventManagerModule
19
+ import com.google.gson.GsonBuilder
19
20
 
20
21
  internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
21
22
  getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, value)
@@ -108,12 +109,7 @@ internal fun InboxMessage.toWritableMap(): WritableMap {
108
109
  map.putBoolean("archived", isArchived)
109
110
 
110
111
  val trackingIds = Arguments.createMap()
111
- trackingIds.putString("archiveTrackingId", archiveTrackingId)
112
- trackingIds.putString("openTrackingId", openTrackingId)
113
112
  trackingIds.putString("clickTrackingId", clickTrackingId)
114
- trackingIds.putString("deliverTrackingId", deliverTrackingId)
115
- trackingIds.putString("unreadTrackingId", unreadTrackingId)
116
- trackingIds.putString("readTrackingId", readTrackingId)
117
113
 
118
114
  map.putMap("trackingIds", trackingIds)
119
115
 
@@ -218,3 +214,7 @@ internal fun ReadableMap.toInfoViewStyle(context: Context): CourierStyles.InfoVi
218
214
  )
219
215
 
220
216
  }
217
+
218
+ internal fun Any.toJson(): String {
219
+ return GsonBuilder().setPrettyPrinting().create().toJson(this)
220
+ }
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
  s.source_files = "ios/**/*.{h,m,mm,swift}"
18
18
 
19
19
  # Courier Core Dependency
20
- s.dependency "Courier_iOS", "3.5.5"
20
+ s.dependency "Courier_iOS", "4.4.2"
21
21
 
22
22
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
23
23
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.