diff --git a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java index 3824054ad..f85794e81 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java @@ -24,8 +24,9 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.NotificationIntentAdapter; @@ -45,8 +46,12 @@ public class CustomPushNotification extends PushNotification { private NotificationChannel mHighImportanceChannel; private NotificationChannel mMinImportanceChannel; - private static LinkedHashMap channelIdToNotificationCount = new LinkedHashMap(); - private static LinkedHashMap> channelIdToNotification = new LinkedHashMap>(); + private static final String PUSH_TYPE_MESSAGE = "message"; + private static final String PUSH_TYPE_CLEAR = "clear"; + private static final String PUSH_TYPE_UPDATE_BADGE = "update_badge"; + + private static Map channelIdToNotificationCount = new HashMap(); + private static Map> channelIdToNotification = new HashMap>(); private static AppLifecycleFacade lifecycleFacade; private static Context context; private static int badgeCount = 0; @@ -59,11 +64,9 @@ public class CustomPushNotification extends PushNotification { public static void clearNotification(Context mContext, int notificationId, String channelId) { if (notificationId != -1) { - Object objCount = channelIdToNotificationCount.get(channelId); - Integer count = -1; - - if (objCount != null) { - count = (Integer)objCount; + Integer count = channelIdToNotificationCount.get(channelId); + if (count == null) { + count = -1; } channelIdToNotificationCount.remove(channelId); @@ -105,23 +108,26 @@ public class CustomPushNotification extends PushNotification { if (channelId != null) { notificationId = channelId.hashCode(); - Object objCount = channelIdToNotificationCount.get(channelId); - Integer count = 1; - if (objCount != null) { - count = (Integer)objCount + 1; - } - channelIdToNotificationCount.put(channelId, count); - Object bundleArray = channelIdToNotification.get(channelId); - List list = null; - if (bundleArray == null) { - list = Collections.synchronizedList(new ArrayList(0)); - } else { - list = Collections.synchronizedList((List)bundleArray); + synchronized (channelIdToNotificationCount) { + Integer count = channelIdToNotificationCount.get(channelId); + if (count == null) { + count = 0; + } + + count += 1; + + channelIdToNotificationCount.put(channelId, count); } - synchronized (list) { - if (!"clear".equals(type)) { - String senderName = getSenderName(data); + + synchronized (channelIdToNotification) { + List list = channelIdToNotification.get(channelId); + if (list == null) { + list = Collections.synchronizedList(new ArrayList(0)); + } + + if (PUSH_TYPE_MESSAGE.equals(type)) { + String senderName = getSenderName(data.getString("sender_name"), data.getString("channel_name"), data.getString("message")); data.putLong("time", new Date().getTime()); data.putString("sender_name", senderName); data.putString("sender_id", data.getString("sender_id")); @@ -131,10 +137,13 @@ public class CustomPushNotification extends PushNotification { } } - if ("clear".equals(type)) { - cancelNotification(data, notificationId); - } else { + switch(type) { + case PUSH_TYPE_MESSAGE: super.postNotification(notificationId); + break; + case PUSH_TYPE_CLEAR: + cancelNotification(data, notificationId); + break; } notifyReceivedToJS(); diff --git a/ios/Mattermost/AppDelegate.m b/ios/Mattermost/AppDelegate.m index 9222f9e7b..357d84cb7 100644 --- a/ios/Mattermost/AppDelegate.m +++ b/ios/Mattermost/AppDelegate.m @@ -26,7 +26,9 @@ @implementation AppDelegate +NSString* const NOTIFICATION_MESSAGE_ACTION = @"message"; NSString* const NOTIFICATION_CLEAR_ACTION = @"clear"; +NSString* const NOTIFICATION_UPDATE_BADGE_ACTION = @"update_badge"; -(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler { os_log(OS_LOG_DEFAULT, "Mattermost will attach session from handleEventsForBackgroundURLSession!! identifier=%{public}@", identifier);