Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ public void AndroidConfig()
DefaultLightSettings = false,
Visibility = NotificationVisibility.PUBLIC,
NotificationCount = 10,
Proxy = NotificationProxy.IfPriorityLowered,
},
FcmOptions = new AndroidFcmOptions()
{
Expand Down Expand Up @@ -359,6 +360,7 @@ public void AndroidConfig()
{ "visibility", "PUBLIC" },
{ "vibrate_timings", new JArray() { "1s", "1.001000000s" } },
{ "event_time", "2020-06-27T20:29:06.032691000Z" },
{ "proxy", "IF_PRIORITY_LOWERED" },
}
},
{
Expand Down Expand Up @@ -493,6 +495,7 @@ public void AndroidNotificationDeserialization()
DefaultLightSettings = false,
Visibility = NotificationVisibility.PUBLIC,
NotificationCount = 10,
Proxy = NotificationProxy.IfPriorityLowered,
};
var json = NewtonsoftJsonSerializer.Instance.Serialize(original);
var copy = NewtonsoftJsonSerializer.Instance.Deserialize<AndroidNotification>(json);
Expand Down Expand Up @@ -523,6 +526,7 @@ public void AndroidNotificationDeserialization()
Assert.Equal(original.DefaultLightSettings, copy.DefaultLightSettings);
Assert.Equal(original.Visibility, copy.Visibility);
Assert.Equal(original.NotificationCount, copy.NotificationCount);
Assert.Equal(original.Proxy, copy.Proxy);
}

[Fact]
Expand Down
50 changes: 49 additions & 1 deletion FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ public sealed class AndroidNotification
[JsonProperty("notification_count")]
public int? NotificationCount { get; set; }

/// <summary>
/// Gets or sets the proxy behavior of this notification.
/// </summary>
[JsonIgnore]
public NotificationProxy? Proxy { get; set; }

/// <summary>
/// Gets or sets the string representation of the <see cref="NotificationPriority"/> property.
/// </summary>
Expand Down Expand Up @@ -312,7 +318,7 @@ private string VisibilityString
return;
default:
throw new ArgumentException(
$"Invalid visibility value: {value}. Only 'PUBLIC', 'PRIVATE', ''SECRET' are allowed.");
$"Invalid visibility value: {value}. Only 'PUBLIC', 'PRIVATE', 'SECRET' are allowed.");
}
}
}
Expand Down Expand Up @@ -379,6 +385,47 @@ private string EventTimeString
}
}

/// <summary>
/// Gets or sets the string representation of the <see cref="NotificationProxy"/> property.
/// </summary>
[JsonProperty("proxy")]
private string ProxyString
{
get
{
switch (this.Proxy)
{
case NotificationProxy.Allow:
return "ALLOW";
case NotificationProxy.Deny:
return "DENY";
case NotificationProxy.IfPriorityLowered:
return "IF_PRIORITY_LOWERED";
default:
return null;
}
}

set
{
switch (value)
{
case "ALLOW":
this.Proxy = NotificationProxy.Allow;
return;
case "DENY":
this.Proxy = NotificationProxy.Deny;
return;
case "IF_PRIORITY_LOWERED":
this.Proxy = NotificationProxy.IfPriorityLowered;
return;
default:
throw new ArgumentException(
$"Invalid proxy value: {value}. Only 'ALLOW', 'DENY', 'IF_PRIORITY_LOWERED' are allowed.");
}
}
}

/// <summary>
/// Copies this notification, and validates the content of it to ensure that it can be
/// serialized into the JSON format expected by the FCM service.
Expand Down Expand Up @@ -411,6 +458,7 @@ internal AndroidNotification CopyAndValidate()
DefaultLightSettings = this.DefaultLightSettings,
Visibility = this.Visibility,
NotificationCount = this.NotificationCount,
Proxy = this.Proxy,
};
if (copy.Color != null && !Regex.Match(copy.Color, "^#[0-9a-fA-F]{6}$").Success)
{
Expand Down
38 changes: 38 additions & 0 deletions FirebaseAdmin/FirebaseAdmin/Messaging/NotificationProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2025, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace FirebaseAdmin.Messaging
{
/// <summary>
/// Proxy behavior that can be set on an <see cref="AndroidNotification"/>.
/// </summary>
public enum NotificationProxy
{
/// <summary>
/// Try to proxy this notification.
/// </summary>
Allow,

/// <summary>
/// Do not proxy this notification..
/// </summary>
Deny,

/// <summary>
/// Only try to proxy this notification if its `AndroidMessagePriority`
/// was lowered from HIGH to NORMAL on the device.
/// </summary>
IfPriorityLowered,
}
}