From 9f7159666afb72f14e9c14ea95b1725db66f4296 Mon Sep 17 00:00:00 2001 From: Ahmed Mseddi Date: Tue, 21 Feb 2023 17:59:36 +0100 Subject: [PATCH] [RN SDK] Offline messaging core (#25022) --- CHANGELOG.md | 11 ++- messaging-sample-app/ios/Podfile.lock | 77 ++++++++++--------- .../react-native-core/android/build.gradle | 2 +- .../nabla-react-native-core.podspec | 2 +- .../android/build.gradle | 2 +- .../messaging/core/models/ConversationItem.kt | 11 +-- .../messaging/core/models/PaginatedContent.kt | 15 ++++ .../messaging/core/models/RefreshingState.kt | 19 +++++ .../messaging/core/models/Response.kt | 12 +++ .../ConversationItemsWatcherModule.kt | 16 ++-- .../ConversationListWatcherModule.kt | 8 +- .../ConversationWatcherModule.kt | 5 +- .../NablaMessagingClientModule.kt | 2 +- .../ConversationItemsWatcherModule.swift | 11 ++- .../ConversationListWatcherModule.swift | 4 +- .../ConversationWatcherModule.swift | 4 +- .../ios/Sources/Models/PaginatedList.swift | 13 ++++ .../ios/Sources/Models/Response.swift | 32 ++++++++ .../nabla-react-native-messaging-core.podspec | 2 +- .../NablaMessagingClient.ts | 34 ++++---- .../types/NativeConversationItems.ts | 18 ++--- .../types/NativeConversationList.ts | 22 ++---- .../types/ResponseMapper.ts | 30 ++++++++ .../src/NablaMessagingClient/types/index.ts | 1 + .../src/types/ConversationItems.ts | 11 --- .../src/types/ConversationList.ts | 11 --- .../src/types/PaginatedList.ts | 4 + .../src/types/Response.ts | 10 +++ .../src/types/index.ts | 4 +- .../android/build.gradle | 2 +- .../nabla-react-native-messaging-ui.podspec | 2 +- .../android/build.gradle | 2 +- .../nabla-react-native-scheduling.podspec | 2 +- .../android/build.gradle | 2 +- .../nabla-react-native-video-call.podspec | 2 +- 35 files changed, 259 insertions(+), 146 deletions(-) create mode 100644 packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/PaginatedContent.kt create mode 100644 packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/RefreshingState.kt create mode 100644 packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/Response.kt create mode 100644 packages/react-native-messaging-core/ios/Sources/Models/PaginatedList.swift create mode 100644 packages/react-native-messaging-core/ios/Sources/Models/Response.swift create mode 100644 packages/react-native-messaging-core/src/NablaMessagingClient/types/ResponseMapper.ts delete mode 100644 packages/react-native-messaging-core/src/types/ConversationItems.ts delete mode 100644 packages/react-native-messaging-core/src/types/ConversationList.ts create mode 100644 packages/react-native-messaging-core/src/types/PaginatedList.ts create mode 100644 packages/react-native-messaging-core/src/types/Response.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index fdedc88..c20e7bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,23 @@ ### Added +- Messaging Core: Added a new `Response` object returned by watchers. It contains metadata about the freshness of the data returned, allowing the caller to know if the data comes from cache or is fresh and if a background refresh is in progress. + ### Changed +- Messaging Core: `watchConversation` success callback is now called with a `Response, NablaError>`. +- Messaging Core: `watchItemsOfConversation` success callback is now called with a `Response, NablaError>`. +- Messaging Core: `watchConversations` success callback is now called with a `Response> NablaError>`. + ### Fixed - Core: fixed a crash that occurred on iOS when authenticating a different user or the same user multiple times. +- Messaging Core: Fixed `createConversationWithMessage` not correctly setting providerIds on Android. ### Versions -- Android: [`1.0.0-alpha22`](https://github.com/nabla/nabla-android/releases/tag/1.0.0-alpha22) -- iOS: [`1.0.0-alpha30`](https://github.com/nabla/nabla-ios/releases/tag/1.0.0-alpha30) +- Android: [`1.0.0-alpha24`](https://github.com/nabla/nabla-android/releases/tag/1.0.0-alpha24) +- iOS: [`1.0.0-alpha32`](https://github.com/nabla/nabla-ios/releases/tag/1.0.0-alpha32) ## [1.0.0-alpha13] - 2023-01-30 diff --git a/messaging-sample-app/ios/Podfile.lock b/messaging-sample-app/ios/Podfile.lock index 931d3af..30e6b5f 100644 --- a/messaging-sample-app/ios/Podfile.lock +++ b/messaging-sample-app/ios/Podfile.lock @@ -87,38 +87,38 @@ PODS: - WebRTC-SDK (~> 104.5112.07) - Logging (1.4.0) - nabla-react-native-core (1.0.0-alpha13): - - NablaCore (= 1.0.0-alpha30) + - NablaCore (= 1.0.0-alpha32) - React-Core - nabla-react-native-messaging-core (1.0.0-alpha13): - nabla-react-native-core - - NablaMessagingCore (= 1.0.0-alpha30) + - NablaMessagingCore (= 1.0.0-alpha32) - React-Core - nabla-react-native-messaging-ui (1.0.0-alpha13): - nabla-react-native-messaging-core - - NablaMessagingUI (= 1.0.0-alpha30) + - NablaMessagingUI (= 1.0.0-alpha32) - React-Core - nabla-react-native-video-call (1.0.0-alpha13): - nabla-react-native-core - - NablaVideoCall (= 1.0.0-alpha30) + - NablaVideoCall (= 1.0.0-alpha32) - React-Core - - NablaCore (1.0.0-alpha30): + - NablaCore (1.0.0-alpha32): - Apollo/SQLite (~> 0.50) - Apollo/WebSocket (~> 0.50) - - Sentry (~> 7.30.1) - - NablaDocumentScanner (1.0.0-alpha30) - - NablaMessagingCore (1.0.0-alpha30): - - NablaCore (= 1.0.0-alpha30) - - NablaMessagingUI (1.0.0-alpha30): - - NablaCore (= 1.0.0-alpha30) - - NablaDocumentScanner (= 1.0.0-alpha30) - - NablaMessagingCore (= 1.0.0-alpha30) - - NablaVideoCall (1.0.0-alpha30): - - LiveKitClient (~> 1.0.3) - - NablaCore (= 1.0.0-alpha30) + - Sentry (~> 8.1.0) + - NablaDocumentScanner (1.0.0-alpha32) + - NablaMessagingCore (1.0.0-alpha32): + - NablaCore (= 1.0.0-alpha32) + - NablaMessagingUI (1.0.0-alpha32): + - NablaCore (= 1.0.0-alpha32) + - NablaDocumentScanner (= 1.0.0-alpha32) + - NablaMessagingCore (= 1.0.0-alpha32) + - NablaVideoCall (1.0.0-alpha32): + - LiveKitClient (~> 1.0.8) + - NablaCore (= 1.0.0-alpha32) - OpenSSL-Universal (1.1.1100) - - PromisesObjC (2.1.1) - - PromisesSwift (2.1.1): - - PromisesObjC (= 2.1.1) + - PromisesObjC (2.2.0) + - PromisesSwift (2.2.0): + - PromisesObjC (= 2.2.0) - RCT-Folly (2021.07.22.00): - boost - DoubleConversion @@ -394,15 +394,18 @@ PODS: - React-jsi (= 0.70.6) - React-logger (= 0.70.6) - React-perflogger (= 0.70.6) - - Sentry (7.30.2): - - Sentry/Core (= 7.30.2) - - Sentry/Core (7.30.2) + - Sentry (8.1.0): + - Sentry/Core (= 8.1.0) + - SentryPrivate (= 8.1.0) + - Sentry/Core (8.1.0): + - SentryPrivate (= 8.1.0) + - SentryPrivate (8.1.0) - SocketRocket (0.6.0) - SQLite.swift (0.13.3): - SQLite.swift/standard (= 0.13.3) - SQLite.swift/standard (0.13.3) - SwiftProtobuf (1.20.3) - - WebRTC-SDK (104.5112.08) + - WebRTC-SDK (104.5112.11) - Yoga (1.14.0) - YogaKit (1.18.1): - Yoga (~> 1.14) @@ -495,6 +498,7 @@ SPEC REPOS: - PromisesObjC - PromisesSwift - Sentry + - SentryPrivate - SocketRocket - SQLite.swift - SwiftProtobuf @@ -596,18 +600,18 @@ SPEC CHECKSUMS: libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 LiveKitClient: e4c5d63cd7633a5006058f27ccfddd914c5fa592 Logging: beeb016c9c80cf77042d62e83495816847ef108b - nabla-react-native-core: 4ecfd0ba468ed32975c38c29c4bbc80eb8e5af66 - nabla-react-native-messaging-core: 6f5c7f803fd41c6dca058b13f7b94ecb99adcbdc - nabla-react-native-messaging-ui: f747f0407c863759ab76721f7edf1fc12c9b070a - nabla-react-native-video-call: 67e50f23f62e842241bb9d4f9118c48677e21192 - NablaCore: cabe7a67184596bcdb87db8c384b4945cfaa4e2b - NablaDocumentScanner: 1c84c7813c2242137ee9442a16e8f7d6e176c810 - NablaMessagingCore: 7f77bebb39b2fcdc0eead22128b8cd23a52e50c5 - NablaMessagingUI: f8842233b2813726c8229e22c25bfa04f182ea1d - NablaVideoCall: 97564e510993e3cd57d0858120c367dd4d388c0b + nabla-react-native-core: c0a1c862c52dbcf2e7d3a8a106a54bb1abec6143 + nabla-react-native-messaging-core: 9c6f915343fd765e879559baf3052629853c660c + nabla-react-native-messaging-ui: f6315d355831ecfc7bf9bde2972f936eb5f37063 + nabla-react-native-video-call: a14e8bd01ff5bf95bf29cbf5a958401c5ec4df9a + NablaCore: 873295e95ed9e43d757864450bffc1d162f0c746 + NablaDocumentScanner: 8c0542f70bc9b67f5afdfe06e14c1058d9126b51 + NablaMessagingCore: f3c1168589cdf61c845d2c0ba5cf51137f024c42 + NablaMessagingUI: 68806f4813ff6dd7b106f6b25601cef79836b33a + NablaVideoCall: ad42751ba6e930c0c80456276ebdc8ee3d976dff OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c - PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb - PromisesSwift: 99fddfe4a0ec88a56486644c0da106694c92a604 + PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef + PromisesSwift: cf9eb58666a43bbe007302226e510b16c1e10959 RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda RCTRequired: e1866f61af7049eb3d8e08e8b133abd38bc1ca7a RCTTypeSafety: 27c2ac1b00609a432ced1ae701247593f07f901e @@ -634,11 +638,12 @@ SPEC CHECKSUMS: React-RCTVibration: c75ceef7aa60a33b2d5731ebe5800ddde40cefc4 React-runtimeexecutor: 15437b576139df27635400de0599d9844f1ab817 ReactCommon: 349be31adeecffc7986a0de875d7fb0dcf4e251c - Sentry: 9be48e341494bc976c963b05aa4a8ca48308c684 + Sentry: a73976b9f5a5141187b0c15432425a167c90d80f + SentryPrivate: eb7ce6ea7ccf1bbeda1f3f37fa355668849426ae SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 SQLite.swift: 903bfa3bc9ab06345fdfbb578e34f47cfcf417da SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1 - WebRTC-SDK: d5816d8135a5a947839db0caa8d8ba0e94d2b1fb + WebRTC-SDK: 98ab93b8d28f33699a6d4909a06e824a6c7497aa Yoga: 99caf8d5ab45e9d637ee6e0174ec16fbbb01bcfc YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/packages/react-native-core/android/build.gradle b/packages/react-native-core/android/build.gradle index 126882e..329b409 100644 --- a/packages/react-native-core/android/build.gradle +++ b/packages/react-native-core/android/build.gradle @@ -44,6 +44,6 @@ dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' - implementation 'com.nabla.nabla-android:core:1.0.0-alpha22' + implementation 'com.nabla.nabla-android:core:1.0.0-alpha24' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' } diff --git a/packages/react-native-core/nabla-react-native-core.podspec b/packages/react-native-core/nabla-react-native-core.podspec index 5c36b45..d3c570f 100644 --- a/packages/react-native-core/nabla-react-native-core.podspec +++ b/packages/react-native-core/nabla-react-native-core.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| s.source_files = "ios/Sources/**/*.{h,m,swift}" s.dependency 'React-Core' - s.dependency 'NablaCore', '1.0.0-alpha30' + s.dependency 'NablaCore', '1.0.0-alpha32' s.test_spec 'Tests' do |test_spec| test_spec.source_files= "ios/Tests/**/*.{h,m,swift}" diff --git a/packages/react-native-messaging-core/android/build.gradle b/packages/react-native-messaging-core/android/build.gradle index 957fa53..14020dd 100644 --- a/packages/react-native-messaging-core/android/build.gradle +++ b/packages/react-native-messaging-core/android/build.gradle @@ -46,6 +46,6 @@ dependencies { implementation project(path: ':nabla_react-native-core') - implementation 'com.nabla.nabla-android:messaging-core:1.0.0-alpha22' + implementation 'com.nabla.nabla-android:messaging-core:1.0.0-alpha24' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' } diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/ConversationItem.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/ConversationItem.kt index 81a5348..4fb25a4 100644 --- a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/ConversationItem.kt +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/ConversationItem.kt @@ -6,16 +6,7 @@ import com.facebook.react.bridge.ReadableMap import com.nabla.sdk.core.domain.entity.VideoCallRoomStatus import com.nabla.sdk.messaging.core.domain.entity.* -@JvmName("toConversationItemMapArray") -internal fun List.toMapArray(): ReadableArray { - return Arguments.createArray().apply { - forEach { item -> - pushMap(item.toMap()) - } - } -} - -private fun ConversationItem.toMap(): ReadableMap { +internal fun ConversationItem.toMap(): ReadableMap { return Arguments.createMap().also { it.putString("createdAt", createdAt.toString()) when (this) { diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/PaginatedContent.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/PaginatedContent.kt new file mode 100644 index 0000000..f4952b3 --- /dev/null +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/PaginatedContent.kt @@ -0,0 +1,15 @@ +package com.nabla.sdk.reactnative.messaging.core.models + +import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.ReadableMap +import com.facebook.react.bridge.WritableMap +import com.nabla.sdk.core.domain.entity.PaginatedContent + +internal fun PaginatedContent>.toMap(mapElement: (T) -> ReadableMap): WritableMap = + Arguments.createMap().apply { + putArray("elements", Arguments.createArray().apply { + content.forEach { pushMap(mapElement(it)) } + }) + putBoolean("hasMore", loadMore != null) + } + diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/RefreshingState.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/RefreshingState.kt new file mode 100644 index 0000000..928a357 --- /dev/null +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/RefreshingState.kt @@ -0,0 +1,19 @@ +package com.nabla.sdk.reactnative.messaging.core.models + +import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.ReadableMap +import com.nabla.sdk.core.domain.entity.RefreshingState + +internal fun RefreshingState.toMap(): ReadableMap = + Arguments.createMap().also { + when (this) { + is RefreshingState.ErrorWhileRefreshing -> { + it.putString("type", "ErrorWhileRefreshing") + it.putMap("error", error.toMap()) + } + RefreshingState.Refreshed -> + it.putString("type", "Refreshed") + RefreshingState.Refreshing -> + it.putString("type", "Refreshing") + } + } diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/Response.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/Response.kt new file mode 100644 index 0000000..6156a37 --- /dev/null +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/models/Response.kt @@ -0,0 +1,12 @@ +package com.nabla.sdk.reactnative.messaging.core.models + +import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.ReadableMap +import com.nabla.sdk.core.domain.entity.Response + +internal fun Response.toMap(mapData: (T) -> ReadableMap): ReadableMap = + Arguments.createMap().apply { + putBoolean("isDataFresh", isDataFresh) + putMap("refreshingState", refreshingState.toMap()) + putMap("data", mapData(data)) + } diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationItemsWatcherModule.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationItemsWatcherModule.kt index 6dfd10c..c9c818a 100644 --- a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationItemsWatcherModule.kt +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationItemsWatcherModule.kt @@ -6,7 +6,10 @@ import com.nabla.sdk.core.NablaClient import com.nabla.sdk.core.annotation.NablaInternal import com.nabla.sdk.core.domain.entity.InternalException.Companion.asNablaInternal import com.nabla.sdk.core.domain.entity.NablaException +import com.nabla.sdk.core.domain.entity.PaginatedContent +import com.nabla.sdk.core.domain.entity.Response import com.nabla.sdk.messaging.core.domain.entity.ConversationId +import com.nabla.sdk.messaging.core.domain.entity.ConversationItem import com.nabla.sdk.messaging.core.messagingClient import com.nabla.sdk.reactnative.messaging.core.models.toConversationId import com.nabla.sdk.reactnative.messaging.core.models.toMap @@ -43,13 +46,14 @@ internal class ConversationItemsWatcherModule( var loadMoreItemsCallback: ToUnitResult = null val watchItemsJob = NablaClient.getInstance().messagingClient.watchConversationItems(conversationId) - .onEach { - loadMoreItemsCallback = it.loadMore + .onEach { response: Response>> -> + loadMoreItemsCallback = response.data.loadMore sendUpdate( - Arguments.createMap().apply { - putMap("id", conversationId.toMap()) - putArray("items", it.content.toMapArray()) - putBoolean("hasMore", it.loadMore != null) + response.toMap { list -> + list.toMap(ConversationItem::toMap) + .also { + it.putMap("id", conversationId.toMap()) + } } ) } diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationListWatcherModule.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationListWatcherModule.kt index 84551f8..485c875 100644 --- a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationListWatcherModule.kt +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationListWatcherModule.kt @@ -33,10 +33,10 @@ internal class ConversationListWatcherModule( fun addListener(eventName: String) { if (eventName == WATCH_CONVERSATIONS_UPDATED || eventName == WATCH_CONVERSATIONS_ERROR) { watchConversationJob = NablaClient.getInstance().messagingClient.watchConversations() - .onEach { - loadMoreConversationsCallback = it.loadMore - val params = Arguments.createMap().apply { - putArray("conversations", it.content.toMapArray(reactApplicationContext)) + .onEach { response -> + loadMoreConversationsCallback = response.data.loadMore + val params = response.toMap { content -> + content.toMap { it.toMap(reactApplicationContext) } } sendEvent(reactApplicationContext, WATCH_CONVERSATIONS_UPDATED, params) diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationWatcherModule.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationWatcherModule.kt index e660121..97e002a 100644 --- a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationWatcherModule.kt +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/ConversationWatcherModule.kt @@ -4,7 +4,6 @@ import com.facebook.react.bridge.* import com.facebook.react.modules.core.DeviceEventManagerModule import com.nabla.sdk.core.NablaClient import com.nabla.sdk.core.annotation.NablaInternal -import com.nabla.sdk.core.domain.entity.InternalException import com.nabla.sdk.core.domain.entity.InternalException.Companion.asNablaInternal import com.nabla.sdk.core.domain.entity.NablaException import com.nabla.sdk.messaging.core.domain.entity.ConversationId @@ -41,8 +40,8 @@ internal class ConversationWatcherModule( } val watchConversationJob = NablaClient.getInstance().messagingClient.watchConversation(conversationId) - .onEach { - sendUpdate(it.toMap(reactApplicationContext)) + .onEach { response -> + sendUpdate(response.toMap { it.toMap(reactApplicationContext) }) } .catch { exception: Throwable -> sendError( diff --git a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/NablaMessagingClientModule.kt b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/NablaMessagingClientModule.kt index 9aaf878..68d8d64 100644 --- a/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/NablaMessagingClientModule.kt +++ b/packages/react-native-messaging-core/android/src/main/java/com/nabla/sdk/reactnative/messaging/core/nablamessagingclient/NablaMessagingClientModule.kt @@ -4,7 +4,6 @@ import com.benasher44.uuid.Uuid import com.facebook.react.bridge.* import com.nabla.sdk.core.NablaClient import com.nabla.sdk.core.annotation.NablaInternal -import com.nabla.sdk.core.domain.entity.InternalException import com.nabla.sdk.core.domain.entity.InternalException.Companion.asNablaInternal import com.nabla.sdk.core.domain.entity.NablaException import com.nabla.sdk.messaging.core.NablaMessagingModule @@ -56,6 +55,7 @@ internal class NablaMessagingClientModule( .createConversationWithMessage( initialMessage, title, + providerUuids ) .onSuccess { callback(null, it.id.toMap()) diff --git a/packages/react-native-messaging-core/ios/Sources/ConversationItemsWatcherModule/ConversationItemsWatcherModule.swift b/packages/react-native-messaging-core/ios/Sources/ConversationItemsWatcherModule/ConversationItemsWatcherModule.swift index 812c736..e795e2a 100644 --- a/packages/react-native-messaging-core/ios/Sources/ConversationItemsWatcherModule/ConversationItemsWatcherModule.swift +++ b/packages/react-native-messaging-core/ios/Sources/ConversationItemsWatcherModule/ConversationItemsWatcherModule.swift @@ -59,13 +59,16 @@ final class ConversationItemsWatcherModule: RCTEventEmitter { } }, - receiveValue: { [weak self] conversationItems in + receiveValue: { [weak self] response in guard let self = self else { return } - var dictionaryRepresentation = conversationItems.dictionaryRepresentation - dictionaryRepresentation["id"] = conversationIdMap - self.conversationItemsLoadMoreFunctions[conversationId] = conversationItems.loadMore + let dictionaryRepresentation = response.dictionaryRepresentation { list in + var dictionaryRepresentation = list.dictionaryRepresentation(\.dictionaryRepresentation) + dictionaryRepresentation["id"] = conversationIdMap + return dictionaryRepresentation + } + self.conversationItemsLoadMoreFunctions[conversationId] = response.data.loadMore self.sendEvent( withName: Event.watchConversationItemsUpdated.rawValue, body: dictionaryRepresentation diff --git a/packages/react-native-messaging-core/ios/Sources/ConversationListWatcherModule/ConversationListWatcherModule.swift b/packages/react-native-messaging-core/ios/Sources/ConversationListWatcherModule/ConversationListWatcherModule.swift index c4ee476..7d22b19 100644 --- a/packages/react-native-messaging-core/ios/Sources/ConversationListWatcherModule/ConversationListWatcherModule.swift +++ b/packages/react-native-messaging-core/ios/Sources/ConversationListWatcherModule/ConversationListWatcherModule.swift @@ -37,13 +37,13 @@ final class ConversationListWatcherModule: RCTEventEmitter { ) } }, - receiveValue: { [weak self] conversations in + receiveValue: { [weak self] response in guard let self = self else { return } self.sendEvent( withName: Event.watchConversationsUpdated.rawValue, - body: conversations.dictionaryRepresentation + body: response.dictionaryRepresentation { $0.dictionaryRepresentation(\.dictionaryRepresentation) } ) }) } diff --git a/packages/react-native-messaging-core/ios/Sources/ConversationWatcherModule/ConversationWatcherModule.swift b/packages/react-native-messaging-core/ios/Sources/ConversationWatcherModule/ConversationWatcherModule.swift index 2f9212c..e227066 100644 --- a/packages/react-native-messaging-core/ios/Sources/ConversationWatcherModule/ConversationWatcherModule.swift +++ b/packages/react-native-messaging-core/ios/Sources/ConversationWatcherModule/ConversationWatcherModule.swift @@ -56,13 +56,13 @@ final class ConversationWatcherModule: RCTEventEmitter { ) } }, - receiveValue: { [weak self] conversation in + receiveValue: { [weak self] response in guard let self = self else { return } self.sendEvent( withName: Event.watchConversationUpdated.rawValue, - body: conversation.dictionaryRepresentation + body: response.dictionaryRepresentation(\.dictionaryRepresentation) ) } ) diff --git a/packages/react-native-messaging-core/ios/Sources/Models/PaginatedList.swift b/packages/react-native-messaging-core/ios/Sources/Models/PaginatedList.swift new file mode 100644 index 0000000..86a14ef --- /dev/null +++ b/packages/react-native-messaging-core/ios/Sources/Models/PaginatedList.swift @@ -0,0 +1,13 @@ +import Foundation +import NablaCore + +extension PaginatedList { + func dictionaryRepresentation( + _ elementDictionaryRepresentation: (Element) -> [String: Any] + ) -> [String: Any] { + [ + "elements": elements.map(elementDictionaryRepresentation), + "hasMore": hasMore + ] + } +} diff --git a/packages/react-native-messaging-core/ios/Sources/Models/Response.swift b/packages/react-native-messaging-core/ios/Sources/Models/Response.swift new file mode 100644 index 0000000..0c73f71 --- /dev/null +++ b/packages/react-native-messaging-core/ios/Sources/Models/Response.swift @@ -0,0 +1,32 @@ +import Foundation +import NablaCore + +extension RefreshingState { + var dictionaryRepresentation: [String: Any] { + switch self { + + case .refreshing: + return ["type": "Refreshing"] + case .refreshed: + return ["type": "Refreshed"] + case let .failed(error): + return [ + "type": "ErrorWhileRefreshing", + "error": error.dictionaryRepresentation + ] + } + } +} + +extension Response { + func dictionaryRepresentation( + _ dataDictionaryRepresentation: (Data) -> [String: Any] + ) -> [String: Any] { + [ + "isDataFresh": isDataFresh, + "refreshingState": refreshingState.dictionaryRepresentation, + "data": dataDictionaryRepresentation(data) + + ] + } +} diff --git a/packages/react-native-messaging-core/nabla-react-native-messaging-core.podspec b/packages/react-native-messaging-core/nabla-react-native-messaging-core.podspec index f1b618c..e165edb 100644 --- a/packages/react-native-messaging-core/nabla-react-native-messaging-core.podspec +++ b/packages/react-native-messaging-core/nabla-react-native-messaging-core.podspec @@ -17,7 +17,7 @@ Pod::Spec.new do |s| s.dependency 'React-Core' s.dependency 'nabla-react-native-core' - s.dependency 'NablaMessagingCore', '1.0.0-alpha30' + s.dependency 'NablaMessagingCore', '1.0.0-alpha32' s.test_spec 'Tests' do |test_spec| test_spec.source_files= "ios/Tests/**/*.{h,m,swift}" diff --git a/packages/react-native-messaging-core/src/NablaMessagingClient/NablaMessagingClient.ts b/packages/react-native-messaging-core/src/NablaMessagingClient/NablaMessagingClient.ts index f239c9e..1182f23 100644 --- a/packages/react-native-messaging-core/src/NablaMessagingClient/NablaMessagingClient.ts +++ b/packages/react-native-messaging-core/src/NablaMessagingClient/NablaMessagingClient.ts @@ -14,12 +14,12 @@ import { } from './NativeModules'; import { Conversation, - ConversationId, - ConversationItems, - ConversationList, + ConversationId, ConversationItem, MessageId, MessageInput, NablaEventSubscription, + PaginatedList, + Response, } from '../types'; import { mapConversation, @@ -28,8 +28,8 @@ import { mapError, NativeConversation, NativeConversationItems, - NativeConversationList, } from './types'; +import { mapResponse } from './types/ResponseMapper'; const conversationListEmitter = new NativeEventEmitter( conversationListWatcherModule, @@ -78,7 +78,7 @@ export class NablaMessagingClient { */ public watchConversations( errorCallback: (error: NablaError) => void, - successCallback: (conversationsList: ConversationList) => void, + successCallback: (response: Response, NablaError>) => void, ): NablaEventSubscription { return new NablaEventSubscription( conversationListEmitter.addListener( @@ -89,8 +89,10 @@ export class NablaMessagingClient { ), conversationListEmitter.addListener( 'watchConversationsUpdated', - (data: NativeConversationList) => { - successCallback(mapConversationList(data)); + ( + response: Response, NativeError>, + ) => { + successCallback(mapResponse(response, mapConversationList)); }, ), ); @@ -162,7 +164,7 @@ export class NablaMessagingClient { public async watchConversation( conversationId: ConversationId, errorCallback: (error: NablaError) => void, - successCallback: (conversation: Conversation) => void, + successCallback: (response: Response) => void, ): Promise { return new Promise((resolve, reject) => { const subscription = new NablaEventSubscription( @@ -176,9 +178,9 @@ export class NablaMessagingClient { ), conversationEmitter.addListener( 'watchConversationUpdated', - (data: NativeConversation) => { - if (equal(data.id, conversationId)) { - successCallback(mapConversation(data)); + (response: Response) => { + if (equal(response.data.id, conversationId)) { + successCallback(mapResponse(response, mapConversation)); } }, ), @@ -206,7 +208,9 @@ export class NablaMessagingClient { public async watchItemsOfConversation( conversationId: ConversationId, errorCallback: (error: NablaError) => void, - successCallback: (conversationItems: ConversationItems) => void, + successCallback: ( + response: Response, NablaError>, + ) => void, ): Promise { return new Promise((resolve, reject) => { const subscription = new NablaEventSubscription( @@ -220,9 +224,9 @@ export class NablaMessagingClient { ), conversationItemsEmitter.addListener( 'watchConversationItemsUpdated', - (data: NativeConversationItems) => { - if (equal(data.id, conversationId)) { - successCallback(mapConversationItems(data)); + (response: Response) => { + if (equal(response.data.id, conversationId)) { + successCallback(mapResponse(response, mapConversationItems)); } }, ), diff --git a/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationItems.ts b/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationItems.ts index 9bcf0f6..baadc0b 100644 --- a/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationItems.ts +++ b/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationItems.ts @@ -2,19 +2,15 @@ import { mapConversationItem, NativeConversationItem, } from './NativeConversationItem'; -import { ConversationId, ConversationItems } from '../../types'; +import { ConversationId, ConversationItem, PaginatedList } from '../../types'; -export interface NativeConversationItems { +export type NativeConversationItems = PaginatedList & { id: ConversationId; - hasMore: boolean; - items: NativeConversationItem[]; -} +}; export const mapConversationItems: ( conversationItems: NativeConversationItems, -) => ConversationItems = (conversationItems) => { - return new ConversationItems( - conversationItems.hasMore, - conversationItems.items.map(mapConversationItem), - ); -}; +) => PaginatedList = (conversationItems) => ({ + hasMore: conversationItems.hasMore, + elements: conversationItems.elements.map(mapConversationItem), +}); diff --git a/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationList.ts b/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationList.ts index e73490d..50c9596 100644 --- a/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationList.ts +++ b/packages/react-native-messaging-core/src/NablaMessagingClient/types/NativeConversationList.ts @@ -1,21 +1,11 @@ import { mapConversation, NativeConversation } from './NativeConversation'; -import { ConversationList } from '../../types'; +import { Conversation, PaginatedList } from '../../types'; -export class NativeConversationList { - conversations: NativeConversation[]; - hasMore: Boolean; - - constructor(conversations: NativeConversation[], hasMore: Boolean) { - this.conversations = conversations; - this.hasMore = hasMore; - } -} +export type NativeConversationList = PaginatedList; export const mapConversationList: ( conversationList: NativeConversationList, -) => ConversationList = (conversationList) => { - return new ConversationList( - conversationList.conversations.map(mapConversation), - conversationList.hasMore, - ); -}; +) => PaginatedList = (conversationList) => ({ + elements: conversationList.elements.map(mapConversation), + hasMore: conversationList.hasMore, +}); diff --git a/packages/react-native-messaging-core/src/NablaMessagingClient/types/ResponseMapper.ts b/packages/react-native-messaging-core/src/NablaMessagingClient/types/ResponseMapper.ts new file mode 100644 index 0000000..d2b59ba --- /dev/null +++ b/packages/react-native-messaging-core/src/NablaMessagingClient/types/ResponseMapper.ts @@ -0,0 +1,30 @@ +import { Response, RefreshingState } from '../../types'; +import { NablaError } from '@nabla/react-native-core'; +import { NativeError } from '@nabla/react-native-core/lib/internal'; +import { mapError } from './errorMapper'; + +function mapRefreshingState( + refreshingState: RefreshingState, +): RefreshingState { + switch (refreshingState.type) { + case 'Refreshing': + case 'Refreshed': + return refreshingState; + case 'ErrorWhileRefreshing': + return { + type: refreshingState.type, + error: mapError(refreshingState.error), + }; + } +} + +export function mapResponse( + nativeResponse: Response, + transform: (native: NativeT) => T, +): Response { + return { + isDataFresh: nativeResponse.isDataFresh, + refreshingState: mapRefreshingState(nativeResponse.refreshingState), + data: transform(nativeResponse.data), + }; +} diff --git a/packages/react-native-messaging-core/src/NablaMessagingClient/types/index.ts b/packages/react-native-messaging-core/src/NablaMessagingClient/types/index.ts index faa1529..1763dfd 100644 --- a/packages/react-native-messaging-core/src/NablaMessagingClient/types/index.ts +++ b/packages/react-native-messaging-core/src/NablaMessagingClient/types/index.ts @@ -4,3 +4,4 @@ export * from './NativeConversationItem'; export * from './NativeConversationItems'; export * from './NativeConversationList'; export * from './NativeProviderInConversation'; +export * from './NativeProviderInConversation'; diff --git a/packages/react-native-messaging-core/src/types/ConversationItems.ts b/packages/react-native-messaging-core/src/types/ConversationItems.ts deleted file mode 100644 index a6847c9..0000000 --- a/packages/react-native-messaging-core/src/types/ConversationItems.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { ConversationItem } from './ConversationItem'; - -export class ConversationItems { - hasMore: boolean; - items: ConversationItem[]; - - constructor(hasMore: boolean, items: ConversationItem[]) { - this.hasMore = hasMore; - this.items = items; - } -} diff --git a/packages/react-native-messaging-core/src/types/ConversationList.ts b/packages/react-native-messaging-core/src/types/ConversationList.ts deleted file mode 100644 index 353ff31..0000000 --- a/packages/react-native-messaging-core/src/types/ConversationList.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { Conversation } from './Conversation'; - -export class ConversationList { - conversations: Conversation[]; - hasMore: Boolean; - - constructor(conversations: Conversation[], hasMore: Boolean) { - this.conversations = conversations; - this.hasMore = hasMore; - } -} diff --git a/packages/react-native-messaging-core/src/types/PaginatedList.ts b/packages/react-native-messaging-core/src/types/PaginatedList.ts new file mode 100644 index 0000000..654a2fb --- /dev/null +++ b/packages/react-native-messaging-core/src/types/PaginatedList.ts @@ -0,0 +1,4 @@ +export type PaginatedList = { + elements: Element[]; + hasMore: Boolean; +}; diff --git a/packages/react-native-messaging-core/src/types/Response.ts b/packages/react-native-messaging-core/src/types/Response.ts new file mode 100644 index 0000000..9d3bc01 --- /dev/null +++ b/packages/react-native-messaging-core/src/types/Response.ts @@ -0,0 +1,10 @@ +export type RefreshingState = + | { type: 'Refreshing' } + | { type: 'Refreshed' } + | { type: 'ErrorWhileRefreshing'; error: Error }; + +export type Response = { + isDataFresh: boolean; + refreshingState: RefreshingState; + data: Data; +}; diff --git a/packages/react-native-messaging-core/src/types/index.ts b/packages/react-native-messaging-core/src/types/index.ts index 31b41fa..8a348e8 100644 --- a/packages/react-native-messaging-core/src/types/index.ts +++ b/packages/react-native-messaging-core/src/types/index.ts @@ -1,12 +1,12 @@ export * from './Conversation'; export * from './ConversationId'; export * from './ConversationItem'; -export * from './ConversationItems'; -export * from './ConversationList'; export * from './MessageId'; export * from './MessageInput'; export * from './MessagingError'; export * from './NablaEventSubscription'; +export * from './PaginatedList'; export * from './Provider'; export * from './ProviderInConversation'; export * from './TransientId'; +export * from './Response'; diff --git a/packages/react-native-messaging-ui/android/build.gradle b/packages/react-native-messaging-ui/android/build.gradle index 80ab5aa..86ef08e 100644 --- a/packages/react-native-messaging-ui/android/build.gradle +++ b/packages/react-native-messaging-ui/android/build.gradle @@ -49,7 +49,7 @@ dependencies { implementation project(path: ':nabla_react-native-core') implementation project(path: ':nabla_react-native-messaging-core') - implementation 'com.nabla.nabla-android:messaging-ui:1.0.0-alpha22' + implementation 'com.nabla.nabla-android:messaging-ui:1.0.0-alpha24' implementation 'androidx.appcompat:appcompat:1.6.0' implementation 'com.google.android.material:material:1.7.0' implementation 'androidx.fragment:fragment-ktx:1.5.5' diff --git a/packages/react-native-messaging-ui/nabla-react-native-messaging-ui.podspec b/packages/react-native-messaging-ui/nabla-react-native-messaging-ui.podspec index cb7d4d3..7e0fbbf 100644 --- a/packages/react-native-messaging-ui/nabla-react-native-messaging-ui.podspec +++ b/packages/react-native-messaging-ui/nabla-react-native-messaging-ui.podspec @@ -17,5 +17,5 @@ Pod::Spec.new do |s| s.dependency 'React-Core' s.dependency 'nabla-react-native-messaging-core' - s.dependency 'NablaMessagingUI', '1.0.0-alpha30' + s.dependency 'NablaMessagingUI', '1.0.0-alpha32' end diff --git a/packages/react-native-scheduling/android/build.gradle b/packages/react-native-scheduling/android/build.gradle index dbc7e32..3250260 100644 --- a/packages/react-native-scheduling/android/build.gradle +++ b/packages/react-native-scheduling/android/build.gradle @@ -47,5 +47,5 @@ dependencies { implementation project(path: ':nabla_react-native-core') implementation 'androidx.fragment:fragment-ktx:1.5.5' - implementation 'com.nabla.nabla-android:scheduling:1.0.0-alpha22' + implementation 'com.nabla.nabla-android:scheduling:1.0.0-alpha24' } diff --git a/packages/react-native-scheduling/nabla-react-native-scheduling.podspec b/packages/react-native-scheduling/nabla-react-native-scheduling.podspec index b4c5e71..a01e347 100644 --- a/packages/react-native-scheduling/nabla-react-native-scheduling.podspec +++ b/packages/react-native-scheduling/nabla-react-native-scheduling.podspec @@ -17,7 +17,7 @@ Pod::Spec.new do |s| s.dependency 'React-Core' s.dependency 'nabla-react-native-core' - s.dependency 'NablaScheduling', '1.0.0-alpha30' + s.dependency 'NablaScheduling', '1.0.0-alpha32' s.test_spec 'Tests' do |test_spec| test_spec.source_files= "ios/Tests/**/*.{h,m,swift}" diff --git a/packages/react-native-video-call/android/build.gradle b/packages/react-native-video-call/android/build.gradle index 0d41b07..067ead2 100644 --- a/packages/react-native-video-call/android/build.gradle +++ b/packages/react-native-video-call/android/build.gradle @@ -46,5 +46,5 @@ dependencies { implementation project(path: ':nabla_react-native-core') - implementation 'com.nabla.nabla-android:video-call:1.0.0-alpha22' + implementation 'com.nabla.nabla-android:video-call:1.0.0-alpha24' } diff --git a/packages/react-native-video-call/nabla-react-native-video-call.podspec b/packages/react-native-video-call/nabla-react-native-video-call.podspec index ccf8d01..3ec4972 100644 --- a/packages/react-native-video-call/nabla-react-native-video-call.podspec +++ b/packages/react-native-video-call/nabla-react-native-video-call.podspec @@ -17,7 +17,7 @@ Pod::Spec.new do |s| s.dependency 'React-Core' s.dependency 'nabla-react-native-core' - s.dependency 'NablaVideoCall', '1.0.0-alpha30' + s.dependency 'NablaVideoCall', '1.0.0-alpha32' s.test_spec 'Tests' do |test_spec| test_spec.source_files= "ios/Tests/**/*.{h,m,swift}"