Skip to content

Commit

Permalink
make firebase-admin an optional dependency (#707)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Jahn <[email protected]>
  • Loading branch information
ceoy and Tim Jahn authored Feb 27, 2024
1 parent 307a1b8 commit 9fbab31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/FCM.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Initialize the firebase admin in your ``settings.py`` file.
.. code-block:: python
# Import the firebase service
from firebase_admin import auth
import firebase_admin
# Initialize the default app
default_app = firebase_admin.initialize_app()
Expand Down
10 changes: 7 additions & 3 deletions push_notifications/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from firebase_admin import messaging

from .fields import HexIntegerField
from .gcm import dict_to_fcm_message
from .settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS


Expand Down Expand Up @@ -60,6 +58,9 @@ def get_queryset(self):
class GCMDeviceQuerySet(models.query.QuerySet):
def send_message(self, message, **kwargs):
if self.exists():
from firebase_admin import messaging

from .gcm import dict_to_fcm_message
from .gcm import send_message as fcm_send_message

if not isinstance(message, messaging.Message):
Expand Down Expand Up @@ -108,6 +109,9 @@ class Meta:
verbose_name = _("FCM device")

def send_message(self, message, **kwargs):
from firebase_admin import messaging

from .gcm import dict_to_fcm_message
from .gcm import send_message as fcm_send_message

# GCM is not supported.
Expand Down Expand Up @@ -137,7 +141,7 @@ def send_message(self, message, creds=None, **kwargs):
if self.exists():
from .apns import apns_send_bulk_message

app_ids = self.filter(active=True).order_by("application_id")\
app_ids = self.filter(active=True).order_by("application_id") \
.values_list("application_id", flat=True).distinct()
res = []
for app_id in app_ids:
Expand Down

0 comments on commit 9fbab31

Please sign in to comment.