@trycourier/courier-react-native 3.2.1 → 4.0.4

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 (251) hide show
  1. package/android/build.gradle +4 -1
  2. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
  3. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
  4. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
  5. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +321 -0
  6. package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
  7. package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
  8. package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
  9. package/courier-react-native.podspec +1 -1
  10. package/ios/CourierClientModule.swift +450 -0
  11. package/ios/CourierInboxReactNativeManager.swift +17 -9
  12. package/ios/CourierReactNativeDelegate.m +18 -35
  13. package/ios/CourierReactNativeEventEmitter.swift +25 -0
  14. package/ios/CourierReactNativeModule.m +192 -23
  15. package/ios/CourierSharedModule.swift +425 -0
  16. package/ios/CourierSystemModule.swift +147 -0
  17. package/ios/Utils.swift +103 -115
  18. package/lib/commonjs/Broadcaster.js +30 -0
  19. package/lib/commonjs/Broadcaster.js.map +1 -0
  20. package/lib/commonjs/Modules.js +25 -0
  21. package/lib/commonjs/Modules.js.map +1 -0
  22. package/lib/commonjs/client/BrandClient.js +25 -0
  23. package/lib/commonjs/client/BrandClient.js.map +1 -0
  24. package/lib/commonjs/client/ClientModule.js +21 -0
  25. package/lib/commonjs/client/ClientModule.js.map +1 -0
  26. package/lib/commonjs/client/CourierClient.js +33 -0
  27. package/lib/commonjs/client/CourierClient.js.map +1 -0
  28. package/lib/commonjs/client/InboxClient.js +116 -0
  29. package/lib/commonjs/client/InboxClient.js.map +1 -0
  30. package/lib/commonjs/client/PreferenceClient.js +73 -0
  31. package/lib/commonjs/client/PreferenceClient.js.map +1 -0
  32. package/lib/commonjs/client/TokenClient.js +36 -0
  33. package/lib/commonjs/client/TokenClient.js.map +1 -0
  34. package/lib/commonjs/client/TrackingClient.js +25 -0
  35. package/lib/commonjs/client/TrackingClient.js.map +1 -0
  36. package/lib/commonjs/index.js +418 -186
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
  39. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
  40. package/lib/commonjs/models/CourierBrand.js +2 -0
  41. package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  42. package/lib/commonjs/models/CourierButton.js.map +1 -1
  43. package/lib/commonjs/models/CourierDevice.js +2 -0
  44. package/lib/commonjs/models/CourierDevice.js.map +1 -0
  45. package/lib/commonjs/models/CourierFont.js.map +1 -1
  46. package/lib/commonjs/models/CourierInboxListener.js +2 -2
  47. package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
  48. package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
  49. package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
  50. package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
  51. package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
  52. package/lib/commonjs/models/CourierPaging.js.map +1 -1
  53. package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
  54. package/lib/commonjs/models/CourierPushListener.js +7 -3
  55. package/lib/commonjs/models/CourierPushListener.js.map +1 -1
  56. package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
  57. package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
  58. package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
  59. package/lib/commonjs/models/CourierUserPreferences.js +54 -0
  60. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
  61. package/lib/commonjs/models/InboxAction.js.map +1 -1
  62. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  63. package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
  64. package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
  65. package/lib/commonjs/utils.js +9 -17
  66. package/lib/commonjs/utils.js.map +1 -1
  67. package/lib/commonjs/views/CourierInboxView.js +3 -3
  68. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  69. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
  70. package/lib/module/Broadcaster.js +23 -0
  71. package/lib/module/Broadcaster.js.map +1 -0
  72. package/lib/module/Modules.js +18 -0
  73. package/lib/module/Modules.js.map +1 -0
  74. package/lib/module/client/BrandClient.js +18 -0
  75. package/lib/module/client/BrandClient.js.map +1 -0
  76. package/lib/module/client/ClientModule.js +14 -0
  77. package/lib/module/client/ClientModule.js.map +1 -0
  78. package/lib/module/client/CourierClient.js +26 -0
  79. package/lib/module/client/CourierClient.js.map +1 -0
  80. package/lib/module/client/InboxClient.js +109 -0
  81. package/lib/module/client/InboxClient.js.map +1 -0
  82. package/lib/module/client/PreferenceClient.js +66 -0
  83. package/lib/module/client/PreferenceClient.js.map +1 -0
  84. package/lib/module/client/TokenClient.js +29 -0
  85. package/lib/module/client/TokenClient.js.map +1 -0
  86. package/lib/module/client/TrackingClient.js +18 -0
  87. package/lib/module/client/TrackingClient.js.map +1 -0
  88. package/lib/module/index.js +383 -185
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/models/Android_CourierSheet.js.map +1 -1
  91. package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
  92. package/lib/module/models/CourierBrand.js +2 -0
  93. package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  94. package/lib/module/models/CourierButton.js.map +1 -1
  95. package/lib/module/models/CourierDevice.js +2 -0
  96. package/lib/module/models/CourierDevice.js.map +1 -0
  97. package/lib/module/models/CourierFont.js.map +1 -1
  98. package/lib/module/models/CourierInboxListener.js +1 -1
  99. package/lib/module/models/CourierInboxListener.js.map +1 -1
  100. package/lib/module/models/CourierInboxMessages.js +2 -0
  101. package/lib/module/models/CourierInboxMessages.js.map +1 -0
  102. package/lib/module/models/CourierInboxTheme.js.map +1 -1
  103. package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
  104. package/lib/module/models/CourierPaging.js.map +1 -1
  105. package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
  106. package/lib/module/models/CourierPushListener.js +7 -3
  107. package/lib/module/models/CourierPushListener.js.map +1 -1
  108. package/lib/module/models/CourierPushProvider.js.map +1 -1
  109. package/lib/module/models/CourierTrackingEvent.js +9 -0
  110. package/lib/module/models/CourierTrackingEvent.js.map +1 -0
  111. package/lib/module/models/CourierUserPreferences.js +53 -1
  112. package/lib/module/models/CourierUserPreferences.js.map +1 -1
  113. package/lib/module/models/InboxAction.js.map +1 -1
  114. package/lib/module/models/InboxMessage.js.map +1 -1
  115. package/lib/module/models/iOS_CourierCell.js.map +1 -1
  116. package/lib/module/models/iOS_CourierSheet.js.map +1 -1
  117. package/lib/module/utils.js +7 -16
  118. package/lib/module/utils.js.map +1 -1
  119. package/lib/module/views/CourierInboxView.js +3 -3
  120. package/lib/module/views/CourierInboxView.js.map +1 -1
  121. package/lib/module/views/CourierPreferencesView.js.map +1 -1
  122. package/lib/typescript/src/Broadcaster.d.ts +14 -0
  123. package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
  124. package/lib/typescript/src/Modules.d.ts +8 -0
  125. package/lib/typescript/src/Modules.d.ts.map +1 -0
  126. package/lib/typescript/src/client/BrandClient.d.ts +15 -0
  127. package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
  128. package/lib/typescript/src/client/ClientModule.d.ts +8 -0
  129. package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
  130. package/lib/typescript/src/client/CourierClient.d.ts +31 -0
  131. package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
  132. package/lib/typescript/src/client/InboxClient.d.ts +94 -0
  133. package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
  134. package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
  135. package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
  136. package/lib/typescript/src/client/TokenClient.d.ts +28 -0
  137. package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
  138. package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
  139. package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
  140. package/lib/typescript/src/index.d.ts +300 -0
  141. package/lib/typescript/src/index.d.ts.map +1 -0
  142. package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
  143. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
  144. package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
  145. package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
  146. package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
  147. package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
  148. package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
  149. package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
  150. package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
  151. package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
  152. package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
  153. package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
  154. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
  155. package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
  156. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
  157. package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
  158. package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
  159. package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
  160. package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
  161. package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
  162. package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
  163. package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
  164. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
  165. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
  166. package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
  167. package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
  168. package/lib/typescript/src/utils.d.ts +14 -0
  169. package/lib/typescript/src/utils.d.ts.map +1 -0
  170. package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
  171. package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
  172. package/package.json +3 -3
  173. package/src/Broadcaster.tsx +32 -0
  174. package/src/Modules.tsx +28 -0
  175. package/src/client/BrandClient.tsx +23 -0
  176. package/src/client/ClientModule.tsx +21 -0
  177. package/src/client/CourierClient.tsx +49 -0
  178. package/src/client/InboxClient.tsx +114 -0
  179. package/src/client/PreferenceClient.tsx +77 -0
  180. package/src/client/TokenClient.tsx +34 -0
  181. package/src/client/TrackingClient.tsx +23 -0
  182. package/src/index.tsx +398 -205
  183. package/src/models/CourierBrand.tsx +24 -0
  184. package/src/models/CourierDevice.tsx +8 -0
  185. package/src/models/CourierInboxListener.tsx +1 -1
  186. package/src/models/CourierInboxMessages.tsx +28 -0
  187. package/src/models/CourierPushListener.tsx +11 -6
  188. package/src/models/CourierTrackingEvent.tsx +7 -0
  189. package/src/models/CourierUserPreferences.tsx +70 -3
  190. package/src/utils.tsx +7 -23
  191. package/src/views/CourierInboxView.tsx +3 -3
  192. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
  193. package/ios/CourierReactNativeModule.swift +0 -524
  194. package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
  195. package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
  196. package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
  197. package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
  198. package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
  199. package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
  200. package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
  201. package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
  202. package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
  203. package/lib/typescript/index.d.ts +0 -199
  204. package/lib/typescript/index.d.ts.map +0 -1
  205. package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
  206. package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
  207. package/lib/typescript/models/CourierButton.d.ts.map +0 -1
  208. package/lib/typescript/models/CourierFont.d.ts.map +0 -1
  209. package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
  210. package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
  211. package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
  212. package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
  213. package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
  214. package/lib/typescript/models/CourierPushListener.d.ts +0 -7
  215. package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
  216. package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
  217. package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
  218. package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
  219. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
  220. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
  221. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
  222. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
  223. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
  224. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
  225. package/lib/typescript/models/InboxAction.d.ts.map +0 -1
  226. package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
  227. package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
  228. package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
  229. package/lib/typescript/utils.d.ts +0 -21
  230. package/lib/typescript/utils.d.ts.map +0 -1
  231. package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
  232. package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
  233. package/src/models/CourierUserPreferencesChannel.tsx +0 -8
  234. package/src/models/CourierUserPreferencesStatus.tsx +0 -6
  235. package/src/models/CourierUserPreferencesTopic.tsx +0 -13
  236. /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
  237. /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
  238. /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
  239. /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
  240. /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
  241. /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
  242. /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
  243. /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
  244. /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
  245. /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
  246. /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
  247. /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
  248. /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
  249. /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
  250. /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
  251. /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
@@ -0,0 +1,321 @@
1
+ package com.courierreactnative
2
+
3
+ import com.courier.android.Courier
4
+ import com.courier.android.models.CourierAgent
5
+ import com.courier.android.models.CourierAuthenticationListener
6
+ import com.courier.android.models.CourierInboxListener
7
+ import com.courier.android.models.InboxMessage
8
+ import com.courier.android.models.remove
9
+ import com.courier.android.modules.addAuthenticationListener
10
+ import com.courier.android.modules.addInboxListener
11
+ import com.courier.android.modules.archiveMessage
12
+ import com.courier.android.modules.clickMessage
13
+ import com.courier.android.modules.fetchNextInboxPage
14
+ import com.courier.android.modules.getToken
15
+ import com.courier.android.modules.inboxPaginationLimit
16
+ import com.courier.android.modules.isUserSignedIn
17
+ import com.courier.android.modules.openMessage
18
+ import com.courier.android.modules.readAllInboxMessages
19
+ import com.courier.android.modules.readMessage
20
+ import com.courier.android.modules.refreshInbox
21
+ import com.courier.android.modules.setToken
22
+ import com.courier.android.modules.signIn
23
+ import com.courier.android.modules.signOut
24
+ import com.courier.android.modules.tenantId
25
+ import com.courier.android.modules.tokens
26
+ import com.courier.android.modules.unreadMessage
27
+ import com.courier.android.modules.userId
28
+ import com.facebook.react.bridge.Arguments
29
+ import com.facebook.react.bridge.Promise
30
+ import com.facebook.react.bridge.ReactApplicationContext
31
+ import com.facebook.react.bridge.ReactMethod
32
+ import kotlinx.coroutines.CoroutineScope
33
+ import kotlinx.coroutines.Dispatchers
34
+ import kotlinx.coroutines.launch
35
+ import java.util.UUID
36
+
37
+
38
+ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Shared Instance Error", name = "CourierSharedModule", reactContext = reactContext) {
39
+
40
+ // Listeners
41
+ private var authenticationListeners = mutableMapOf<String, CourierAuthenticationListener>()
42
+ private var inboxListeners = mutableMapOf<String, CourierInboxListener>()
43
+
44
+ init {
45
+
46
+ // User Agent is used to ensure we know the SDK
47
+ // the requests come from
48
+ Courier.USER_AGENT = CourierAgent.REACT_NATIVE_ANDROID
49
+
50
+ }
51
+
52
+ @ReactMethod
53
+ fun addListener(type: String?) {
54
+ // Keep: Required for RN built in Event Emitter Calls.
55
+ }
56
+
57
+ @ReactMethod
58
+ fun removeListeners(type: Int?) {
59
+ // Keep: Required for RN built in Event Emitter Calls.
60
+ }
61
+
62
+ // Client
63
+
64
+ @ReactMethod(isBlockingSynchronousMethod = true)
65
+ fun getClient(): String? {
66
+ val options = Courier.shared.client?.options ?: return null
67
+ return options.toJson()
68
+ }
69
+
70
+ // Authentication
71
+
72
+ @ReactMethod(isBlockingSynchronousMethod = true)
73
+ fun getUserId(): String? {
74
+ return Courier.shared.userId
75
+ }
76
+
77
+ @ReactMethod(isBlockingSynchronousMethod = true)
78
+ fun getTenantId(): String? {
79
+ return Courier.shared.tenantId
80
+ }
81
+
82
+ @ReactMethod(isBlockingSynchronousMethod = true)
83
+ fun getIsUserSignedIn(): String {
84
+ return Courier.shared.isUserSignedIn.toString()
85
+ }
86
+
87
+ @ReactMethod
88
+ fun signIn(accessToken: String, clientKey: String?, userId: String, tenantId: String?, showLogs: Boolean, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
89
+ Courier.shared.signIn(
90
+ userId = userId,
91
+ tenantId = tenantId,
92
+ accessToken = accessToken,
93
+ clientKey = clientKey,
94
+ showLogs = showLogs
95
+ )
96
+ promise.resolve(null)
97
+ }
98
+
99
+ @ReactMethod
100
+ fun signOut(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
101
+ Courier.shared.signOut()
102
+ promise.resolve(null)
103
+ }
104
+
105
+ @ReactMethod(isBlockingSynchronousMethod = true)
106
+ fun addAuthenticationListener(listenerId: String): String {
107
+
108
+ // Create the listener
109
+ val listener = Courier.shared.addAuthenticationListener { userId ->
110
+ reactApplicationContext.sendEvent(
111
+ eventName = listenerId,
112
+ value = userId
113
+ )
114
+ }
115
+
116
+ // Add the listener to the map
117
+ authenticationListeners[listenerId] = listener
118
+
119
+ return listenerId
120
+
121
+ }
122
+
123
+ @ReactMethod(isBlockingSynchronousMethod = true)
124
+ fun removeAuthenticationListener(listenerId: String): String {
125
+
126
+ val listener = authenticationListeners[listenerId]
127
+
128
+ // Disable the listener
129
+ listener?.remove()
130
+
131
+ // Remove the id from the map
132
+ authenticationListeners.remove(listenerId)
133
+
134
+ return listenerId
135
+
136
+ }
137
+
138
+ @ReactMethod(isBlockingSynchronousMethod = true)
139
+ fun removeAllAuthenticationListeners(): String? {
140
+ authenticationListeners.values.forEach { it.remove() }
141
+ authenticationListeners.clear()
142
+ return null
143
+ }
144
+
145
+ // Push
146
+
147
+ @ReactMethod
148
+ fun getAllTokens(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
149
+ val tokens = Courier.shared.tokens
150
+ val resultMap = Arguments.createMap()
151
+ tokens.forEach { (key, value) ->
152
+ resultMap.putString(key, value)
153
+ }
154
+ promise.resolve(resultMap)
155
+ }
156
+
157
+ @ReactMethod
158
+ fun getToken(provider: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
159
+ val token = Courier.shared.getToken(provider)
160
+ promise.resolve(token)
161
+ }
162
+
163
+ @ReactMethod
164
+ fun setToken(provider: String, token: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
165
+ try {
166
+ Courier.shared.setToken(provider, token)
167
+ promise.resolve(null)
168
+ } catch (e: Exception) {
169
+ promise.apiError(e)
170
+ }
171
+ }
172
+
173
+ // Inbox
174
+
175
+ @ReactMethod(isBlockingSynchronousMethod = true)
176
+ fun getInboxPaginationLimit(): String {
177
+ return Courier.shared.inboxPaginationLimit.toString()
178
+ }
179
+
180
+ @ReactMethod(isBlockingSynchronousMethod = true)
181
+ fun setInboxPaginationLimit(limit: Double): String {
182
+ Courier.shared.inboxPaginationLimit = limit.toInt()
183
+ return Courier.shared.inboxPaginationLimit.toString()
184
+ }
185
+
186
+ @ReactMethod
187
+ fun openMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
188
+ try {
189
+ Courier.shared.openMessage(messageId)
190
+ promise.resolve(null)
191
+ } catch (e: Exception) {
192
+ promise.apiError(e)
193
+ }
194
+ }
195
+
196
+ @ReactMethod
197
+ fun archiveMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
198
+ try {
199
+ Courier.shared.archiveMessage(messageId)
200
+ promise.resolve(null)
201
+ } catch (e: Exception) {
202
+ promise.apiError(e)
203
+ }
204
+ }
205
+
206
+ @ReactMethod
207
+ fun clickMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
208
+ try {
209
+ Courier.shared.clickMessage(messageId)
210
+ promise.resolve(null)
211
+ } catch (e: Exception) {
212
+ promise.apiError(e)
213
+ }
214
+ }
215
+
216
+ @ReactMethod
217
+ fun readMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
218
+ try {
219
+ Courier.shared.readMessage(messageId)
220
+ promise.resolve(null)
221
+ } catch (e: Exception) {
222
+ promise.apiError(e)
223
+ }
224
+ }
225
+
226
+ @ReactMethod
227
+ fun unreadMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
228
+ try {
229
+ Courier.shared.unreadMessage(messageId)
230
+ promise.resolve(null)
231
+ } catch (e: Exception) {
232
+ promise.apiError(e)
233
+ }
234
+ }
235
+
236
+ @ReactMethod
237
+ fun readAllInboxMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
238
+ try {
239
+ Courier.shared.readAllInboxMessages()
240
+ promise.resolve(null)
241
+ } catch (e: Exception) {
242
+ promise.apiError(e)
243
+ }
244
+ }
245
+
246
+ @ReactMethod(isBlockingSynchronousMethod = true)
247
+ fun addInboxListener(loadingId: String, errorId: String, messagesId: String): String {
248
+
249
+ val listener = Courier.shared.addInboxListener(
250
+ onInitialLoad = {
251
+
252
+ reactApplicationContext.sendEvent(
253
+ eventName = loadingId,
254
+ value = null
255
+ )
256
+
257
+ },
258
+ onError = { e ->
259
+
260
+ reactApplicationContext.sendEvent(
261
+ eventName = errorId,
262
+ value = e.message ?: "Courier Inbox Error"
263
+ )
264
+
265
+ },
266
+ onMessagesChanged = { messages: List<InboxMessage>, unreadMessageCount: Int, totalMessageCount: Int, canPaginate: Boolean ->
267
+
268
+ val json = Arguments.createMap()
269
+ json.putArray("messages", messages.toList().map { it.toJson() }.toWritableArray())
270
+ json.putInt("unreadMessageCount", unreadMessageCount)
271
+ json.putInt("totalMessageCount", totalMessageCount)
272
+ json.putBoolean("canPaginate", canPaginate)
273
+
274
+ reactApplicationContext.sendEvent(
275
+ eventName = messagesId,
276
+ value = json
277
+ )
278
+
279
+ }
280
+ )
281
+
282
+ // Add listener
283
+ val id = UUID.randomUUID().toString()
284
+ inboxListeners[id] = listener
285
+
286
+ return id
287
+
288
+ }
289
+
290
+ @ReactMethod(isBlockingSynchronousMethod = true)
291
+ fun removeInboxListener(listenerId: String): String {
292
+ val listener = inboxListeners[listenerId]
293
+ listener?.remove()
294
+ inboxListeners.remove(listenerId)
295
+ return listenerId
296
+ }
297
+
298
+ @ReactMethod(isBlockingSynchronousMethod = true)
299
+ fun removeAllInboxListeners(): String? {
300
+ inboxListeners.values.forEach { it.remove() }
301
+ inboxListeners.clear()
302
+ return null
303
+ }
304
+
305
+ @ReactMethod
306
+ fun refreshInbox(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
307
+ Courier.shared.refreshInbox()
308
+ promise.resolve(null)
309
+ }
310
+
311
+ @ReactMethod
312
+ fun fetchNextPageOfMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
313
+ try {
314
+ val messages = Courier.shared.fetchNextInboxPage()
315
+ promise.resolve(messages.map { it.toJson() }.toWritableArray())
316
+ } catch (e: Exception) {
317
+ promise.apiError(e)
318
+ }
319
+ }
320
+
321
+ }
@@ -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.USER_AGENT = CourierAgent.REACT_NATIVE_ANDROID
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.0"
20
+ s.dependency "Courier_iOS", "4.3.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.