Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make firebase-admin an optional dependency #707

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines -3 to -6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

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
Loading