Repository navigation
fix(fcm): Omit event_time when AndroidNotification.EventTimestamp is not set - #619
caglarenes wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the AndroidNotification class to prevent the EventTimestamp from being included in the serialized message when it is left at its default value. Specifically, a check was added to return null in EventTimeString if EventTimestamp is equal to default(DateTime). Corresponding unit tests were added to verify serialization behavior both with and without an event timestamp. There are no review comments, so I have no feedback to provide.
c6de157 to
ce7624e
Compare
…not set AndroidNotification.EventTimestamp is a non-nullable DateTime and the private EventTimeString helper always returned a formatted value, so a notification that never set EventTimestamp was sent with "event_time": "0001-01-01T00:00:00.000000000Z" (shifted by the host's UTC offset on hosts west of UTC). The Android FCM SDK uses event_time as the notification's "when" value, so these notifications show a wrong time and sort as the oldest entry in the notification drawer. EventTimeString now returns null when EventTimestamp is default(DateTime), and the serializer omits null values, so event_time is left out of the request. This matches how Priority, Visibility, Proxy and VibrateTimingsMillis are omitted when unset. The public API does not change. Testing: Added unit tests in MessageTest.cs that serialize an AndroidNotification with and without EventTimestamp.
ce7624e to
28728dd
Compare
Fixes #618.
AndroidNotification.EventTimestampis a non-nullableDateTime, and the privateEventTimeStringhelper always returned a formatted value. A notification that never setEventTimestampwas therefore sent with"event_time": "0001-01-01T00:00:00.000000000Z". Onhosts west of UTC the value was shifted by the UTC offset. The FCM Android SDK uses
event_timeas the notification's
when, so these notifications show a wrong time and the drawer sorts themas the oldest entries.
EventTimeStringnow returnsnullwhenEventTimestampisdefault(DateTime).NewtonsoftJsonSerializeromits null values, soevent_timeis left out of the request.Priority,Visibility,ProxyandVibrateTimingsMillisare omitted the same way when theyare unset. The XML doc for
EventTimestampnow says that the default value is not sent.Deserialization is unchanged: a payload without
event_timeleaves the default value, and theround trip still omits it.
Why not change the type to
DateTime?DateTime?gives a clearer API. It matches the other optional members of this class, theother Admin SDKs, and
AndroidNotificationV2in feat(fcm): Add support for AndroidConfigV2 #537. However, it changes a public property'stype:
MissingMethodExceptiononget_EventTimestampandset_EventTimestampuntil they are recompiled. This hits librariesthat depend on FirebaseAdmin.
n.EventTimestamp.ToString("o"),.Year, or passing it to aDateTimeparameter.Under semver, both breaks require a major release.
The
defaultsentinel (this PR) changes neither the API nor the ABI, so it can ship in apatch release. The only cost is that a caller can no longer send exactly
0001-01-01T00:00:00(DateTime ==ignoresKind). That value is not a meaningful event time.feat(fcm): Add support for AndroidConfigV2 #537 deprecates this class in favor of the nullable
AndroidNotificationV2. Changing thelegacy type now would be churn on an API that is being phased out.
Testing
Added
MessageTest.AndroidNotificationWithoutEventTimestampandMessageTest.AndroidNotificationWithEventTimestamp. Before the fix, the first test failsbecause the actual JSON contains
"event_time": "0001-01-01T00:00:00.000000000Z". After thefix, both tests pass.
Ran
dotnet test FirebaseAdmin.Tests --filter "FullyQualifiedName~FirebaseAdmin.Messaging"with .NET SDK 11.0.100:
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1The one failure is
AndroidNotificationDeserialization. It is pre-existing and unrelated: itfails the same way on unmodified
main(119 tests, 1 failure) on a machine with a culture thatuses
,as the decimal separator. The cause is thatTimeConverter.StringToLongMillisparses"1.001000000"with the current culture.FirebaseAdminbuilds for netstandard2.0, net462 and net6.0 withTreatWarningsAsErrors.dotnet format --verify-no-changesreports no changes for the two edited files.🤖 Generated with Claude Code