react-native-moengage-inbox 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,4 +18,6 @@ Pod::Spec.new do |s|
18
18
  s.dependency "React-Core"
19
19
  s.dependency "MoEngagePluginInbox",'>= 2.8.0','< 2.9.0'
20
20
 
21
+ install_modules_dependencies(s)
22
+
21
23
  end
@@ -13,8 +13,16 @@ buildscript {
13
13
  }
14
14
  }
15
15
 
16
+ ext {
17
+ //dependency version
18
+ moengageCoreVersion = "13.00.03"
19
+ moengageInboxCoreVersion = "3.0.1"
20
+ pluginBaseInboxVersion = "4.0.0"
21
+ }
22
+
16
23
  apply plugin: 'com.android.library'
17
24
  apply plugin: 'kotlin-android'
25
+ apply plugin: 'com.facebook.react'
18
26
 
19
27
  android {
20
28
  compileSdk 33
@@ -23,6 +31,8 @@ android {
23
31
  minSdk 21
24
32
  versionCode 1
25
33
  versionName "1.0"
34
+
35
+ buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
26
36
  }
27
37
 
28
38
  buildTypes {
@@ -41,6 +51,20 @@ android {
41
51
  kotlinOptions {
42
52
  freeCompilerArgs = ['-Xjvm-default=all']
43
53
  }
54
+
55
+ buildFeatures {
56
+ buildConfig true
57
+ }
58
+
59
+ sourceSets {
60
+ main {
61
+ if (isNewArchitectureEnabled()) {
62
+ java.srcDirs += ['src/newarch']
63
+ } else {
64
+ java.srcDirs += ['src/oldarch']
65
+ }
66
+ }
67
+ }
44
68
  }
45
69
 
46
70
  repositories {
@@ -50,9 +74,13 @@ repositories {
50
74
 
51
75
  dependencies {
52
76
  // noinspection GradleDynamicVersion
53
- compileOnly 'com.facebook.react:react-native:+'
77
+ compileOnly('com.facebook.react:react-native')
54
78
  compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
55
- compileOnly("com.moengage:moe-android-sdk:13.00.01")
56
- compileOnly("com.moengage:inbox-core:3.0.0")
57
- implementation("com.moengage:plugin-base-inbox:4.0.0")
79
+ compileOnly("com.moengage:moe-android-sdk:$moengageCoreVersion")
80
+ api("com.moengage:inbox-core:$moengageInboxCoreVersion")
81
+ implementation("com.moengage:plugin-base-inbox:$pluginBaseInboxVersion")
58
82
  }
83
+
84
+ def isNewArchitectureEnabled() {
85
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
86
+ }
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Copyright (c) 2014-2024 MoEngage Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Use of source code or binaries contained within MoEngage SDK is permitted only to enable use of the MoEngage platform by customers of MoEngage.
7
+ * Modification of source code and inclusion in mobile apps is explicitly allowed provided that all other conditions are met.
8
+ * Neither the name of MoEngage nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+ * Redistribution of source code or binaries is disallowed except with specific prior written permission. Any such redistribution must retain the above copyright notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+ */
13
+
14
+ package com.moengage.react.inbox
15
+
16
+ import android.content.Context
17
+ import com.facebook.react.bridge.Promise
18
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
19
+ import com.moengage.core.internal.logger.Logger
20
+ import com.moengage.core.LogLevel
21
+ import com.moengage.plugin.base.inbox.internal.InboxPluginHelper
22
+ import com.moengage.plugin.base.inbox.internal.inboxDataToJson
23
+ import com.moengage.plugin.base.inbox.internal.unClickedCountToJson
24
+
25
+ /**
26
+ * Class to handle all the request from the [MoEReactInbox] from both old and new arch
27
+ *
28
+ * @author Abhishek Kumar
29
+ * @since Todo: Add Version
30
+ */
31
+ internal class MoEngageInboxHandler(private val context: Context){
32
+
33
+ private val tag = "MoEngageInboxHandler"
34
+
35
+ private val pluginHelper = InboxPluginHelper()
36
+
37
+ fun getName() = NAME
38
+
39
+ fun getUnClickedCount(payload: String, promise: Promise) {
40
+ try {
41
+ Logger.print { "$tag getUnClickedCount()" }
42
+ val unClickedMessagesCount = pluginHelper.getUnClickedMessagesCount(context, payload)
43
+ if (unClickedMessagesCount != null)
44
+ promise.resolve(unClickedMessagesCount.toString())
45
+ else promise.resolve(unClickedCountToJson(0).toString())
46
+
47
+ } catch (t: Throwable) {
48
+ Logger.print(LogLevel.ERROR, t) { "$tag getUClickedCount() : " }
49
+ promise.resolve(unClickedCountToJson(0).toString())
50
+ }
51
+ }
52
+
53
+ fun fetchAllMessages(payload: String, promise: Promise) {
54
+ try {
55
+ val messages = pluginHelper.fetchAllMessages(context, payload) ?: run {
56
+ Logger.print { "$tag fetchAllMessages() : No messages." }
57
+ return
58
+ }
59
+ val serialisedMessages = inboxDataToJson(messages)
60
+ if (serialisedMessages.length() == 0) {
61
+ promise.reject("", "")
62
+ } else {
63
+ promise.resolve(serialisedMessages.toString())
64
+ }
65
+ } catch (t: Throwable) {
66
+ Logger.print(LogLevel.ERROR, t) { "$tag fetchAllMessages() : " }
67
+ }
68
+ }
69
+
70
+ fun deleteMessage(payload: String) {
71
+ try {
72
+ pluginHelper.deleteMessage(context, payload)
73
+ } catch (t: Throwable) {
74
+ Logger.print(LogLevel.ERROR, t) { "$tag deleteMessage() : " }
75
+ }
76
+ }
77
+
78
+ fun trackMessageClicked(payload: String) {
79
+ try {
80
+ pluginHelper.trackMessageClicked(context, payload)
81
+ } catch (t: Throwable) {
82
+ Logger.print(LogLevel.ERROR, t) { "$tag trackMessageClicked() : " }
83
+ }
84
+ }
85
+
86
+ companion object {
87
+ const val NAME = "MoEReactInbox"
88
+ }
89
+ }
@@ -1,18 +1,47 @@
1
+ /*
2
+ * Copyright (c) 2014-2024 MoEngage Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Use of source code or binaries contained within MoEngage SDK is permitted only to enable use of the MoEngage platform by customers of MoEngage.
7
+ * Modification of source code and inclusion in mobile apps is explicitly allowed provided that all other conditions are met.
8
+ * Neither the name of MoEngage nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+ * Redistribution of source code or binaries is disallowed except with specific prior written permission. Any such redistribution must retain the above copyright notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+ */
13
+
1
14
  package com.moengage.react.inbox
2
15
 
3
- import com.facebook.react.ReactPackage
16
+ import com.facebook.react.TurboReactPackage
4
17
  import com.facebook.react.bridge.NativeModule
5
18
  import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.uimanager.ViewManager
7
- import com.moengage.react.inbox.MoEngageInbox
19
+ import com.facebook.react.module.model.ReactModuleInfo
20
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
21
 
22
+ class MoengageInboxPackage : TurboReactPackage() {
9
23
 
10
- class MoengageInboxPackage : ReactPackage {
11
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
12
- return listOf(MoEngageInbox(reactContext))
24
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
25
+ return if (name == MoEngageInboxHandler.NAME) {
26
+ MoEReactInbox(reactContext)
27
+ } else {
28
+ null
29
+ }
13
30
  }
14
31
 
15
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
- return emptyList()
32
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
33
+ return ReactModuleInfoProvider {
34
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
35
+ val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
36
+ moduleInfos[MoEngageInboxHandler.NAME] = ReactModuleInfo(
37
+ MoEngageInboxHandler.NAME,
38
+ MoEngageInboxHandler.NAME,
39
+ false, // canOverrideExistingModule
40
+ false, // needsEagerInit
41
+ false, // isCxxModule
42
+ isTurboModule // isTurboModule
43
+ )
44
+ moduleInfos
45
+ }
17
46
  }
18
- }
47
+ }
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (c) 2014-2024 MoEngage Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Use of source code or binaries contained within MoEngage SDK is permitted only to enable use of the MoEngage platform by customers of MoEngage.
7
+ * Modification of source code and inclusion in mobile apps is explicitly allowed provided that all other conditions are met.
8
+ * Neither the name of MoEngage nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+ * Redistribution of source code or binaries is disallowed except with specific prior written permission. Any such redistribution must retain the above copyright notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+ */
13
+
14
+ package com.moengage.react.inbox
15
+
16
+ import com.facebook.react.bridge.Promise
17
+ import com.facebook.react.bridge.ReactApplicationContext
18
+
19
+ /**
20
+ * Bridge to communicate with inbox plugin js code in new arch
21
+ *
22
+ * @author Abhishek Kumar
23
+ * @since Todo: Add Version
24
+ */
25
+ class MoEReactInbox(reactContext: ReactApplicationContext) :
26
+ NativeMoEngageInboxSpec(reactContext) {
27
+
28
+ private val bridgeHandler = MoEngageInboxHandler(reactContext.applicationContext)
29
+
30
+ override fun getName() = bridgeHandler.getName()
31
+
32
+ override fun getUnClickedCount(payload: String, promise: Promise) {
33
+ bridgeHandler.getUnClickedCount(payload, promise)
34
+ }
35
+
36
+ override fun fetchAllMessages(payload: String, promise: Promise) {
37
+ bridgeHandler.fetchAllMessages(payload, promise)
38
+ }
39
+
40
+ override fun deleteMessage(payload: String) {
41
+ bridgeHandler.deleteMessage(payload)
42
+ }
43
+
44
+ override fun trackMessageClicked(payload: String) {
45
+ bridgeHandler.trackMessageClicked(payload)
46
+ }
47
+ }
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright (c) 2014-2024 MoEngage Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Use of source code or binaries contained within MoEngage SDK is permitted only to enable use of the MoEngage platform by customers of MoEngage.
7
+ * Modification of source code and inclusion in mobile apps is explicitly allowed provided that all other conditions are met.
8
+ * Neither the name of MoEngage nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+ * Redistribution of source code or binaries is disallowed except with specific prior written permission. Any such redistribution must retain the above copyright notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+ */
13
+
14
+ package com.moengage.react.inbox
15
+
16
+ import com.facebook.react.bridge.Promise
17
+ import com.facebook.react.bridge.ReactApplicationContext
18
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
19
+ import com.facebook.react.bridge.ReactMethod
20
+ import com.moengage.core.internal.logger.Logger
21
+ import com.moengage.core.LogLevel
22
+ import com.moengage.plugin.base.inbox.internal.InboxPluginHelper
23
+ import com.moengage.plugin.base.inbox.internal.inboxDataToJson
24
+ import com.moengage.plugin.base.inbox.internal.unClickedCountToJson
25
+
26
+ /**
27
+ * Bridge to communicate with inbox plugin js code in old arch
28
+ *
29
+ * @author Abhishek Kumar
30
+ * @since Todo: Add Version
31
+ */
32
+ class MoEReactInbox(
33
+ reactContext: ReactApplicationContext
34
+ ) : ReactContextBaseJavaModule(reactContext) {
35
+
36
+ private val bridgeHandler = MoEngageInboxHandler(reactContext.applicationContext)
37
+
38
+
39
+ override fun getName() = bridgeHandler.getName()
40
+
41
+ @ReactMethod
42
+ fun getUnClickedCount(payload: String, promise: Promise) {
43
+ bridgeHandler.getUnClickedCount(payload, promise)
44
+ }
45
+
46
+ @ReactMethod
47
+ fun fetchAllMessages(payload: String, promise: Promise) {
48
+ bridgeHandler.fetchAllMessages(payload, promise)
49
+ }
50
+
51
+ @ReactMethod
52
+ fun deleteMessage(payload: String) {
53
+ bridgeHandler.deleteMessage(payload)
54
+ }
55
+
56
+ @ReactMethod
57
+ fun trackMessageClicked(payload: String) {
58
+ bridgeHandler.trackMessageClicked(payload)
59
+ }
60
+ }
@@ -1,7 +1,14 @@
1
1
 
2
2
  #import <React/RCTBridgeModule.h>
3
- @import MoEngagePluginInbox;
4
3
 
5
- @interface MoEReactInbox : NSObject <RCTBridgeModule>
4
+ #ifdef RCT_NEW_ARCH_ENABLED
5
+ #import <NativeMoEngageInboxSpec/NativeMoEngageInboxSpec.h>
6
+ #endif
6
7
 
8
+ #ifdef RCT_NEW_ARCH_ENABLED
9
+ @interface MoEReactInbox : NSObject <NativeMoEngageInboxSpec>
10
+ @end
11
+ #else
12
+ @interface MoEReactInbox : NSObject <RCTBridgeModule>
7
13
  @end
14
+ #endif
@@ -0,0 +1,38 @@
1
+ //
2
+ // MoEReactGeofence.h
3
+ // ReactNativeMoEngageGeofence
4
+ //
5
+ // Created by Rakshitha on 14/03/24.
6
+ //
7
+
8
+
9
+ #import "MoEReactInbox.h"
10
+ #import "MoEReactNativeInboxHandler.h"
11
+
12
+ @implementation MoEReactInbox
13
+
14
+ RCT_EXPORT_MODULE()
15
+
16
+ RCT_EXPORT_METHOD(fetchAllMessages:(NSString*)payload resolve:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject) {
17
+ [[MoEReactNativeInboxHandler sharedInstance] getInboxMessages:payload resolve:resolve reject:reject];
18
+ }
19
+
20
+ RCT_EXPORT_METHOD(getUnClickedCount:(NSString*)payload resolve:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject) {
21
+ [[MoEReactNativeInboxHandler sharedInstance] getUnClickedMessageCount:payload resolve:resolve reject:reject];
22
+ }
23
+
24
+ RCT_EXPORT_METHOD(trackMessageClicked:(NSString *) payload) {
25
+ [[MoEReactNativeInboxHandler sharedInstance] trackInboxClick: payload];
26
+ }
27
+
28
+ RCT_EXPORT_METHOD(deleteMessage:(NSString *) payload) {
29
+ [[MoEReactNativeInboxHandler sharedInstance] deleteInboxEntry: payload];
30
+ }
31
+
32
+ #ifdef RCT_NEW_ARCH_ENABLED
33
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
34
+ return std::make_shared<facebook::react::NativeMoEngageInboxSpecJSI>(params);
35
+ }
36
+ #endif
37
+
38
+ @end
@@ -0,0 +1,21 @@
1
+ //
2
+ // MoEReactNativeInboxHandler.h
3
+ // Pods
4
+ //
5
+ // Created by Rakshitha on 14/03/24.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <UIKit/UIKit.h>
10
+ #import <React/RCTBridgeModule.h>
11
+
12
+
13
+ @interface MoEReactNativeInboxHandler: NSObject
14
+ +(instancetype)sharedInstance;
15
+
16
+ -(void)getInboxMessages:(NSString *)payload resolve:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject;
17
+ -(void)getUnClickedMessageCount:(NSString *)payload resolve:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject;
18
+ -(void)trackInboxClick:(NSString *)payload;
19
+ -(void)deleteInboxEntry:(NSString *)payload;
20
+ @end
21
+
@@ -0,0 +1,66 @@
1
+ //
2
+ // MoEReactNativeInboxHandler.m
3
+ // ReactNativeMoEngageInbox
4
+ //
5
+ // Created by Rakshitha on 14/03/24.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import "MoEReactNativeInboxHandler.h"
10
+ #import "ReactNativeMoEngage/MoEngageReactUtils.h"
11
+
12
+ @import MoEngagePluginInbox;
13
+
14
+
15
+ @implementation MoEReactNativeInboxHandler : NSObject
16
+
17
+ +(instancetype)sharedInstance{
18
+ static dispatch_once_t onceToken;
19
+ static MoEReactNativeInboxHandler *instance;
20
+ dispatch_once(&onceToken, ^{
21
+ instance = [[MoEReactNativeInboxHandler alloc] init];
22
+ });
23
+ return instance;
24
+ }
25
+
26
+ #pragma mark- Inbox methods
27
+ -(void)getUnClickedMessageCount:(NSString *)payload resolve:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject {
28
+ NSDictionary* jsonPayload = [MoEngageReactUtils getJSONRepresentation:payload];
29
+ [[MoEngagePluginInboxBridge sharedInstance] getUnreadMessageCount:jsonPayload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull countPayload) {
30
+ NSError *err;
31
+ NSData * jsonData = [NSJSONSerialization dataWithJSONObject:countPayload options:0 error:&err];
32
+ if (jsonData) {
33
+ NSString *strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
34
+ resolve(strPayload);
35
+ } else {
36
+ reject(@"Error", @"Error in fetching inbox messages", [NSError errorWithDomain:@"" code:400 userInfo:@{@"Error reason": @"Error in fetching response"}]);
37
+ }
38
+ }];
39
+ }
40
+
41
+ -(void)getInboxMessages:(NSString *)payload resolve:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject {
42
+ NSDictionary* jsonPayload = [MoEngageReactUtils getJSONRepresentation:payload];
43
+ [[MoEngagePluginInboxBridge sharedInstance] getInboxMessages: jsonPayload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull response) {
44
+ NSError *err;
45
+ NSData * jsonData = [NSJSONSerialization dataWithJSONObject:response options:0 error:&err];
46
+ if (jsonData) {
47
+ NSString *strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
48
+ resolve(strPayload);
49
+ } else {
50
+ reject(@"Error", @"Error in fetching inbox messages", [NSError errorWithDomain:@"" code:400 userInfo:@{@"Error reason": @"Error in fetching response"}]);
51
+ }
52
+ }];
53
+ }
54
+
55
+ #pragma mark- Stats methods
56
+ -(void)trackInboxClick:(NSString *)payload {
57
+ NSDictionary* jsonPayload = [MoEngageReactUtils getJSONRepresentation:payload];
58
+ [[MoEngagePluginInboxBridge sharedInstance] trackInboxClick:jsonPayload];
59
+ }
60
+
61
+ -(void)deleteInboxEntry:(NSString *)payload {
62
+ NSDictionary* jsonPayload = [MoEngageReactUtils getJSONRepresentation:payload];
63
+ [[MoEngagePluginInboxBridge sharedInstance] deleteInboxEntry:jsonPayload];
64
+ }
65
+
66
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-moengage-inbox",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "Inbox Module for the MoEngage Platform",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -33,10 +33,18 @@
33
33
  "registry": "https://registry.npmjs.org/"
34
34
  },
35
35
  "peerDependencies": {
36
- "react-native-moengage": "^9.0.0"
36
+ "react-native-moengage": "^10.0.0"
37
37
  },
38
38
  "license": "SEE LICENSE IN LICENSE.txt",
39
39
  "devDependencies": {
40
40
  "@types/react-native": "^0.69.3"
41
+ },
42
+ "codegenConfig": {
43
+ "name": "NativeMoEngageInboxSpec",
44
+ "type": "modules",
45
+ "jsSrcsDir": "src",
46
+ "android": {
47
+ "javaPackageName": "com.moengage.react.inbox"
48
+ }
41
49
  }
42
50
  }
@@ -0,0 +1,39 @@
1
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ /**
6
+ * API to fetch all the inbox messages.
7
+ *
8
+ * @param payload Stringified JSON payload.
9
+ *
10
+ * @returns {Promise<string>} A promise that contains inbox messages.
11
+ */
12
+ fetchAllMessages(payload: string): Promise<string>;
13
+
14
+ /**
15
+ * API to get the count of unclicked inbox messages.
16
+ *
17
+ * @param payload Stringified JSON payload.
18
+ *
19
+ * @returns {Promise<string>} A promise that contains unclicked message count payload
20
+ */
21
+ getUnClickedCount(payload: string): Promise<string>;
22
+
23
+ /**
24
+ * API to track the click on inbox message.
25
+ *
26
+ * @param payload Stringified JSON payload.
27
+ */
28
+ trackMessageClicked: (payload: string) => void;
29
+
30
+ /**
31
+ * API to delete a particular message from the list of messages
32
+ *
33
+ * @param payload Stringified JSON payload.
34
+ */
35
+ deleteMessage: (payload: string) => void;
36
+ }
37
+
38
+ const MoEngageReactInbox = TurboModuleRegistry.getEnforcing<Spec>('MoEReactInbox');
39
+ export default MoEngageReactInbox;
package/src/index.ts CHANGED
@@ -1,65 +1,64 @@
1
- import { Platform } from "react-native";
2
1
  import MoEInboxData from "../src/model/MoEInboxData";
3
2
  import MoEInboxMessage from "../src/model/MoEInboxMessage";
4
3
  import MoETextContent from "../src/model/MoETextContent";
5
4
  import MoEMedia from "../src/model/MoEMedia";
6
5
  import MoEAction from "../src/model/MoEAction";
7
- import * as MoEInboxRNiOS from "./platform/MoEInboxRNiOS";
8
6
  import { fetchEmptyInboxModel } from "./utils/MoEInboxParser"
9
- import { MoEInboxRNAndroid } from "./platform/MoEInboxRNAndroid";
10
- import { getMoEInboxMessageJson } from "./utils/MoEInboxJsonBuilder";
7
+ import * as MoEInboxHandler from "./utils/MoEInboxHandler";
11
8
 
12
- const PLATFORM_ANDROID = "android";
13
- const PLATFORM_iOS = "ios";
14
9
  var moeAppId = "";
15
10
  var MoEReactInbox = {
16
11
 
17
- initialize: function (appId:string) {
18
- moeAppId=appId;
12
+ initialize: function (appId: string) {
13
+ moeAppId = appId;
19
14
  },
20
15
 
16
+ /**
17
+ * API to fetch all the inbox messages.
18
+ *
19
+ * @returns instance of {@link MoEInboxData}
20
+ *
21
+ */
21
22
  fetchAllMessages: async function () {
22
23
  try {
23
- if (Platform.OS == PLATFORM_iOS) {
24
- return await MoEInboxRNiOS.fetchAllMessages(moeAppId);
25
- } else if (Platform.OS == PLATFORM_ANDROID) {
26
- return await MoEInboxRNAndroid.fetchAllMessages(moeAppId)
27
- }
28
- }
29
- catch (e) {
24
+ return await MoEInboxHandler.fetchAllMessages(moeAppId);
25
+ } catch (e) {
30
26
  return (fetchEmptyInboxModel());
31
27
  }
32
28
  },
33
29
 
30
+ /**
31
+ *
32
+ * API to get the count of unclicked inbox messages.
33
+ *
34
+ * @returns Unclicked message count.
35
+ *
36
+ */
34
37
  getUnClickedCount: async function () {
35
38
  try {
36
- if (Platform.OS == PLATFORM_iOS) {
37
- return await MoEInboxRNiOS.getUnClickedCount(moeAppId);
38
- } else if (Platform.OS == PLATFORM_ANDROID) {
39
- return await MoEInboxRNAndroid.getUnClickedCount(moeAppId);
40
- }
39
+ return await MoEInboxHandler.getUnClickedCount(moeAppId);
41
40
  }
42
41
  catch (e) {
43
42
  return 0
44
43
  }
45
44
  },
46
45
 
46
+ /**
47
+ * API to track the click on inbox message.
48
+ *
49
+ * @param inboxMessage instance of {@link MoEInboxMessage}
50
+ */
47
51
  trackMessageClicked: function (inboxMessage: MoEInboxMessage) {
48
- var json = getMoEInboxMessageJson(inboxMessage,moeAppId);
49
- if (Platform.OS == PLATFORM_iOS) {
50
- MoEInboxRNiOS.trackMessageClicked(json);
51
- } else if (Platform.OS == PLATFORM_ANDROID) {
52
- MoEInboxRNAndroid.trackMessageClicked(json)
53
- }
52
+ MoEInboxHandler.trackMessageClicked(inboxMessage, moeAppId);
54
53
  },
55
54
 
55
+ /**
56
+ * API to delete a particular message from the list of messages
57
+ *
58
+ * @param inboxMessage instance of {@link MoEInboxMessage}
59
+ */
56
60
  deleteMessage: function (inboxMessage: MoEInboxMessage) {
57
- var json = getMoEInboxMessageJson(inboxMessage,moeAppId);
58
- if (Platform.OS == PLATFORM_iOS) {
59
- MoEInboxRNiOS.deleteMessage(json);
60
- } else if (Platform.OS == PLATFORM_ANDROID) {
61
- MoEInboxRNAndroid.deleteMessage(json)
62
- }
61
+ MoEInboxHandler.deleteMessage(inboxMessage, moeAppId);
63
62
  }
64
63
  };
65
64
 
@@ -0,0 +1,32 @@
1
+ import { getAppIdJson, getMoEInboxMessageJson } from "../utils/MoEInboxJsonBuilder";
2
+ import { fetchEmptyInboxModel, inboxDataFromJson, unClickedCountFromPayload } from "../utils/MoEInboxParser"
3
+ import MoEngageReactInbox from "../NativeMoEngageInbox";
4
+ import MoEInboxMessage from "../../src/model/MoEInboxMessage";
5
+
6
+ export const fetchAllMessages = async (appId: string) => {
7
+ try {
8
+ const inboxMessages = await MoEngageReactInbox.fetchAllMessages(getAppIdJson(appId));
9
+ return inboxDataFromJson(inboxMessages)
10
+ } catch (error) {
11
+ return fetchEmptyInboxModel();
12
+ }
13
+ }
14
+
15
+ export const getUnClickedCount = async (appId: string) => {
16
+ try {
17
+ const countPayload = await MoEngageReactInbox.getUnClickedCount(getAppIdJson(appId));
18
+ return unClickedCountFromPayload(countPayload)
19
+ } catch (error) {
20
+ return 0;
21
+ }
22
+ }
23
+
24
+ export function trackMessageClicked(inboxMessage: MoEInboxMessage, appId: string) {
25
+ let payload = getMoEInboxMessageJson(inboxMessage, appId);
26
+ MoEngageReactInbox.trackMessageClicked(payload)
27
+ }
28
+
29
+ export function deleteMessage(inboxMessage: MoEInboxMessage, appId: string) {
30
+ let payload = getMoEInboxMessageJson(inboxMessage, appId);
31
+ MoEngageReactInbox.deleteMessage(payload)
32
+ }
@@ -2,20 +2,22 @@ import MoEInboxMessage from "../model/MoEInboxMessage";
2
2
  import { inboxMessageToJson } from "./MoEInboxParser";
3
3
 
4
4
  export function getMoEInboxMessageJson(moEInboxMessage: MoEInboxMessage, appId: String) {
5
- var json: { [k: string]: any } = {
5
+ let payload = {
6
6
  accountMeta: {
7
7
  appId: appId
8
8
  },
9
9
  data: inboxMessageToJson(moEInboxMessage)
10
10
  }
11
- return json;
11
+
12
+ return JSON.stringify(payload);
12
13
  }
13
14
 
14
15
  export function getAppIdJson(appId: String) {
15
- var json: { [k: string]: any } = {
16
+ let payload = {
16
17
  accountMeta: {
17
18
  appId: appId
18
19
  }
19
20
  }
20
- return json;
21
+
22
+ return JSON.stringify(payload);
21
23
  }
@@ -1,75 +0,0 @@
1
- package com.moengage.react.inbox
2
-
3
- import com.facebook.react.bridge.Promise
4
- import com.facebook.react.bridge.ReactApplicationContext
5
- import com.facebook.react.bridge.ReactContextBaseJavaModule
6
- import com.facebook.react.bridge.ReactMethod
7
- import com.moengage.core.internal.logger.Logger
8
- import com.moengage.core.LogLevel
9
- import com.moengage.plugin.base.inbox.internal.InboxPluginHelper
10
- import com.moengage.plugin.base.inbox.internal.inboxDataToJson
11
- import com.moengage.plugin.base.inbox.internal.unClickedCountToJson
12
-
13
- class MoEngageInbox(reactContext: ReactApplicationContext) :
14
- ReactContextBaseJavaModule(reactContext) {
15
-
16
- private val tag = "MoEngageInbox"
17
-
18
- private val context = reactContext.applicationContext
19
- private val pluginHelper = InboxPluginHelper()
20
-
21
- override fun getName(): String {
22
- return "MoEngageInbox"
23
- }
24
-
25
- @ReactMethod
26
- fun getUnClickedCount(payload: String, promise: Promise) {
27
- try {
28
- Logger.print { "$tag getUnClickedCount()" }
29
- val unClickedMessagesCount = pluginHelper.getUnClickedMessagesCount(context, payload)
30
- if (unClickedMessagesCount != null)
31
- promise.resolve(unClickedMessagesCount.toString())
32
- else promise.resolve(unClickedCountToJson(0).toString())
33
-
34
- } catch (t: Throwable) {
35
- Logger.print(LogLevel.ERROR, t) { "$tag getUClickedCount() : " }
36
- promise.resolve(unClickedCountToJson(0).toString())
37
- }
38
- }
39
-
40
- @ReactMethod
41
- fun fetchAllMessages(payload: String, promise: Promise) {
42
- try {
43
- val messages = pluginHelper.fetchAllMessages(context, payload) ?: run {
44
- Logger.print { "$tag fetchAllMessages() : No messages." }
45
- return
46
- }
47
- val serialisedMessages = inboxDataToJson(messages)
48
- if (serialisedMessages.length() == 0) {
49
- promise.reject("", "")
50
- } else {
51
- promise.resolve(serialisedMessages.toString())
52
- }
53
- } catch (t: Throwable) {
54
- Logger.print(LogLevel.ERROR, t) { "$tag fetchAllMessages() : " }
55
- }
56
- }
57
-
58
- @ReactMethod
59
- fun deleteMessage(payload: String) {
60
- try {
61
- pluginHelper.deleteMessage(context, payload)
62
- } catch (t: Throwable) {
63
- Logger.print(LogLevel.ERROR, t) { "$tag deleteMessage() : " }
64
- }
65
- }
66
-
67
- @ReactMethod
68
- fun trackMessageClicked(payload: String) {
69
- try {
70
- pluginHelper.trackMessageClicked(context, payload)
71
- } catch (t: Throwable) {
72
- Logger.print(LogLevel.ERROR, t) { "$tag trackMessageClicked() : " }
73
- }
74
- }
75
- }
@@ -1,43 +0,0 @@
1
- #import "MoEReactInbox.h"
2
-
3
- @implementation MoEReactInbox
4
-
5
- RCT_EXPORT_MODULE()
6
-
7
- RCT_EXPORT_METHOD(fetchAllMessages:(NSDictionary*)payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter) {
8
- [[MoEngagePluginInboxBridge sharedInstance] getInboxMessages:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull inboxMessages) {
9
- NSError *err;
10
- NSData * jsonData = [NSJSONSerialization dataWithJSONObject:inboxMessages options:0 error:&err];
11
- if (jsonData) {
12
- NSString *strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
13
- resolver(strPayload);
14
- } else {
15
- rejecter(@"Error", @"Error in fetching inbox messages", [NSError errorWithDomain:@"" code:400 userInfo:@{@"Error reason": @"Error in fetching response"}]);
16
- }
17
- }];
18
- }
19
-
20
- RCT_EXPORT_METHOD(getUnClickedCount:(NSDictionary*)payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter) {
21
-
22
- [[MoEngagePluginInboxBridge sharedInstance] getUnreadMessageCount:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull payload) {
23
- NSError *err;
24
- NSData * jsonData = [NSJSONSerialization dataWithJSONObject:payload options:0 error:&err];
25
- if (jsonData) {
26
- NSString *strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
27
- resolver(strPayload);
28
- } else {
29
- rejecter(@"Error", @"Error in fetching inbox unclicked message count", [NSError errorWithDomain:@"" code:400 userInfo:@{@"Error reason": @"Error in fetching response"}]);
30
- }
31
-
32
- }];
33
- }
34
-
35
- RCT_EXPORT_METHOD(trackMessageClicked:(NSDictionary *) campaignInfo) {
36
- [[MoEngagePluginInboxBridge sharedInstance] trackInboxClick:campaignInfo];
37
- }
38
-
39
- RCT_EXPORT_METHOD(deleteMessage:(NSDictionary *) campaignInfo) {
40
- [[MoEngagePluginInboxBridge sharedInstance] deleteInboxEntry:campaignInfo];
41
- }
42
-
43
- @end
@@ -1,26 +0,0 @@
1
- import { getAppIdJson } from "../utils/MoEInboxJsonBuilder";
2
- import { inboxDataFromJson, unClickedCountFromPayload } from "../utils/MoEInboxParser";
3
-
4
- const MoEngageInbox = require("react-native").NativeModules.MoEngageInbox;
5
-
6
- export class MoEInboxRNAndroid {
7
-
8
- static async getUnClickedCount(appId:string) {
9
- const countPayload = await MoEngageInbox.getUnClickedCount(JSON.stringify(getAppIdJson(appId)))
10
- return unClickedCountFromPayload(countPayload)
11
- }
12
-
13
- static async fetchAllMessages(appId:string) {
14
- const messages = await MoEngageInbox.fetchAllMessages(JSON.stringify(getAppIdJson(appId)))
15
- return inboxDataFromJson(messages)
16
- }
17
-
18
- static trackMessageClicked(inboxMessage: object) {
19
- MoEngageInbox.trackMessageClicked(JSON.stringify(inboxMessage))
20
- }
21
-
22
- static deleteMessage(inboxMessage: object) {
23
- MoEngageInbox.deleteMessage(JSON.stringify(inboxMessage))
24
- }
25
-
26
- }
@@ -1,31 +0,0 @@
1
- import { getAppIdJson } from "../utils/MoEInboxJsonBuilder";
2
- import { inboxDataFromJson, unClickedCountFromPayload } from "../utils/MoEInboxParser"
3
- const MoEngageInbox = require("react-native").NativeModules.MoEReactInbox;
4
-
5
- export const fetchAllMessages = (appId: string) => {
6
- return new Promise((resolve, reject) => {
7
- MoEngageInbox.fetchAllMessages(getAppIdJson(appId)).then((inboxMessages: string) => {
8
- resolve(inboxDataFromJson(inboxMessages));
9
- }).catch((error: any) => {
10
- reject(error);
11
- });
12
- });
13
- }
14
-
15
- export const getUnClickedCount = (appId:string) => {
16
- return new Promise((resolve, reject) => {
17
- MoEngageInbox.getUnClickedCount(getAppIdJson(appId)).then((countPayload: string) => {
18
- resolve(unClickedCountFromPayload(countPayload));
19
- }).catch((error: any) => {
20
- reject(error);
21
- });
22
- });
23
- }
24
-
25
- export function trackMessageClicked(inboxInfo: Object) {
26
- MoEngageInbox.trackMessageClicked(inboxInfo)
27
- }
28
-
29
- export function deleteMessage(inboxInfo: Object) {
30
- MoEngageInbox.deleteMessage(inboxInfo)
31
- }