@@ -173,6 +173,32 @@ async def send_each_async(
173173 """
174174 return await _get_messaging_service (app ).send_each_async (messages , dry_run )
175175
176+ def _get_messages_from_multicast (multicast_message : MulticastMessage ) -> List [Message ]:
177+ if not isinstance (multicast_message , MulticastMessage ):
178+ raise ValueError ('Message must be an instance of messaging.MulticastMessage class.' )
179+ if multicast_message .tokens is not None :
180+ with warnings .catch_warnings ():
181+ warnings .simplefilter ("ignore" , DeprecationWarning )
182+ return [Message (
183+ data = multicast_message .data ,
184+ notification = multicast_message .notification ,
185+ android = multicast_message .android ,
186+ webpush = multicast_message .webpush ,
187+ apns = multicast_message .apns ,
188+ fcm_options = multicast_message .fcm_options ,
189+ token = token
190+ ) for token in multicast_message .tokens ]
191+
192+ return [Message (
193+ data = multicast_message .data ,
194+ notification = multicast_message .notification ,
195+ android = multicast_message .android ,
196+ webpush = multicast_message .webpush ,
197+ apns = multicast_message .apns ,
198+ fcm_options = multicast_message .fcm_options ,
199+ fid = fid
200+ ) for fid in multicast_message .fids ]
201+
176202async def send_each_for_multicast_async (
177203 multicast_message : MulticastMessage ,
178204 dry_run : bool = False ,
@@ -196,30 +222,7 @@ async def send_each_for_multicast_async(
196222 FirebaseError: If an error occurs while sending the message to the FCM service.
197223 ValueError: If the input arguments are invalid.
198224 """
199- if not isinstance (multicast_message , MulticastMessage ):
200- raise ValueError ('Message must be an instance of messaging.MulticastMessage class.' )
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 ]
225+ messages = _get_messages_from_multicast (multicast_message )
223226 return await _get_messaging_service (app ).send_each_async (messages , dry_run )
224227
225228def send_each_for_multicast (multicast_message , dry_run = False , app = None ):
@@ -240,30 +243,7 @@ def send_each_for_multicast(multicast_message, dry_run=False, app=None):
240243 FirebaseError: If an error occurs while sending the message to the FCM service.
241244 ValueError: If the input arguments are invalid.
242245 """
243- if not isinstance (multicast_message , MulticastMessage ):
244- raise ValueError ('Message must be an instance of messaging.MulticastMessage class.' )
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 ]
246+ messages = _get_messages_from_multicast (multicast_message )
267247 return _get_messaging_service (app ).send_each (messages , dry_run )
268248
269249def subscribe_to_topic (tokens , topic , app = None ):
0 commit comments