Skip to content

Commit c324932

Browse files
committed
feat(messaging, android): add priority + originalPriority to RemoteMessage
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
1 parent 3f2778c commit c324932

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingSerializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class ReactNativeFirebaseMessagingSerializer {
2121
private static final String KEY_ERROR = "error";
2222
private static final String KEY_TO = "to";
2323
private static final String KEY_TTL = "ttl";
24+
private static final String KEY_PRIORITY = "priority";
25+
private static final String KEY_ORIGINAL_PRIORITY = "originalPriority";
2426
private static final String EVENT_MESSAGE_SENT = "messaging_message_sent";
2527
private static final String EVENT_MESSAGES_DELETED = "messaging_message_deleted";
2628
private static final String EVENT_MESSAGE_RECEIVED = "messaging_message_received";
@@ -99,6 +101,8 @@ static WritableMap remoteMessageToWritableMap(RemoteMessage remoteMessage) {
99101
messageMap.putMap(KEY_DATA, dataMap);
100102
messageMap.putDouble(KEY_TTL, remoteMessage.getTtl());
101103
messageMap.putDouble(KEY_SENT_TIME, remoteMessage.getSentTime());
104+
messageMap.putInt(KEY_PRIORITY, remoteMessage.getPriority());
105+
messageMap.putInt(KEY_ORIGINAL_PRIORITY, remoteMessage.getOriginalPriority());
102106

103107
if (remoteMessage.getNotification() != null) {
104108
messageMap.putMap(

packages/messaging/lib/index.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,46 @@ export namespace FirebaseMessagingTypes {
147147
* Options for features provided by the FCM SDK for Web.
148148
*/
149149
fcmOptions: FcmOptions;
150+
151+
/**
152+
* Priority - android-specific, undefined on non-android platforms, default PRIORITY_UNKNOWN
153+
*/
154+
priority?: MessagePriority;
155+
156+
/**
157+
* Original priority - android-specific, undefined on non-android platforms, default PRIORITY_UNKNOWN
158+
*/
159+
originalPriority?: MessagePriority;
160+
}
161+
162+
/**
163+
* Represents the priority of a RemoteMessage
164+
*
165+
* Note: this is an android-specific property of RemoteMessages
166+
*
167+
* See https://github.com/firebase/firebase-android-sdk/blob/b6d01070d246b74f02c42da5691f99f52763e48b/firebase-messaging/src/main/java/com/google/firebase/messaging/RemoteMessage.java#L57-L64
168+
*
169+
* Example:
170+
*
171+
* ```js
172+
* firebase.messaging.MessagePriority.PRIORITY_NORMAL;
173+
* ```
174+
*/
175+
export enum MessagePriority {
176+
/**
177+
* Unknown priority, this will be returned as the default on non-android platforms
178+
*/
179+
PRIORITY_UNKNOWN = 0,
180+
181+
/**
182+
* High priority - Activities may start foreground services if they receive high priority messages
183+
*/
184+
PRIORITY_HIGH = 1,
185+
186+
/**
187+
* Normal priority - Activities have restrictions and may only perform unobtrusive actions on receipt
188+
*/
189+
PRIORITY_NORMAL = 2,
150190
}
151191

152192
/**

0 commit comments

Comments
 (0)