Skip to content

Commit eac11c6

Browse files
amabluea-maurice
authored andcommitted
Added channel_id to Messaging notifications.
PiperOrigin-RevId: 250583162
1 parent fde87af commit eac11c6

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

messaging/src/android/cpp/message_reader.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ void MessageReader::ConsumeMessage(
109109
const SerializedMessage* serialized_message) const {
110110
Message message;
111111
Notification notification;
112+
AndroidNotificationParams android;
112113
message.from = SafeFlatbufferString(serialized_message->from());
113114
message.to = SafeFlatbufferString(serialized_message->to());
114115
if (serialized_message->data()) {
@@ -171,18 +172,24 @@ void MessageReader::ConsumeMessage(
171172
serialized_notification->title_loc_args()->Get(i));
172173
}
173174
}
175+
android.channel_id =
176+
SafeFlatbufferString(serialized_notification->android_channel_id());
174177

175178
// The notification has been allocated on the stack for speed. Set this
176179
// pointer to null before the notification leaves scope or it will be
177180
// deleted.
181+
notification.android = &android;
178182
message.notification = &notification;
179183
}
180184

181185
// Finally, process the message.
182186
message_callback_(message, message_callback_data_);
183187
// Ensure that the stack allocated pointer is null before it goes out of
184188
// scope so it doesn't get deleted.
185-
message.notification = nullptr;
189+
if (message.notification) {
190+
message.notification->android = nullptr;
191+
message.notification = nullptr;
192+
}
186193
}
187194

188195
// Convert the SerializedTokenReceived to a token and calls the registered

messaging/src/android/java/com/google/firebase/messaging/cpp/MessageWriter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ private static byte[] generateMessageByteBuffer(
243243
int tagOffset = builder.createString(emptyIfNull(notification.getTag()));
244244
int colorOffset = builder.createString(emptyIfNull(notification.getColor()));
245245
int clickActionOffset = builder.createString(emptyIfNull(notification.getClickAction()));
246+
int androidChannelIdOffset = builder.createString(emptyIfNull(notification.getChannelId()));
246247
int bodyLocalizationKeyOffset =
247248
builder.createString(emptyIfNull(notification.getBodyLocalizationKey()));
248249
int bodyLocalizationArgsOffset = 0;
@@ -278,6 +279,7 @@ private static byte[] generateMessageByteBuffer(
278279
SerializedNotification.addTag(builder, tagOffset);
279280
SerializedNotification.addColor(builder, colorOffset);
280281
SerializedNotification.addClickAction(builder, clickActionOffset);
282+
SerializedNotification.addAndroidChannelId(builder, androidChannelIdOffset);
281283
SerializedNotification.addBodyLocKey(builder, bodyLocalizationKeyOffset);
282284
SerializedNotification.addBodyLocArgs(builder, bodyLocalizationArgsOffset);
283285
SerializedNotification.addTitleLocKey(builder, titleLocalizationKeyOffset);

messaging/src/android/schemas/messaging.fbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ table SerializedNotification {
102102
//
103103
// [1]: https://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
104104
title_loc_args:[string];
105+
106+
// The channel id that was provided when the message was sent.
107+
android_channel_id:string;
105108
}
106109

107110
table SerializedMessage {
@@ -205,15 +208,14 @@ table SerializedMessage {
205208
// system tray of the OS.
206209
notification_opened:bool;
207210

208-
/// The link into the app from the message in the form of a URL.
211+
// The link into the app from the message in the form of a URL.
209212
link:string;
210213

211214
// Time in milliseconds from the Linux Epoch that the message was sent.
212215
sent_time:long;
213216

214217
// Original priority of the message. Value values are "normal" and "high".
215218
//
216-
//
217219
// For more information, see Setting the priority of a message.
218220
original_priority:string;
219221
}

messaging/src/include/firebase/messaging.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,52 @@ struct MessagingOptions {
6161
bool suppress_notification_permission_prompt;
6262
};
6363

64+
/// @brief Data structure for parameters that are unique to the Android
65+
/// implementation.
66+
struct AndroidNotificationParams {
67+
/// The channel id that was provided when the message was sent.
68+
std::string channel_id;
69+
};
70+
6471
/// Used for messages that display a notification.
6572
///
6673
/// On android, this requires that the app is using the Play Services client
6774
/// library.
6875
struct Notification {
76+
Notification() : android(nullptr) {}
77+
78+
#ifndef SWIG
79+
/// Copy constructor. Makes a deep copy of this Message.
80+
Notification(const Notification& other) : android(nullptr) { *this = other; }
81+
#endif // !SWIG
82+
83+
#ifndef SWIG
84+
/// Copy assignment operator. Makes a deep copy of this Message.
85+
Notification& operator=(const Notification& other) {
86+
this->title = other.title;
87+
this->body = other.body;
88+
this->icon = other.icon;
89+
this->sound = other.sound;
90+
this->tag = other.tag;
91+
this->color = other.color;
92+
this->click_action = other.click_action;
93+
this->body_loc_key = other.body_loc_key;
94+
this->body_loc_args = other.body_loc_args;
95+
this->title_loc_key = other.title_loc_key;
96+
this->title_loc_args = other.title_loc_args;
97+
delete this->android;
98+
if (other.android) {
99+
this->android = new AndroidNotificationParams(*other.android);
100+
} else {
101+
this->android = nullptr;
102+
}
103+
return *this;
104+
}
105+
#endif // !SWIG
106+
107+
/// Destructor.
108+
~Notification() { delete android; }
109+
69110
/// Indicates notification title. This field is not visible on iOS phones
70111
/// and tablets.
71112
std::string title;
@@ -146,6 +187,9 @@ struct Notification {
146187
/// [1]:
147188
/// https://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
148189
std::vector<std::string> title_loc_args;
190+
191+
/// Parameters that are unique to the Android implementation.
192+
AndroidNotificationParams* android;
149193
};
150194

151195
/// @brief Data structure used to send messages to, and receive messages from,

0 commit comments

Comments
 (0)