react-native-moengage-inbox 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # react-native-moengage-inbox
2
+
3
+ Inbox Module for the MoEngage Platform
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install react-native-moengage-inbox
9
+ ```
10
+
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "ReactNativeMoEngageInbox"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = "https://www.moengage.com"
10
+ s.license = package['license']
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => "10.0" }
14
+ s.source = { :git => "https://github.com/moengage/React-Native.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
17
+
18
+ s.dependency "React-Core"
19
+ s.dependency "MoEPluginBase", "~> 2.1.0"
20
+
21
+ end
@@ -0,0 +1,56 @@
1
+ buildscript {
2
+ ext.kotlinVersion = '1.4.20'
3
+
4
+ repositories {
5
+ google()
6
+ mavenCentral()
7
+ }
8
+
9
+ dependencies {
10
+ classpath 'com.android.tools.build:gradle:4.1.2'
11
+ // noinspection DifferentKotlinGradleVersion
12
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
13
+ }
14
+ }
15
+
16
+ apply plugin: 'com.android.library'
17
+ apply plugin: 'kotlin-android'
18
+
19
+ android {
20
+ compileSdkVersion 29
21
+
22
+ defaultConfig {
23
+ minSdkVersion 16
24
+ targetSdkVersion 29
25
+ versionCode 1
26
+ versionName "1.0"
27
+ }
28
+
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
32
+ }
33
+ }
34
+ lintOptions {
35
+ disable 'GradleCompatible'
36
+ }
37
+ compileOptions {
38
+ sourceCompatibility JavaVersion.VERSION_1_8
39
+ targetCompatibility JavaVersion.VERSION_1_8
40
+ }
41
+ }
42
+
43
+ repositories {
44
+ mavenLocal()
45
+ mavenCentral()
46
+ google()
47
+ }
48
+
49
+ dependencies {
50
+ // noinspection GradleDynamicVersion
51
+ api 'com.facebook.react:react-native:+'
52
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
53
+ compileOnly("com.moengage:moe-android-sdk:11.3.01")
54
+ compileOnly("com.moengage:inbox-core:1.0.00")
55
+ implementation("com.moengage:plugin-base-inbox:2.2.0")
56
+ }
@@ -0,0 +1,5 @@
1
+ distributionBase=GRADLE_USER_HOME
2
+ distributionPath=wrapper/dists
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
4
+ zipStoreBase=GRADLE_USER_HOME
5
+ zipStorePath=wrapper/dists
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env sh
2
+
3
+ #
4
+ # Copyright 2015 the original author or authors.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # https://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ ##############################################################################
20
+ ##
21
+ ## Gradle start up script for UN*X
22
+ ##
23
+ ##############################################################################
24
+
25
+ # Attempt to set APP_HOME
26
+ # Resolve links: $0 may be a link
27
+ PRG="$0"
28
+ # Need this for relative symlinks.
29
+ while [ -h "$PRG" ] ; do
30
+ ls=`ls -ld "$PRG"`
31
+ link=`expr "$ls" : '.*-> \(.*\)$'`
32
+ if expr "$link" : '/.*' > /dev/null; then
33
+ PRG="$link"
34
+ else
35
+ PRG=`dirname "$PRG"`"/$link"
36
+ fi
37
+ done
38
+ SAVED="`pwd`"
39
+ cd "`dirname \"$PRG\"`/" >/dev/null
40
+ APP_HOME="`pwd -P`"
41
+ cd "$SAVED" >/dev/null
42
+
43
+ APP_NAME="Gradle"
44
+ APP_BASE_NAME=`basename "$0"`
45
+
46
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47
+ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48
+
49
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
50
+ MAX_FD="maximum"
51
+
52
+ warn () {
53
+ echo "$*"
54
+ }
55
+
56
+ die () {
57
+ echo
58
+ echo "$*"
59
+ echo
60
+ exit 1
61
+ }
62
+
63
+ # OS specific support (must be 'true' or 'false').
64
+ cygwin=false
65
+ msys=false
66
+ darwin=false
67
+ nonstop=false
68
+ case "`uname`" in
69
+ CYGWIN* )
70
+ cygwin=true
71
+ ;;
72
+ Darwin* )
73
+ darwin=true
74
+ ;;
75
+ MINGW* )
76
+ msys=true
77
+ ;;
78
+ NONSTOP* )
79
+ nonstop=true
80
+ ;;
81
+ esac
82
+
83
+ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84
+
85
+
86
+ # Determine the Java command to use to start the JVM.
87
+ if [ -n "$JAVA_HOME" ] ; then
88
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89
+ # IBM's JDK on AIX uses strange locations for the executables
90
+ JAVACMD="$JAVA_HOME/jre/sh/java"
91
+ else
92
+ JAVACMD="$JAVA_HOME/bin/java"
93
+ fi
94
+ if [ ! -x "$JAVACMD" ] ; then
95
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96
+
97
+ Please set the JAVA_HOME variable in your environment to match the
98
+ location of your Java installation."
99
+ fi
100
+ else
101
+ JAVACMD="java"
102
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103
+
104
+ Please set the JAVA_HOME variable in your environment to match the
105
+ location of your Java installation."
106
+ fi
107
+
108
+ # Increase the maximum file descriptors if we can.
109
+ if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110
+ MAX_FD_LIMIT=`ulimit -H -n`
111
+ if [ $? -eq 0 ] ; then
112
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113
+ MAX_FD="$MAX_FD_LIMIT"
114
+ fi
115
+ ulimit -n $MAX_FD
116
+ if [ $? -ne 0 ] ; then
117
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
118
+ fi
119
+ else
120
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121
+ fi
122
+ fi
123
+
124
+ # For Darwin, add options to specify how the application appears in the dock
125
+ if $darwin; then
126
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127
+ fi
128
+
129
+ # For Cygwin or MSYS, switch paths to Windows format before running java
130
+ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133
+
134
+ JAVACMD=`cygpath --unix "$JAVACMD"`
135
+
136
+ # We build the pattern for arguments to be converted via cygpath
137
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138
+ SEP=""
139
+ for dir in $ROOTDIRSRAW ; do
140
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
141
+ SEP="|"
142
+ done
143
+ OURCYGPATTERN="(^($ROOTDIRS))"
144
+ # Add a user-defined pattern to the cygpath arguments
145
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147
+ fi
148
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
149
+ i=0
150
+ for arg in "$@" ; do
151
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153
+
154
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156
+ else
157
+ eval `echo args$i`="\"$arg\""
158
+ fi
159
+ i=`expr $i + 1`
160
+ done
161
+ case $i in
162
+ 0) set -- ;;
163
+ 1) set -- "$args0" ;;
164
+ 2) set -- "$args0" "$args1" ;;
165
+ 3) set -- "$args0" "$args1" "$args2" ;;
166
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172
+ esac
173
+ fi
174
+
175
+ # Escape application args
176
+ save () {
177
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178
+ echo " "
179
+ }
180
+ APP_ARGS=`save "$@"`
181
+
182
+ # Collect all arguments for the java command, following the shell quoting and substitution rules
183
+ eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184
+
185
+ exec "$JAVACMD" "$@"
@@ -0,0 +1,89 @@
1
+ @rem
2
+ @rem Copyright 2015 the original author or authors.
3
+ @rem
4
+ @rem Licensed under the Apache License, Version 2.0 (the "License");
5
+ @rem you may not use this file except in compliance with the License.
6
+ @rem You may obtain a copy of the License at
7
+ @rem
8
+ @rem https://www.apache.org/licenses/LICENSE-2.0
9
+ @rem
10
+ @rem Unless required by applicable law or agreed to in writing, software
11
+ @rem distributed under the License is distributed on an "AS IS" BASIS,
12
+ @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ @rem See the License for the specific language governing permissions and
14
+ @rem limitations under the License.
15
+ @rem
16
+
17
+ @if "%DEBUG%" == "" @echo off
18
+ @rem ##########################################################################
19
+ @rem
20
+ @rem Gradle startup script for Windows
21
+ @rem
22
+ @rem ##########################################################################
23
+
24
+ @rem Set local scope for the variables with windows NT shell
25
+ if "%OS%"=="Windows_NT" setlocal
26
+
27
+ set DIRNAME=%~dp0
28
+ if "%DIRNAME%" == "" set DIRNAME=.
29
+ set APP_BASE_NAME=%~n0
30
+ set APP_HOME=%DIRNAME%
31
+
32
+ @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33
+ for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34
+
35
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36
+ set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37
+
38
+ @rem Find java.exe
39
+ if defined JAVA_HOME goto findJavaFromJavaHome
40
+
41
+ set JAVA_EXE=java.exe
42
+ %JAVA_EXE% -version >NUL 2>&1
43
+ if "%ERRORLEVEL%" == "0" goto execute
44
+
45
+ echo.
46
+ echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47
+ echo.
48
+ echo Please set the JAVA_HOME variable in your environment to match the
49
+ echo location of your Java installation.
50
+
51
+ goto fail
52
+
53
+ :findJavaFromJavaHome
54
+ set JAVA_HOME=%JAVA_HOME:"=%
55
+ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56
+
57
+ if exist "%JAVA_EXE%" goto execute
58
+
59
+ echo.
60
+ echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61
+ echo.
62
+ echo Please set the JAVA_HOME variable in your environment to match the
63
+ echo location of your Java installation.
64
+
65
+ goto fail
66
+
67
+ :execute
68
+ @rem Setup the command line
69
+
70
+ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71
+
72
+
73
+ @rem Execute Gradle
74
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75
+
76
+ :end
77
+ @rem End local scope for the variables with windows NT shell
78
+ if "%ERRORLEVEL%"=="0" goto mainEnd
79
+
80
+ :fail
81
+ rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82
+ rem the _cmd.exe /c_ return code!
83
+ if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84
+ exit /b 1
85
+
86
+ :mainEnd
87
+ if "%OS%"=="Windows_NT" endlocal
88
+
89
+ :omega
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.moengage.react.inbox">
3
+
4
+ </manifest>
@@ -0,0 +1,68 @@
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.plugin.base.inbox.InboxPluginHelper
9
+ import com.moengage.plugin.base.inbox.unClickedCountToJson
10
+
11
+ class MoEngageInbox(reactContext: ReactApplicationContext) :
12
+ ReactContextBaseJavaModule(reactContext) {
13
+
14
+ private val tag = "MoEngageInbox"
15
+
16
+ private val context = reactContext.applicationContext
17
+ private val pluginHelper = InboxPluginHelper()
18
+
19
+ override fun getName(): String {
20
+ return "MoEngageInbox"
21
+ }
22
+
23
+ @ReactMethod
24
+ fun getUnClickedCount(promise: Promise) {
25
+ try {
26
+ Logger.v("$tag getUnClickedCount() ")
27
+ promise.resolve(unClickedCountToJson(pluginHelper.getUnClickedMessagesCount(context)).toString())
28
+ } catch (e: Exception) {
29
+ Logger.e("$tag getUClickedCount() : ", e)
30
+ promise.resolve(unClickedCountToJson(0).toString())
31
+ }
32
+ }
33
+
34
+ @ReactMethod
35
+ fun fetchAllMessages(promise: Promise) {
36
+ try {
37
+ val messages = pluginHelper.fetchAllMessages(context)
38
+ val serialisedMessages = pluginHelper.serialiseInboxMessages(messages)
39
+ if (serialisedMessages == null) {
40
+ promise.reject("", "")
41
+ } else {
42
+ promise.resolve(serialisedMessages.toString())
43
+ }
44
+ } catch (e: Exception) {
45
+ Logger.e("$tag fetchAllMessages() : ", e)
46
+ }
47
+ }
48
+
49
+ @ReactMethod
50
+ fun deleteMessage(payload: String) {
51
+ try {
52
+ pluginHelper.deleteMessage(context, payload)
53
+ } catch (e: Exception) {
54
+ Logger.e("$tag deleteMessage() : ", e)
55
+ }
56
+ }
57
+
58
+ @ReactMethod
59
+ fun trackMessageClicked(payload: String) {
60
+ try {
61
+ pluginHelper.trackMessageClicked(context, payload)
62
+ } catch (e: Exception) {
63
+ Logger.e("$tag trackMessageClicked() : ", e)
64
+ }
65
+ }
66
+
67
+
68
+ }
@@ -0,0 +1,18 @@
1
+ package com.moengage.react.inbox
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+ import com.moengage.react.inbox.MoEngageInbox
8
+
9
+
10
+ class MoengageInboxPackage : ReactPackage {
11
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
12
+ return listOf(MoEngageInbox(reactContext))
13
+ }
14
+
15
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
+ return emptyList()
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+
2
+ #import <React/RCTBridgeModule.h>
3
+ #import <MoEPluginBase/MoEPluginBase.h>
4
+
5
+ @interface MoEngageInbox : NSObject <RCTBridgeModule>
6
+
7
+ @end
@@ -0,0 +1,42 @@
1
+ #import "MoEngageInbox.h"
2
+
3
+ @implementation MoEngageInbox
4
+
5
+ RCT_EXPORT_MODULE()
6
+
7
+ RCT_EXPORT_METHOD(fetchAllMessages:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter) {
8
+ [[MoEPluginBridge sharedInstance] getInboxMessagesWithCompletionBlock:^(NSDictionary *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:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter) {
21
+ NSInteger messageCount = [[MoEPluginBridge sharedInstance] getUnreadMessageCount];
22
+ NSDictionary *payload = @{@"unClickedCount": [NSNumber numberWithInteger:messageCount]};
23
+
24
+ NSError *err;
25
+ NSData * jsonData = [NSJSONSerialization dataWithJSONObject:payload options:0 error:&err];
26
+ if (jsonData) {
27
+ NSString *strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
28
+ resolver(strPayload);
29
+ } else {
30
+ rejecter(@"Error", @"Error in fetching inbox unclicked message count", [NSError errorWithDomain:@"" code:400 userInfo:@{@"Error reason": @"Error in fetching response"}]);
31
+ }
32
+ }
33
+
34
+ RCT_EXPORT_METHOD(trackMessageClicked:(NSDictionary *) campaignInfo) {
35
+ [[MoEPluginBridge sharedInstance] trackInboxClickForCampaign:campaignInfo];
36
+ }
37
+
38
+ RCT_EXPORT_METHOD(deleteMessage:(NSDictionary *) campaignInfo) {
39
+ [[MoEPluginBridge sharedInstance] deleteInboxEntryForCampaign:campaignInfo];
40
+ }
41
+
42
+ @end
@@ -0,0 +1,267 @@
1
+ // !$*UTF8*$!
2
+ {
3
+ archiveVersion = 1;
4
+ classes = {
5
+ };
6
+ objectVersion = 46;
7
+ objects = {
8
+
9
+ /* Begin PBXCopyFilesBuildPhase section */
10
+ 58B511D91A9E6C8500147676 /* CopyFiles */ = {
11
+ isa = PBXCopyFilesBuildPhase;
12
+ buildActionMask = 2147483647;
13
+ dstPath = "include/$(PRODUCT_NAME)";
14
+ dstSubfolderSpec = 16;
15
+ files = (
16
+ );
17
+ runOnlyForDeploymentPostprocessing = 0;
18
+ };
19
+ /* End PBXCopyFilesBuildPhase section */
20
+
21
+ /* Begin PBXFileReference section */
22
+ 134814201AA4EA6300B7C361 /* libMoEngageInbox.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMoEngageInbox.a; sourceTree = BUILT_PRODUCTS_DIR; };
23
+ B3E7B5881CC2AC0600A0062D /* MoEngageInbox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MoEngageInbox.h; sourceTree = "<group>"; };
24
+ B3E7B5891CC2AC0600A0062D /* MoEngageInbox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MoEngageInbox.m; sourceTree = "<group>"; };
25
+ /* End PBXFileReference section */
26
+
27
+ /* Begin PBXFrameworksBuildPhase section */
28
+ 58B511D81A9E6C8500147676 /* Frameworks */ = {
29
+ isa = PBXFrameworksBuildPhase;
30
+ buildActionMask = 2147483647;
31
+ files = (
32
+ );
33
+ runOnlyForDeploymentPostprocessing = 0;
34
+ };
35
+ /* End PBXFrameworksBuildPhase section */
36
+
37
+ /* Begin PBXGroup section */
38
+ 134814211AA4EA7D00B7C361 /* Products */ = {
39
+ isa = PBXGroup;
40
+ children = (
41
+ 134814201AA4EA6300B7C361 /* libMoEngageInbox.a */,
42
+ );
43
+ name = Products;
44
+ sourceTree = "<group>";
45
+ };
46
+ 58B511D21A9E6C8500147676 = {
47
+ isa = PBXGroup;
48
+ children = (
49
+ B3E7B5881CC2AC0600A0062D /* MoEngageInbox.h */,
50
+ B3E7B5891CC2AC0600A0062D /* MoEngageInbox.m */,
51
+ 134814211AA4EA7D00B7C361 /* Products */,
52
+ );
53
+ sourceTree = "<group>";
54
+ };
55
+ /* End PBXGroup section */
56
+
57
+ /* Begin PBXNativeTarget section */
58
+ 58B511DA1A9E6C8500147676 /* MoEngageInbox */ = {
59
+ isa = PBXNativeTarget;
60
+ buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "MoEngageInbox" */;
61
+ buildPhases = (
62
+ 58B511D71A9E6C8500147676 /* Sources */,
63
+ 58B511D81A9E6C8500147676 /* Frameworks */,
64
+ 58B511D91A9E6C8500147676 /* CopyFiles */,
65
+ );
66
+ buildRules = (
67
+ );
68
+ dependencies = (
69
+ );
70
+ name = MoEngageInbox;
71
+ productName = RCTDataManager;
72
+ productReference = 134814201AA4EA6300B7C361 /* libMoEngageInbox.a */;
73
+ productType = "com.apple.product-type.library.static";
74
+ };
75
+ /* End PBXNativeTarget section */
76
+
77
+ /* Begin PBXProject section */
78
+ 58B511D31A9E6C8500147676 /* Project object */ = {
79
+ isa = PBXProject;
80
+ attributes = {
81
+ LastUpgradeCheck = 0920;
82
+ ORGANIZATIONNAME = Facebook;
83
+ TargetAttributes = {
84
+ 58B511DA1A9E6C8500147676 = {
85
+ CreatedOnToolsVersion = 6.1.1;
86
+ };
87
+ };
88
+ };
89
+ buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "MoEngageInbox" */;
90
+ compatibilityVersion = "Xcode 3.2";
91
+ developmentRegion = English;
92
+ hasScannedForEncodings = 0;
93
+ knownRegions = (
94
+ English,
95
+ en,
96
+ );
97
+ mainGroup = 58B511D21A9E6C8500147676;
98
+ productRefGroup = 58B511D21A9E6C8500147676;
99
+ projectDirPath = "";
100
+ projectRoot = "";
101
+ targets = (
102
+ 58B511DA1A9E6C8500147676 /* MoEngageInbox */,
103
+ );
104
+ };
105
+ /* End PBXProject section */
106
+
107
+ /* Begin PBXSourcesBuildPhase section */
108
+ 58B511D71A9E6C8500147676 /* Sources */ = {
109
+ isa = PBXSourcesBuildPhase;
110
+ buildActionMask = 2147483647;
111
+ files = (
112
+ );
113
+ runOnlyForDeploymentPostprocessing = 0;
114
+ };
115
+ /* End PBXSourcesBuildPhase section */
116
+
117
+ /* Begin XCBuildConfiguration section */
118
+ 58B511ED1A9E6C8500147676 /* Debug */ = {
119
+ isa = XCBuildConfiguration;
120
+ buildSettings = {
121
+ ALWAYS_SEARCH_USER_PATHS = NO;
122
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
123
+ CLANG_CXX_LIBRARY = "libc++";
124
+ CLANG_ENABLE_MODULES = YES;
125
+ CLANG_ENABLE_OBJC_ARC = YES;
126
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
127
+ CLANG_WARN_BOOL_CONVERSION = YES;
128
+ CLANG_WARN_COMMA = YES;
129
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
130
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
131
+ CLANG_WARN_EMPTY_BODY = YES;
132
+ CLANG_WARN_ENUM_CONVERSION = YES;
133
+ CLANG_WARN_INFINITE_RECURSION = YES;
134
+ CLANG_WARN_INT_CONVERSION = YES;
135
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
136
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
137
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
138
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
139
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
140
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
141
+ CLANG_WARN_UNREACHABLE_CODE = YES;
142
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
143
+ COPY_PHASE_STRIP = NO;
144
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
145
+ ENABLE_TESTABILITY = YES;
146
+ GCC_C_LANGUAGE_STANDARD = gnu99;
147
+ GCC_DYNAMIC_NO_PIC = NO;
148
+ GCC_NO_COMMON_BLOCKS = YES;
149
+ GCC_OPTIMIZATION_LEVEL = 0;
150
+ GCC_PREPROCESSOR_DEFINITIONS = (
151
+ "DEBUG=1",
152
+ "$(inherited)",
153
+ );
154
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
155
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
156
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
157
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
158
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
159
+ GCC_WARN_UNUSED_FUNCTION = YES;
160
+ GCC_WARN_UNUSED_VARIABLE = YES;
161
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
162
+ MTL_ENABLE_DEBUG_INFO = YES;
163
+ ONLY_ACTIVE_ARCH = YES;
164
+ SDKROOT = iphoneos;
165
+ };
166
+ name = Debug;
167
+ };
168
+ 58B511EE1A9E6C8500147676 /* Release */ = {
169
+ isa = XCBuildConfiguration;
170
+ buildSettings = {
171
+ ALWAYS_SEARCH_USER_PATHS = NO;
172
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
173
+ CLANG_CXX_LIBRARY = "libc++";
174
+ CLANG_ENABLE_MODULES = YES;
175
+ CLANG_ENABLE_OBJC_ARC = YES;
176
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
177
+ CLANG_WARN_BOOL_CONVERSION = YES;
178
+ CLANG_WARN_COMMA = YES;
179
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
180
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
181
+ CLANG_WARN_EMPTY_BODY = YES;
182
+ CLANG_WARN_ENUM_CONVERSION = YES;
183
+ CLANG_WARN_INFINITE_RECURSION = YES;
184
+ CLANG_WARN_INT_CONVERSION = YES;
185
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
186
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
187
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
188
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
189
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
190
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
191
+ CLANG_WARN_UNREACHABLE_CODE = YES;
192
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
193
+ COPY_PHASE_STRIP = YES;
194
+ ENABLE_NS_ASSERTIONS = NO;
195
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
196
+ GCC_C_LANGUAGE_STANDARD = gnu99;
197
+ GCC_NO_COMMON_BLOCKS = YES;
198
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
199
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
200
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
201
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
202
+ GCC_WARN_UNUSED_FUNCTION = YES;
203
+ GCC_WARN_UNUSED_VARIABLE = YES;
204
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
205
+ MTL_ENABLE_DEBUG_INFO = NO;
206
+ SDKROOT = iphoneos;
207
+ VALIDATE_PRODUCT = YES;
208
+ };
209
+ name = Release;
210
+ };
211
+ 58B511F01A9E6C8500147676 /* Debug */ = {
212
+ isa = XCBuildConfiguration;
213
+ buildSettings = {
214
+ HEADER_SEARCH_PATHS = (
215
+ "$(inherited)",
216
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
217
+ "$(SRCROOT)/../../../React/**",
218
+ "$(SRCROOT)/../../react-native/React/**",
219
+ );
220
+ LIBRARY_SEARCH_PATHS = "$(inherited)";
221
+ OTHER_LDFLAGS = "-ObjC";
222
+ PRODUCT_NAME = MoEngageInbox;
223
+ SKIP_INSTALL = YES;
224
+ };
225
+ name = Debug;
226
+ };
227
+ 58B511F11A9E6C8500147676 /* Release */ = {
228
+ isa = XCBuildConfiguration;
229
+ buildSettings = {
230
+ HEADER_SEARCH_PATHS = (
231
+ "$(inherited)",
232
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
233
+ "$(SRCROOT)/../../../React/**",
234
+ "$(SRCROOT)/../../react-native/React/**",
235
+ );
236
+ LIBRARY_SEARCH_PATHS = "$(inherited)";
237
+ OTHER_LDFLAGS = "-ObjC";
238
+ PRODUCT_NAME = MoEngageInbox;
239
+ SKIP_INSTALL = YES;
240
+ };
241
+ name = Release;
242
+ };
243
+ /* End XCBuildConfiguration section */
244
+
245
+ /* Begin XCConfigurationList section */
246
+ 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "MoEngageInbox" */ = {
247
+ isa = XCConfigurationList;
248
+ buildConfigurations = (
249
+ 58B511ED1A9E6C8500147676 /* Debug */,
250
+ 58B511EE1A9E6C8500147676 /* Release */,
251
+ );
252
+ defaultConfigurationIsVisible = 0;
253
+ defaultConfigurationName = Release;
254
+ };
255
+ 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "MoEngageInbox" */ = {
256
+ isa = XCConfigurationList;
257
+ buildConfigurations = (
258
+ 58B511F01A9E6C8500147676 /* Debug */,
259
+ 58B511F11A9E6C8500147676 /* Release */,
260
+ );
261
+ defaultConfigurationIsVisible = 0;
262
+ defaultConfigurationName = Release;
263
+ };
264
+ /* End XCConfigurationList section */
265
+ };
266
+ rootObject = 58B511D31A9E6C8500147676 /* Project object */;
267
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "react-native-moengage-inbox",
3
+ "version": "1.1.0",
4
+ "description": "Inbox Module for the MoEngage Platform",
5
+ "main": "src/index.ts",
6
+ "files": [
7
+ "src",
8
+ "lib",
9
+ "android",
10
+ "ios",
11
+ "cpp",
12
+ "ReactNativeMoEngageInbox.podspec",
13
+ "!lib/typescript/example",
14
+ "!android/build",
15
+ "!ios/build",
16
+ "!**/__tests__",
17
+ "!**/__fixtures__",
18
+ "!**/__mocks__"
19
+ ],
20
+ "scripts": {
21
+ },
22
+ "keywords": [
23
+ "react-native",
24
+ "ios",
25
+ "android",
26
+ "moengage"
27
+ ],
28
+ "repository": "https://github.com/moengage/React-Native",
29
+ "author": "MoEngage <mobiledevs@moengage.com> (https://moengage.com)",
30
+ "publishConfig": {
31
+ "registry": "https://registry.npmjs.org/"
32
+ }
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { Platform } from "react-native";
2
+ import MoEInboxData from "../src/model/MoEInboxData";
3
+ import MoEInboxMessage from "../src/model/MoEInboxMessage";
4
+ import MoETextContent from "../src/model/MoETextContent";
5
+ import MoEMedia from "../src/model/MoEMedia";
6
+ import MoEAction from "../src/model/MoEAction";
7
+ import MoENavigationAction from "../src/model/MoENavigationAction";
8
+ import * as MoEInboxRNiOS from "./platform/MoEInboxRNiOS";
9
+ import { fetchEmptyInboxModel, fetchInboxJSON } from "./utils/MoEInboxParser"
10
+ import { MoEInboxRNAndroid } from "./platform/MoEInboxRNAndroid";
11
+
12
+ const PLATFORM_ANDROID = "android";
13
+ const PLATFORM_iOS = "ios";
14
+
15
+ var MoEReactInbox = {
16
+
17
+ fetchAllMessages: async function () {
18
+ try {
19
+ if (Platform.OS == PLATFORM_iOS) {
20
+ return await MoEInboxRNiOS.fetchAllMessages();
21
+ } else if (Platform.OS == PLATFORM_ANDROID) {
22
+ return await MoEInboxRNAndroid.fetchAllMessages()
23
+ }
24
+ }
25
+ catch (e) {
26
+ return (fetchEmptyInboxModel());
27
+ }
28
+ },
29
+
30
+ getUnClickedCount: async function () {
31
+ try {
32
+ if (Platform.OS == PLATFORM_iOS) {
33
+ return await MoEInboxRNiOS.getUnClickedCount();
34
+ } else if (Platform.OS == PLATFORM_ANDROID) {
35
+ return await MoEInboxRNAndroid.getUnClickedCount();
36
+ }
37
+ }
38
+ catch (e) {
39
+ return 0
40
+ }
41
+ },
42
+
43
+ trackMessageClicked: function (inboxMessage: MoEInboxMessage) {
44
+ var json = fetchInboxJSON(inboxMessage);
45
+ if (Platform.OS == PLATFORM_iOS) {
46
+ MoEInboxRNiOS.trackMessageClicked(json);
47
+ } else if (Platform.OS == PLATFORM_ANDROID) {
48
+ MoEInboxRNAndroid.trackMessageClicked(json)
49
+ }
50
+ },
51
+
52
+ deleteMessage: function (inboxMessage: MoEInboxMessage) {
53
+ var json = fetchInboxJSON(inboxMessage);
54
+ if (Platform.OS == PLATFORM_iOS) {
55
+ MoEInboxRNiOS.deleteMessage(json);
56
+ } else if (Platform.OS == PLATFORM_ANDROID) {
57
+ MoEInboxRNAndroid.deleteMessage(json)
58
+ }
59
+ }
60
+ };
61
+
62
+ export {
63
+ MoEInboxData,
64
+ MoEInboxMessage,
65
+ MoETextContent,
66
+ MoEMedia,
67
+ MoEAction,
68
+ MoENavigationAction
69
+ };
70
+
71
+ export default MoEReactInbox;
@@ -0,0 +1,6 @@
1
+ import MoENavigationAction from "./MoENavigationAction";
2
+
3
+ export default class MoEAction {
4
+ actionType: string;
5
+ action: MoENavigationAction;
6
+ }
@@ -0,0 +1,6 @@
1
+ import MoEInboxMessage from './MoEInboxMessage'
2
+
3
+ export default class MoEInboxData {
4
+ platform: String;
5
+ messages:Array<MoEInboxMessage> = [];
6
+ }
@@ -0,0 +1,16 @@
1
+ import MoETextContent from "./MoETextContent";
2
+ import MoEMedia from "./MoEMedia"
3
+ import MoEAction from "./MoEAction"
4
+
5
+ export default class MoEInboxMessage {
6
+ id: number;
7
+ campaignId: string;
8
+ textContent: MoETextContent;
9
+ isClicked: boolean;
10
+ media: MoEMedia;
11
+ action: Array<MoEAction> = [];
12
+ tag: string;
13
+ receivedTime: string;
14
+ expiry: string;
15
+ payload: Map<String, Object>;
16
+ }
@@ -0,0 +1,4 @@
1
+ export default class MoEMedia {
2
+ mediaType: string;
3
+ url: string;
4
+ }
@@ -0,0 +1,5 @@
1
+ export default class MoENavigationAction {
2
+ navigationType: string;
3
+ value: string;
4
+ kvPair: Map<String, Object>;
5
+ }
@@ -0,0 +1,6 @@
1
+ export default class MoETextContent {
2
+ title: string;
3
+ message: string;
4
+ summary: string;
5
+ subtitle: string;
6
+ }
@@ -0,0 +1,25 @@
1
+ import { fetchInboxModel, unClickedCountFromPayload } from "../utils/MoEInboxParser";
2
+
3
+ const MoEngageInbox = require("react-native").NativeModules.MoEngageInbox;
4
+
5
+ export class MoEInboxRNAndroid {
6
+
7
+ static async getUnClickedCount() {
8
+ const countPayload = await MoEngageInbox.getUnClickedCount()
9
+ return unClickedCountFromPayload(countPayload)
10
+ }
11
+
12
+ static async fetchAllMessages() {
13
+ const messages = await MoEngageInbox.fetchAllMessages()
14
+ return fetchInboxModel(messages)
15
+ }
16
+
17
+ static trackMessageClicked(inboxMessage: object) {
18
+ MoEngageInbox.trackMessageClicked(JSON.stringify(inboxMessage))
19
+ }
20
+
21
+ static deleteMessage(inboxMessage: object) {
22
+ MoEngageInbox.deleteMessage(JSON.stringify(inboxMessage))
23
+ }
24
+
25
+ }
@@ -0,0 +1,30 @@
1
+ import {fetchInboxModel, unClickedCountFromPayload} from "../utils/MoEInboxParser"
2
+ const MoEngageInbox = require("react-native").NativeModules.MoEngageInbox;
3
+
4
+ export const fetchAllMessages = () => {
5
+ return new Promise((resolve, reject) => {
6
+ MoEngageInbox.fetchAllMessages().then((inboxMessages) => {
7
+ resolve(fetchInboxModel(inboxMessages));
8
+ }).catch((error) => {
9
+ reject(error);
10
+ });
11
+ });
12
+ }
13
+
14
+ export const getUnClickedCount = () => {
15
+ return new Promise((resolve, reject) => {
16
+ MoEngageInbox.getUnClickedCount().then((countPayload) => {
17
+ resolve (unClickedCountFromPayload(countPayload));
18
+ }).catch((error) => {
19
+ reject(error);
20
+ });
21
+ });
22
+ }
23
+
24
+ export function trackMessageClicked(inboxInfo: Object) {
25
+ MoEngageInbox.trackMessageClicked(inboxInfo)
26
+ }
27
+
28
+ export function deleteMessage(inboxInfo: Object) {
29
+ MoEngageInbox.deleteMessage(inboxInfo)
30
+ }
@@ -0,0 +1,25 @@
1
+ export const ID = 'id'
2
+ export const MESSAGES = 'messages'
3
+ export const CAMPAIGN_ID = 'campaignId'
4
+ export const IS_CLICKED = 'isClicked'
5
+ export const RECEIVED_TIME = 'receivedTime'
6
+ export const EXPIRY = 'expiry'
7
+ export const TAG = 'tag'
8
+
9
+ export const MEDIA = 'media'
10
+ export const TYPE = 'type'
11
+ export const URL = 'url'
12
+
13
+ export const ACTION = 'action'
14
+ export const ACTION_TYPE = 'actionType'
15
+ export const NAVIGATION_TYPE = 'navigationType'
16
+ export const VALUE = 'value'
17
+ export const KV_PAIR = 'kvPair'
18
+
19
+ export const TEXT = 'text'
20
+ export const TITLE = 'title'
21
+ export const MESSAGE = 'message'
22
+ export const SUMMARY = 'summary'
23
+ export const SUBTITLE = 'subtitle'
24
+
25
+ export const PAYLOAD = 'payload'
@@ -0,0 +1,15 @@
1
+ export function isValidObject(value: any) {
2
+ return typeof value === "object" && Object.keys(value).length > 0;
3
+ }
4
+
5
+ export function isValidString(value: any): Boolean {
6
+ return typeof value === "string";
7
+ }
8
+
9
+ export function isValidNumber(value: any): Boolean {
10
+ return typeof value === "number";
11
+ }
12
+
13
+ export function isValidBoolean(value: any): Boolean {
14
+ return typeof value === "boolean";
15
+ }
@@ -0,0 +1,213 @@
1
+ import { Platform } from "react-native";
2
+ import MoEInboxData from "../model/MoEInboxData";
3
+ import MoEInboxMessage from "../model/MoEInboxMessage";
4
+ import MoETextContent from "../model/MoETextContent";
5
+ import MoEMedia from "../model/MoEMedia";
6
+ import MoEAction from "../model/MoEAction";
7
+ import MoENavigationAction from "../model/MoENavigationAction";
8
+ import * as InboxConstants from "../utils/MoEInboxConstants"
9
+ import { isValidObject, isValidString, isValidNumber } from "../utils/MoEInboxHelper";
10
+
11
+ const PLATFORM = 'platform'
12
+ const UNCLICKED_COUNT = 'unClickedCount'
13
+
14
+ export function fetchInboxModel(payload: any) {
15
+ const inboxJSON = JSON.parse(payload);
16
+
17
+ var inboxData = new MoEInboxData()
18
+
19
+ if (isValidObject(inboxJSON)) {
20
+
21
+ inboxData.platform = inboxJSON[PLATFORM];
22
+
23
+ var messages = inboxJSON[InboxConstants.MESSAGES];
24
+ for (var message of messages) {
25
+ inboxData.messages.push(fetchInboxMessageModel(message));
26
+ }
27
+ }
28
+
29
+ return inboxData
30
+ }
31
+
32
+ function fetchInboxMessageModel(message: Object) {
33
+ var inboxMessage = new MoEInboxMessage()
34
+
35
+ var id = message[InboxConstants.ID];
36
+ if (isValidNumber(id)) {
37
+ inboxMessage.id = id
38
+ } else {
39
+ inboxMessage.id = -1;
40
+ }
41
+
42
+ inboxMessage.campaignId = message[InboxConstants.CAMPAIGN_ID];
43
+ inboxMessage.isClicked = message[InboxConstants.IS_CLICKED];
44
+ inboxMessage.receivedTime = message[InboxConstants.RECEIVED_TIME];
45
+ inboxMessage.expiry = message[InboxConstants.EXPIRY];
46
+
47
+ if (isValidString(message[InboxConstants.TAG])) {
48
+ inboxMessage.tag = message[InboxConstants.TAG];
49
+ }
50
+
51
+ inboxMessage.textContent = fetchTextContentModel(message[InboxConstants.TEXT]);
52
+
53
+ var actions = message[InboxConstants.ACTION];
54
+ for (var action of actions) {
55
+ inboxMessage.action.push(fetchActionModel(action));
56
+ }
57
+
58
+ if (isValidObject(message[InboxConstants.MEDIA])) {
59
+ inboxMessage.media = fetchMediaModel(message[InboxConstants.MEDIA]);
60
+ }
61
+
62
+ if (isValidObject(message[InboxConstants.PAYLOAD])) {
63
+ inboxMessage.payload = message[InboxConstants.PAYLOAD];
64
+ }
65
+
66
+ return inboxMessage
67
+ }
68
+
69
+ function fetchMediaModel(mediaObject: Object) {
70
+ var media = new MoEMedia()
71
+
72
+ if (isValidString(mediaObject[InboxConstants.TYPE])) {
73
+ media.mediaType = mediaObject[InboxConstants.TYPE];
74
+ }
75
+
76
+ if (isValidString(mediaObject[InboxConstants.URL])) {
77
+ media.url = mediaObject[InboxConstants.URL];
78
+ }
79
+
80
+ return media
81
+ }
82
+
83
+ function fetchActionModel(actionObject: Object) {
84
+ var action = new MoEAction()
85
+
86
+ action.actionType = actionObject[InboxConstants.ACTION_TYPE];
87
+ action.action = fetchNavigationModel(actionObject);
88
+
89
+ return action
90
+ }
91
+
92
+ function fetchNavigationModel(navigationObject: Object) {
93
+ var navigation = new MoENavigationAction()
94
+
95
+ if (isValidString(navigationObject[InboxConstants.NAVIGATION_TYPE])) {
96
+ navigation.navigationType = navigationObject[InboxConstants.NAVIGATION_TYPE];
97
+ }
98
+ if (isValidString(navigationObject[InboxConstants.VALUE])) {
99
+ navigation.value = navigationObject[InboxConstants.VALUE];
100
+ }
101
+ if (isValidObject(navigationObject[InboxConstants.KV_PAIR])) {
102
+ navigation.kvPair = navigationObject[InboxConstants.KV_PAIR];
103
+ }
104
+
105
+ return navigation
106
+ }
107
+
108
+ function fetchTextContentModel(textContentObject: Object) {
109
+ var textContent = new MoETextContent()
110
+
111
+ if (isValidString(textContentObject[InboxConstants.TITLE])) {
112
+ textContent.title = textContentObject[InboxConstants.TITLE];
113
+ }
114
+
115
+ if (isValidString(textContentObject[InboxConstants.MESSAGE])) {
116
+ textContent.message = textContentObject[InboxConstants.MESSAGE];
117
+ }
118
+
119
+ if (isValidString(textContentObject[InboxConstants.SUMMARY])) {
120
+ textContent.summary = textContentObject[InboxConstants.SUMMARY];
121
+ }
122
+
123
+ if (isValidString(textContentObject[InboxConstants.SUBTITLE])) {
124
+ textContent.subtitle = textContentObject[InboxConstants.SUBTITLE];
125
+ }
126
+
127
+ return textContent
128
+ }
129
+
130
+ export function unClickedCountFromPayload(payload: string) {
131
+ const json = JSON.parse(payload);
132
+ return json[UNCLICKED_COUNT]
133
+ }
134
+
135
+ export function fetchInboxJSON(message: MoEInboxMessage) {
136
+ var json = {
137
+ id: message.id,
138
+ campaignId: message.campaignId,
139
+ isClicked: message.isClicked,
140
+ tag: message.tag,
141
+ receivedTime: message.receivedTime,
142
+ expiry: message.expiry
143
+ };
144
+
145
+ if (isValidObject(message.textContent)) {
146
+ json[InboxConstants.TEXT] = textContentToJSON(message.textContent);
147
+ }
148
+
149
+ if (isValidObject(message.media)) {
150
+ json[InboxConstants.MEDIA] = mediaToJSON(message.media);
151
+ }
152
+
153
+ if (isValidObject(message.payload)) {
154
+ json[InboxConstants.PAYLOAD] = message.payload
155
+ }
156
+
157
+ if (isValidObject(message.action)) {
158
+ var inboxActions = Array<Object>();
159
+ for (var inboxAction of message.action) {
160
+ inboxActions.push(actionToJSON(inboxAction));
161
+ }
162
+ json[InboxConstants.ACTION] = inboxActions;
163
+ }
164
+
165
+ return json;
166
+ }
167
+
168
+ function textContentToJSON(textContent: MoETextContent) {
169
+ var json = {
170
+ title: textContent.title,
171
+ message: textContent.message,
172
+ summary: textContent.summary,
173
+ subtitle: textContent.subtitle,
174
+ };
175
+
176
+ return json;
177
+ }
178
+
179
+ function mediaToJSON(media: MoEMedia) {
180
+ var json = {
181
+ type: media.mediaType,
182
+ url: media.url
183
+ }
184
+
185
+ return json
186
+ }
187
+
188
+ function actionToJSON(action : MoEAction) {
189
+ var json = {
190
+ actionType: action.actionType
191
+ }
192
+
193
+ if (isValidObject(action.action)) {
194
+ var navigationJSON = navigationActionToJSON(action.action)
195
+ Object.assign(json, navigationJSON);
196
+ }
197
+
198
+ return json;
199
+ }
200
+
201
+ function navigationActionToJSON(navigation: MoENavigationAction){
202
+ return {
203
+ navigationType: navigation.navigationType,
204
+ value: navigation.value,
205
+ kvPair: navigation.kvPair,
206
+ };
207
+ }
208
+
209
+ export function fetchEmptyInboxModel() {
210
+ var inboxData = new MoEInboxData();
211
+ inboxData.platform = Platform.OS;
212
+ return inboxData
213
+ }