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 <tim@smartfactory.ch>
  • Loading branch information
2 people authored and 50-Course committed Oct 3, 2024
1 parent 645eabe commit fe35a5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 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
8 changes: 6 additions & 2 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

0 comments on commit fe35a5d

Please sign in to comment.