2020import json
2121import asyncio
2222import logging
23+ import warnings
2324import requests
2425import httpx
2526
@@ -177,7 +178,7 @@ async def send_each_for_multicast_async(
177178 dry_run : bool = False ,
178179 app : Optional [App ] = None
179180 ) -> BatchResponse :
180- """Sends the given mutlicast message to each token asynchronously via Firebase Cloud Messaging
181+ """Sends the given multicast message to each token or fid asynchronously via Firebase Cloud Messaging
181182 (FCM).
182183
183184 If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
@@ -197,19 +198,32 @@ async def send_each_for_multicast_async(
197198 """
198199 if not isinstance (multicast_message , MulticastMessage ):
199200 raise ValueError ('Message must be an instance of messaging.MulticastMessage class.' )
200- messages = [Message (
201- data = multicast_message .data ,
202- notification = multicast_message .notification ,
203- android = multicast_message .android ,
204- webpush = multicast_message .webpush ,
205- apns = multicast_message .apns ,
206- fcm_options = multicast_message .fcm_options ,
207- token = token
208- ) for token in multicast_message .tokens ]
201+ if multicast_message .tokens is not None :
202+ with warnings .catch_warnings ():
203+ warnings .simplefilter ("ignore" , DeprecationWarning )
204+ messages = [Message (
205+ data = multicast_message .data ,
206+ notification = multicast_message .notification ,
207+ android = multicast_message .android ,
208+ webpush = multicast_message .webpush ,
209+ apns = multicast_message .apns ,
210+ fcm_options = multicast_message .fcm_options ,
211+ token = token
212+ ) for token in multicast_message .tokens ]
213+ else :
214+ messages = [Message (
215+ data = multicast_message .data ,
216+ notification = multicast_message .notification ,
217+ android = multicast_message .android ,
218+ webpush = multicast_message .webpush ,
219+ apns = multicast_message .apns ,
220+ fcm_options = multicast_message .fcm_options ,
221+ fid = fid
222+ ) for fid in multicast_message .fids ]
209223 return await _get_messaging_service (app ).send_each_async (messages , dry_run )
210224
211225def send_each_for_multicast (multicast_message , dry_run = False , app = None ):
212- """Sends the given mutlicast message to each token via Firebase Cloud Messaging (FCM).
226+ """Sends the given multicast message to each token or fid via Firebase Cloud Messaging (FCM).
213227
214228 If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
215229 recipients. Instead, FCM performs all the usual validations and emulates the send operation.
@@ -228,15 +242,28 @@ def send_each_for_multicast(multicast_message, dry_run=False, app=None):
228242 """
229243 if not isinstance (multicast_message , MulticastMessage ):
230244 raise ValueError ('Message must be an instance of messaging.MulticastMessage class.' )
231- messages = [Message (
232- data = multicast_message .data ,
233- notification = multicast_message .notification ,
234- android = multicast_message .android ,
235- webpush = multicast_message .webpush ,
236- apns = multicast_message .apns ,
237- fcm_options = multicast_message .fcm_options ,
238- token = token
239- ) for token in multicast_message .tokens ]
245+ if multicast_message .tokens is not None :
246+ with warnings .catch_warnings ():
247+ warnings .simplefilter ("ignore" , DeprecationWarning )
248+ messages = [Message (
249+ data = multicast_message .data ,
250+ notification = multicast_message .notification ,
251+ android = multicast_message .android ,
252+ webpush = multicast_message .webpush ,
253+ apns = multicast_message .apns ,
254+ fcm_options = multicast_message .fcm_options ,
255+ token = token
256+ ) for token in multicast_message .tokens ]
257+ else :
258+ messages = [Message (
259+ data = multicast_message .data ,
260+ notification = multicast_message .notification ,
261+ android = multicast_message .android ,
262+ webpush = multicast_message .webpush ,
263+ apns = multicast_message .apns ,
264+ fcm_options = multicast_message .fcm_options ,
265+ fid = fid
266+ ) for fid in multicast_message .fids ]
240267 return _get_messaging_service (app ).send_each (messages , dry_run )
241268
242269def subscribe_to_topic (tokens , topic , app = None ):
0 commit comments