[MM-16232] ID loaded push notifications (#3562)

* [MM-16232] Android: Fetch notification in notificationReceiptDelivery (#3552)

* Fetch notification in notificationReceiptDelivery

* Fix patch

* Fix patch take 2

* No need to send user_id to ack endpoint

* Just putString in mNotificationProps

* Fix patch take 3

* Revert react-native-notifications patch

* Update patch and fix rejections

* Remove trailing newline in patch

* Move PushNotification changes to end of patch

* npm cache test

* Revert "npm cache test"

This reverts commit d31030aaee.

* Created patch after upgrading node

* Created patch after upgrading node take 2

* Remove androidx changes from patch

* Patch packages then jetify

* Cache node_modules without patches

* Remove adding of default message (#3557)

* [MM-16232] iOS: Fetch id-loaded push notification from server (#3556)

* Fetch notification from server

* Parse fetched notification response

* Fix id-loaded notifications for DM/GM's

* audit fix

* Only add keys if they exist

* Throw exception if response code is not 200
This commit is contained in:
Miguel Alatzar
2019-11-18 14:29:49 -08:00
committed by Elias Nahum
parent 84a874918d
commit ba76e5eac7
8 changed files with 134 additions and 37 deletions

View File

@@ -20,6 +20,8 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Build;
import android.provider.Settings.System;
import androidx.annotation.Nullable;
import android.util.Log;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
@@ -35,6 +37,9 @@ import com.wix.reactnativenotifications.core.JsIOHelper;
import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME;
import com.mattermost.react_native_interface.ResolvePromise;
import com.facebook.react.bridge.WritableMap;
public class CustomPushNotification extends PushNotification {
public static final int MESSAGE_NOTIFICATION_ID = 435345;
public static final String GROUP_KEY_MESSAGES = "mm_group_key_messages";
@@ -42,6 +47,8 @@ public class CustomPushNotification extends PushNotification {
public static final String KEY_TEXT_REPLY = "CAN_REPLY";
public static final String NOTIFICATION_REPLIED_EVENT_NAME = "notificationReplied";
private static final String PUSH_TYPE_ID_LOADED = "id_loaded";
private NotificationChannel mHighImportanceChannel;
private NotificationChannel mMinImportanceChannel;
@@ -93,16 +100,34 @@ public class CustomPushNotification extends PushNotification {
@Override
public void onReceived() throws InvalidNotificationException {
Bundle data = mNotificationProps.asBundle();
final String channelId = data.getString("channel_id");
final String type = data.getString("type");
final String ackId = data.getString("ack_id");
final Bundle initialData = mNotificationProps.asBundle();
final String type = initialData.getString("type");
final String ackId = initialData.getString("ack_id");
final String postId = initialData.getString("post_id");
final String channelId = initialData.getString("channel_id");
int notificationId = MESSAGE_NOTIFICATION_ID;
if (ackId != null) {
notificationReceiptDelivery(ackId, type);
notificationReceiptDelivery(ackId, postId, type, new ResolvePromise() {
@Override
public void resolve(@Nullable Object value) {
if (PUSH_TYPE_ID_LOADED.equals(type)) {
Bundle response = (Bundle) value;
mNotificationProps = createProps(response);
}
}
@Override
public void reject(String code, String message) {
Log.e("ReactNative", code + ": " + message);
}
});
}
// notificationReceiptDelivery can override mNotificationProps
// so we fetch the bundle again
final Bundle data = mNotificationProps.asBundle();
if (channelId != null) {
notificationId = channelId.hashCode();
Object objCount = channelIdToNotificationCount.get(channelId);
@@ -493,8 +518,8 @@ public class CustomPushNotification extends PushNotification {
return message.replaceFirst(senderName, "").replaceFirst(": ", "").trim();
}
private void notificationReceiptDelivery(String ackId, String type) {
ReceiptDelivery.send(context, ackId, type);
private void notificationReceiptDelivery(String ackId, String postId, String type, ResolvePromise promise) {
ReceiptDelivery.send(context, ackId, postId, type, promise);
}
private void createNotificationChannels() {