Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Update the package name
Browse files Browse the repository at this point in the history
  • Loading branch information
el173 committed Apr 7, 2020
1 parent 84c4862 commit d4975cc
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smooch.rnsmooch">
package="com.el173.rnsmooch">
</manifest>
119 changes: 119 additions & 0 deletions android/src/main/java/com/smooch/rnsmooch/ReactNativeSmooch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.el173.rnsmooch;

import android.content.Intent;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.Promise;

import java.util.HashMap;
import java.util.Map;

import io.smooch.core.Smooch;
import io.smooch.core.SmoochCallback;
import io.smooch.core.User;
import io.smooch.ui.ConversationActivity;

public class ReactNativeSmooch extends ReactContextBaseJavaModule {
@Override
public String getName() {
return "SmoochManager";
}

public ReactNativeSmooch(ReactApplicationContext reactContext) {
super(reactContext);
}

@ReactMethod
public void login(String userId, String jwt, final Promise promise) {
Smooch.login(userId, jwt, new SmoochCallback() {
@Override
public void run(Response response) {
if (promise != null) {
if (response.getError() != null) {
promise.reject("" + response.getStatus(), response.getError());
return;
}

promise.resolve(null);
}
}
});
}

@ReactMethod
public void logout(final Promise promise) {
Smooch.logout(new SmoochCallback() {
@Override
public void run(Response response) {
if (response.getError() != null) {
promise.reject("" + response.getStatus(), response.getError());
return;
}

promise.resolve(null);
}
});
}

@ReactMethod
public void show() {
ConversationActivity.show(getReactApplicationContext(), Intent.FLAG_ACTIVITY_NEW_TASK);
// ConversationActivity.builder().withFlags(Intent.FLAG_ACTIVITY_NEW_TASK).show(getReactApplicationContext());
}

@ReactMethod
public void close() {
ConversationActivity.close();
}

@ReactMethod
public void getUnreadCount(Promise promise) {
int unreadCount = Smooch.getConversation().getUnreadCount();
promise.resolve(unreadCount);
}

@ReactMethod
public void setFirstName(String firstName) {
User.getCurrentUser().setFirstName(firstName);
}

@ReactMethod
public void setLastName(String lastName) {
User.getCurrentUser().setLastName(lastName);
}

@ReactMethod
public void setEmail(String email) {
User.getCurrentUser().setEmail(email);
}

@ReactMethod
public void setUserProperties(ReadableMap properties) {
User.getCurrentUser().addProperties(getUserProperties(properties));
}

private Map<String, Object> getUserProperties(ReadableMap properties) {
ReadableMapKeySetIterator iterator = properties.keySetIterator();
Map<String, Object> userProperties = new HashMap<>();

while (iterator.hasNextKey()) {
String key = iterator.nextKey();
ReadableType type = properties.getType(key);
if (type == ReadableType.Boolean) {
userProperties.put(key, properties.getBoolean(key));
} else if (type == ReadableType.Number) {
userProperties.put(key, properties.getDouble(key));
} else if (type == ReadableType.String) {
userProperties.put(key, properties.getString(key));
}
}

return userProperties;
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@el173/react-native-smooch",
"version": "1.1.0",
"version": "1.1.1",
"description": "A React Native client for smooch.io",
"main": "./lib/SmoochClient.js",
"repository": {
Expand Down

0 comments on commit d4975cc

Please sign in to comment.