Commit ca7143a4 authored by Libin Lu's avatar Libin Lu

bump version

parent de31a2c1
...@@ -38,7 +38,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -38,7 +38,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
private final static String TAG = FIRMessagingModule.class.getCanonicalName(); private final static String TAG = FIRMessagingModule.class.getCanonicalName();
private FIRLocalMessagingHelper mFIRLocalMessagingHelper; private FIRLocalMessagingHelper mFIRLocalMessagingHelper;
private BadgeHelper mBadgeHelper; private BadgeHelper mBadgeHelper;
public FIRMessagingModule(ReactApplicationContext reactContext) { public FIRMessagingModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
mFIRLocalMessagingHelper = new FIRLocalMessagingHelper((Application) reactContext.getApplicationContext()); mFIRLocalMessagingHelper = new FIRLocalMessagingHelper((Application) reactContext.getApplicationContext());
...@@ -49,12 +49,12 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -49,12 +49,12 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
registerMessageHandler(); registerMessageHandler();
registerLocalMessageHandler(); registerLocalMessageHandler();
} }
@Override @Override
public String getName() { public String getName() {
return "RNFIRMessaging"; return "RNFIRMessaging";
} }
@ReactMethod @ReactMethod
public void getInitialNotification(Promise promise){ public void getInitialNotification(Promise promise){
Activity activity = getCurrentActivity(); Activity activity = getCurrentActivity();
...@@ -65,7 +65,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -65,7 +65,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
} }
promise.resolve(parseIntent(activity.getIntent())); promise.resolve(parseIntent(activity.getIntent()));
} }
@ReactMethod @ReactMethod
public void requestPermissions(Promise promise){ public void requestPermissions(Promise promise){
if(NotificationManagerCompat.from(getReactApplicationContext()).areNotificationsEnabled()){ if(NotificationManagerCompat.from(getReactApplicationContext()).areNotificationsEnabled()){
...@@ -74,7 +74,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -74,7 +74,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
promise.reject(null, "Notification disabled"); promise.reject(null, "Notification disabled");
} }
} }
@ReactMethod @ReactMethod
public void getFCMToken(Promise promise) { public void getFCMToken(Promise promise) {
try { try {
...@@ -85,7 +85,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -85,7 +85,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
promise.reject(null,e.getMessage()); promise.reject(null,e.getMessage());
} }
} }
@ReactMethod @ReactMethod
public void deleteInstanceId(Promise promise){ public void deleteInstanceId(Promise promise){
try { try {
...@@ -96,19 +96,19 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -96,19 +96,19 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
promise.reject(null,e.getMessage()); promise.reject(null,e.getMessage());
} }
} }
@ReactMethod @ReactMethod
public void presentLocalNotification(ReadableMap details) { public void presentLocalNotification(ReadableMap details) {
Bundle bundle = Arguments.toBundle(details); Bundle bundle = Arguments.toBundle(details);
mFIRLocalMessagingHelper.sendNotification(bundle); mFIRLocalMessagingHelper.sendNotification(bundle);
} }
@ReactMethod @ReactMethod
public void scheduleLocalNotification(ReadableMap details) { public void scheduleLocalNotification(ReadableMap details) {
Bundle bundle = Arguments.toBundle(details); Bundle bundle = Arguments.toBundle(details);
mFIRLocalMessagingHelper.sendNotificationScheduled(bundle); mFIRLocalMessagingHelper.sendNotificationScheduled(bundle);
} }
@ReactMethod @ReactMethod
public void cancelLocalNotification(String notificationID) { public void cancelLocalNotification(String notificationID) {
mFIRLocalMessagingHelper.cancelLocalNotification(notificationID); mFIRLocalMessagingHelper.cancelLocalNotification(notificationID);
...@@ -117,27 +117,27 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -117,27 +117,27 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
public void cancelAllLocalNotifications() { public void cancelAllLocalNotifications() {
mFIRLocalMessagingHelper.cancelAllLocalNotifications(); mFIRLocalMessagingHelper.cancelAllLocalNotifications();
} }
@ReactMethod @ReactMethod
public void removeDeliveredNotification(String notificationID) { public void removeDeliveredNotification(String notificationID) {
mFIRLocalMessagingHelper.removeDeliveredNotification(notificationID); mFIRLocalMessagingHelper.removeDeliveredNotification(notificationID);
} }
@ReactMethod @ReactMethod
public void removeAllDeliveredNotifications(){ public void removeAllDeliveredNotifications(){
mFIRLocalMessagingHelper.removeAllDeliveredNotifications(); mFIRLocalMessagingHelper.removeAllDeliveredNotifications();
} }
@ReactMethod @ReactMethod
public void subscribeToTopic(String topic){ public void subscribeToTopic(String topic){
FirebaseMessaging.getInstance().subscribeToTopic(topic); FirebaseMessaging.getInstance().subscribeToTopic(topic);
} }
@ReactMethod @ReactMethod
public void unsubscribeFromTopic(String topic){ public void unsubscribeFromTopic(String topic){
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic); FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
} }
@ReactMethod @ReactMethod
public void getScheduledLocalNotifications(Promise promise){ public void getScheduledLocalNotifications(Promise promise){
ArrayList<Bundle> bundles = mFIRLocalMessagingHelper.getScheduledLocalNotifications(); ArrayList<Bundle> bundles = mFIRLocalMessagingHelper.getScheduledLocalNotifications();
...@@ -147,23 +147,23 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -147,23 +147,23 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
} }
promise.resolve(array); promise.resolve(array);
} }
@ReactMethod @ReactMethod
public void setBadgeNumber(int badgeNumber) { public void setBadgeNumber(int badgeNumber) {
mBadgeHelper.setBadgeCount(badgeNumber); mBadgeHelper.setBadgeCount(badgeNumber);
} }
@ReactMethod @ReactMethod
public void getBadgeNumber(Promise promise) { public void getBadgeNumber(Promise promise) {
promise.resolve(mBadgeHelper.getBadgeCount()); promise.resolve(mBadgeHelper.getBadgeCount());
} }
private void sendEvent(String eventName, Object params) { private void sendEvent(String eventName, Object params) {
getReactApplicationContext() getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params); .emit(eventName, params);
} }
private void registerTokenRefreshHandler() { private void registerTokenRefreshHandler() {
IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.FCMRefreshToken"); IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.FCMRefreshToken");
getReactApplicationContext().registerReceiver(new BroadcastReceiver() { getReactApplicationContext().registerReceiver(new BroadcastReceiver() {
...@@ -176,13 +176,13 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -176,13 +176,13 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
} }
}, intentFilter); }, intentFilter);
} }
@ReactMethod @ReactMethod
public void send(String senderId, ReadableMap payload) throws Exception { public void send(String senderId, ReadableMap payload) throws Exception {
FirebaseMessaging fm = FirebaseMessaging.getInstance(); FirebaseMessaging fm = FirebaseMessaging.getInstance();
RemoteMessage.Builder message = new RemoteMessage.Builder(senderId + "@gcm.googleapis.com") RemoteMessage.Builder message = new RemoteMessage.Builder(senderId + "@gcm.googleapis.com")
.setMessageId(UUID.randomUUID().toString()); .setMessageId(UUID.randomUUID().toString());
ReadableMapKeySetIterator iterator = payload.keySetIterator(); ReadableMapKeySetIterator iterator = payload.keySetIterator();
while (iterator.hasNextKey()) { while (iterator.hasNextKey()) {
String key = iterator.nextKey(); String key = iterator.nextKey();
...@@ -191,7 +191,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -191,7 +191,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
} }
fm.send(message.build()); fm.send(message.build());
} }
private String getStringFromReadableMap(ReadableMap map, String key) throws Exception { private String getStringFromReadableMap(ReadableMap map, String key) throws Exception {
switch (map.getType(key)) { switch (map.getType(key)) {
case String: case String:
...@@ -208,10 +208,10 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -208,10 +208,10 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
throw new Exception("Unknown data type: " + map.getType(key).name() + " for message key " + key ); throw new Exception("Unknown data type: " + map.getType(key).name() + " for message key " + key );
} }
} }
private void registerMessageHandler() { private void registerMessageHandler() {
IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.ReceiveNotification"); IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.ReceiveNotification");
getReactApplicationContext().registerReceiver(new BroadcastReceiver() { getReactApplicationContext().registerReceiver(new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
...@@ -219,7 +219,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -219,7 +219,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
RemoteMessage message = intent.getParcelableExtra("data"); RemoteMessage message = intent.getParcelableExtra("data");
WritableMap params = Arguments.createMap(); WritableMap params = Arguments.createMap();
WritableMap fcmData = Arguments.createMap(); WritableMap fcmData = Arguments.createMap();
if (message.getNotification() != null) { if (message.getNotification() != null) {
Notification notification = message.getNotification(); Notification notification = message.getNotification();
fcmData.putString("title", notification.getTitle()); fcmData.putString("title", notification.getTitle());
...@@ -234,7 +234,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -234,7 +234,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
params.putString("from", message.getFrom()); params.putString("from", message.getFrom());
params.putString("google.message_id", message.getMessageId()); params.putString("google.message_id", message.getMessageId());
params.putDouble("google.sent_time", message.getSentTime()); params.putDouble("google.sent_time", message.getSentTime());
if(message.getData() != null){ if(message.getData() != null){
Map<String, String> data = message.getData(); Map<String, String> data = message.getData();
Set<String> keysIterator = data.keySet(); Set<String> keysIterator = data.keySet();
...@@ -243,15 +243,15 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -243,15 +243,15 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
} }
} }
sendEvent("FCMNotificationReceived", params); sendEvent("FCMNotificationReceived", params);
} }
} }
}, intentFilter); }, intentFilter);
} }
private void registerLocalMessageHandler() { private void registerLocalMessageHandler() {
IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.ReceiveLocalNotification"); IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.ReceiveLocalNotification");
getReactApplicationContext().registerReceiver(new BroadcastReceiver() { getReactApplicationContext().registerReceiver(new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
...@@ -261,7 +261,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -261,7 +261,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
} }
}, intentFilter); }, intentFilter);
} }
private WritableMap parseIntent(Intent intent){ private WritableMap parseIntent(Intent intent){
WritableMap params; WritableMap params;
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
...@@ -278,30 +278,30 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -278,30 +278,30 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
WritableMap fcm = Arguments.createMap(); WritableMap fcm = Arguments.createMap();
fcm.putString("action", intent.getAction()); fcm.putString("action", intent.getAction());
params.putMap("fcm", fcm); params.putMap("fcm", fcm);
params.putInt("opened_from_tray", 1); params.putInt("opened_from_tray", 1);
return params; return params;
} }
@Override @Override
public void onHostResume() { public void onHostResume() {
mFIRLocalMessagingHelper.setApplicationForeground(true); mFIRLocalMessagingHelper.setApplicationForeground(true);
} }
@Override @Override
public void onHostPause() { public void onHostPause() {
mFIRLocalMessagingHelper.setApplicationForeground(false); mFIRLocalMessagingHelper.setApplicationForeground(false);
} }
@Override @Override
public void onHostDestroy() { public void onHostDestroy() {
} }
@Override @Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
} }
@Override @Override
public void onNewIntent(Intent intent){ public void onNewIntent(Intent intent){
// don't call notification if it is started from icon // don't call notification if it is started from icon
...@@ -311,3 +311,4 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -311,3 +311,4 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
sendEvent("FCMNotificationReceived", parseIntent(intent)); sendEvent("FCMNotificationReceived", parseIntent(intent));
} }
} }
...@@ -24,5 +24,5 @@ ...@@ -24,5 +24,5 @@
"type": "git", "type": "git",
"url": "git+https://github.com/evollu/react-native-fcm.git" "url": "git+https://github.com/evollu/react-native-fcm.git"
}, },
"version": "9.6.0" "version": "9.6.1"
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment