1414
1515"""Types and utilities used by the messaging (FCM) module."""
1616from __future__ import annotations
17+ from dataclasses import dataclass
1718import datetime
1819from typing import Dict , List , Optional , Union
20+ import warnings
1921
2022from firebase_admin import exceptions
2123
@@ -38,6 +40,8 @@ def __init__(self, title=None, body=None, image=None):
3840class AndroidConfig :
3941 """Android-specific options that can be included in a message.
4042
43+ AndroidConfig is deprecated. Use AndroidConfigV2 instead.
44+
4145 Args:
4246 collapse_key: Collapse key string for the message (optional). This is an identifier for a
4347 group of messages that can be collapsed, so that only the last message is sent when
@@ -73,6 +77,11 @@ def __init__(
7377 bandwidth_constrained_ok : Optional [bool ] = None ,
7478 restricted_satellite_ok : Optional [bool ] = None
7579 ):
80+ warnings .warn (
81+ 'AndroidConfig is deprecated. Use AndroidConfigV2 instead.' ,
82+ DeprecationWarning ,
83+ stacklevel = 2
84+ )
7685 self .collapse_key = collapse_key
7786 self .priority = priority
7887 self .ttl = ttl
@@ -85,6 +94,7 @@ def __init__(
8594 self .restricted_satellite_ok = restricted_satellite_ok
8695
8796
97+ @dataclass
8898class AndroidConfigV2 :
8999 """Android-specific options that can be included in a message (V2).
90100
@@ -111,35 +121,23 @@ class AndroidConfigV2:
111121 restricted_satellite_ok: A boolean indicating whether messages will be allowed to be
112122 delivered to the app while the device is on a restricted satellite network (optional).
113123 """
114-
115- def __init__ (
116- self ,
117- collapse_key : Optional [str ] = None ,
118- ttl : Optional [Union [int , float , datetime .timedelta ]] = None ,
119- restricted_package_name : Optional [str ] = None ,
120- data : Optional [Dict [str , str ]] = None ,
121- remote_notification : Optional [AndroidRemoteNotification ] = None ,
122- background_sync : Optional [AndroidBackgroundSyncMessage ] = None ,
123- fcm_options : Optional [AndroidFCMOptions ] = None ,
124- direct_boot_ok : Optional [bool ] = None ,
125- bandwidth_constrained_ok : Optional [bool ] = None ,
126- restricted_satellite_ok : Optional [bool ] = None
127- ):
128- self .collapse_key = collapse_key
129- self .ttl = ttl
130- self .restricted_package_name = restricted_package_name
131- self .data = data
132- self .remote_notification = remote_notification
133- self .background_sync = background_sync
134- self .fcm_options = fcm_options
135- self .direct_boot_ok = direct_boot_ok
136- self .bandwidth_constrained_ok = bandwidth_constrained_ok
137- self .restricted_satellite_ok = restricted_satellite_ok
124+ collapse_key : Optional [str ] = None
125+ ttl : Optional [Union [int , float , datetime .timedelta ]] = None
126+ restricted_package_name : Optional [str ] = None
127+ data : Optional [Dict [str , str ]] = None
128+ remote_notification : Optional [AndroidRemoteNotification ] = None
129+ background_sync : Optional [AndroidBackgroundSyncMessage ] = None
130+ fcm_options : Optional [AndroidFCMOptions ] = None
131+ direct_boot_ok : Optional [bool ] = None
132+ bandwidth_constrained_ok : Optional [bool ] = None
133+ restricted_satellite_ok : Optional [bool ] = None
138134
139135
140136class AndroidNotification :
141137 """Android-specific notification parameters.
142138
139+ AndroidNotification is deprecated. Use AndroidNotificationV2 instead.
140+
143141 Args:
144142 title: Title of the notification (optional). If specified, overrides the title set via
145143 ``messaging.Notification``.
@@ -232,6 +230,11 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
232230 default_vibrate_timings = None , default_sound = None , light_settings = None ,
233231 default_light_settings = None , visibility = None , notification_count = None ,
234232 proxy = None ):
233+ warnings .warn (
234+ 'AndroidNotification is deprecated. Use AndroidNotificationV2 instead.' ,
235+ DeprecationWarning ,
236+ stacklevel = 2
237+ )
235238 self .title = title
236239 self .body = body
237240 self .icon = icon
@@ -260,6 +263,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
260263 self .proxy = proxy
261264
262265
266+ @dataclass
263267class AndroidNotificationV2 :
264268 """Android-specific notification options (V2).
265269
@@ -345,64 +349,35 @@ class AndroidNotificationV2:
345349 unspecified, systems that support badging use the default, which is to increment a
346350 number displayed on the long-press menu each time a new notification arrives.
347351 """
348-
349- def __init__ (
350- self ,
351- title : Optional [str ] = None ,
352- body : Optional [str ] = None ,
353- icon : Optional [str ] = None ,
354- color : Optional [str ] = None ,
355- sound : Optional [str ] = None ,
356- tag : Optional [str ] = None ,
357- id : Optional [int ] = None , # pylint: disable=redefined-builtin,invalid-name
358- click_action : Optional [str ] = None ,
359- body_loc_key : Optional [str ] = None ,
360- body_loc_args : Optional [List [str ]] = None ,
361- title_loc_key : Optional [str ] = None ,
362- title_loc_args : Optional [List [str ]] = None ,
363- channel_id : Optional [str ] = None ,
364- image : Optional [str ] = None ,
365- ticker : Optional [str ] = None ,
366- sticky : Optional [bool ] = None ,
367- event_time : Optional [datetime .datetime ] = None ,
368- local_only : Optional [bool ] = None ,
369- notification_priority : Optional [str ] = None ,
370- vibrate_timings_millis : Optional [List [Union [int , float , datetime .timedelta ]]] = None ,
371- default_vibrate_timings : Optional [bool ] = None ,
372- default_sound : Optional [bool ] = None ,
373- light_settings : Optional [LightSettings ] = None ,
374- default_light_settings : Optional [bool ] = None ,
375- visibility : Optional [str ] = None ,
376- notification_count : Optional [int ] = None
377- ):
378- self .title = title
379- self .body = body
380- self .icon = icon
381- self .color = color
382- self .sound = sound
383- self .tag = tag
384- self .id = id # pylint: disable=invalid-name
385- self .click_action = click_action
386- self .body_loc_key = body_loc_key
387- self .body_loc_args = body_loc_args
388- self .title_loc_key = title_loc_key
389- self .title_loc_args = title_loc_args
390- self .channel_id = channel_id
391- self .image = image
392- self .ticker = ticker
393- self .sticky = sticky
394- self .event_time = event_time
395- self .local_only = local_only
396- self .notification_priority = notification_priority
397- self .vibrate_timings_millis = vibrate_timings_millis
398- self .default_vibrate_timings = default_vibrate_timings
399- self .default_sound = default_sound
400- self .light_settings = light_settings
401- self .default_light_settings = default_light_settings
402- self .visibility = visibility
403- self .notification_count = notification_count
404-
405-
352+ title : Optional [str ] = None
353+ body : Optional [str ] = None
354+ icon : Optional [str ] = None
355+ color : Optional [str ] = None
356+ sound : Optional [str ] = None
357+ tag : Optional [str ] = None
358+ id : Optional [int ] = None # pylint: disable=redefined-builtin,invalid-name
359+ click_action : Optional [str ] = None
360+ body_loc_key : Optional [str ] = None
361+ body_loc_args : Optional [List [str ]] = None
362+ title_loc_key : Optional [str ] = None
363+ title_loc_args : Optional [List [str ]] = None
364+ channel_id : Optional [str ] = None
365+ image : Optional [str ] = None
366+ ticker : Optional [str ] = None
367+ sticky : Optional [bool ] = None
368+ event_time : Optional [datetime .datetime ] = None
369+ local_only : Optional [bool ] = None
370+ notification_priority : Optional [str ] = None
371+ vibrate_timings_millis : Optional [List [Union [int , float , datetime .timedelta ]]] = None
372+ default_vibrate_timings : Optional [bool ] = None
373+ default_sound : Optional [bool ] = None
374+ light_settings : Optional [LightSettings ] = None
375+ default_light_settings : Optional [bool ] = None
376+ visibility : Optional [str ] = None
377+ notification_count : Optional [int ] = None
378+
379+
380+ @dataclass
406381class AndroidRemoteNotification :
407382 """Android remote notification options.
408383
@@ -413,18 +388,12 @@ class AndroidRemoteNotification:
413388 use_as_v1_data_message: A boolean indicating whether to use as a V1 data message
414389 fallback (optional).
415390 """
416-
417- def __init__ (
418- self ,
419- notification : AndroidNotificationV2 ,
420- mutable_content : Optional [bool ] = None ,
421- use_as_v1_data_message : Optional [bool ] = None
422- ):
423- self .notification = notification
424- self .mutable_content = mutable_content
425- self .use_as_v1_data_message = use_as_v1_data_message
391+ notification : AndroidNotificationV2
392+ mutable_content : Optional [bool ] = None
393+ use_as_v1_data_message : Optional [bool ] = None
426394
427395
396+ @dataclass
428397class AndroidBackgroundSyncMessage :
429398 """Android background sync message options."""
430399
0 commit comments