Skip to content

Commit

Permalink
feat(messaging, android): add priority + originalPriority to RemoteMe…
Browse files Browse the repository at this point in the history
…ssage

messages may be sent as high priority but downgraded to normal priority on
delivery and it is very important for applications to know this

if a priority is downgraded from high to normal, the application may not
start foreground services and the app will crash if a foreground start is
attempted

see invertase/notifee#470
  • Loading branch information
mikehardy committed Oct 21, 2024
1 parent 3f2778c commit c324932
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ReactNativeFirebaseMessagingSerializer {
private static final String KEY_ERROR = "error";
private static final String KEY_TO = "to";
private static final String KEY_TTL = "ttl";
private static final String KEY_PRIORITY = "priority";
private static final String KEY_ORIGINAL_PRIORITY = "originalPriority";
private static final String EVENT_MESSAGE_SENT = "messaging_message_sent";
private static final String EVENT_MESSAGES_DELETED = "messaging_message_deleted";
private static final String EVENT_MESSAGE_RECEIVED = "messaging_message_received";
Expand Down Expand Up @@ -99,6 +101,8 @@ static WritableMap remoteMessageToWritableMap(RemoteMessage remoteMessage) {
messageMap.putMap(KEY_DATA, dataMap);
messageMap.putDouble(KEY_TTL, remoteMessage.getTtl());
messageMap.putDouble(KEY_SENT_TIME, remoteMessage.getSentTime());
messageMap.putInt(KEY_PRIORITY, remoteMessage.getPriority());
messageMap.putInt(KEY_ORIGINAL_PRIORITY, remoteMessage.getOriginalPriority());

if (remoteMessage.getNotification() != null) {
messageMap.putMap(
Expand Down
40 changes: 40 additions & 0 deletions packages/messaging/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,46 @@ export namespace FirebaseMessagingTypes {
* Options for features provided by the FCM SDK for Web.
*/
fcmOptions: FcmOptions;

/**
* Priority - android-specific, undefined on non-android platforms, default PRIORITY_UNKNOWN
*/
priority?: MessagePriority;

/**
* Original priority - android-specific, undefined on non-android platforms, default PRIORITY_UNKNOWN
*/
originalPriority?: MessagePriority;
}

/**
* Represents the priority of a RemoteMessage
*
* Note: this is an android-specific property of RemoteMessages
*
* See https://github.com/firebase/firebase-android-sdk/blob/b6d01070d246b74f02c42da5691f99f52763e48b/firebase-messaging/src/main/java/com/google/firebase/messaging/RemoteMessage.java#L57-L64
*
* Example:
*
* ```js
* firebase.messaging.MessagePriority.PRIORITY_NORMAL;
* ```
*/
export enum MessagePriority {
/**
* Unknown priority, this will be returned as the default on non-android platforms
*/
PRIORITY_UNKNOWN = 0,

/**
* High priority - Activities may start foreground services if they receive high priority messages
*/
PRIORITY_HIGH = 1,

/**
* Normal priority - Activities have restrictions and may only perform unobtrusive actions on receipt
*/
PRIORITY_NORMAL = 2,
}

/**
Expand Down

0 comments on commit c324932

Please sign in to comment.