-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
Generic FCM device convenience model #615
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 3.1.12 on 2021-07-08 05:32 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('push_notifications', '0007_uniquesetting'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='FCMDevice', | ||
fields=[ | ||
('gcmdevice_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='push_notifications.gcmdevice')), | ||
('platform', models.CharField(blank=True, choices=[('i', 'ios'), ('a', 'android'), ('w', 'web')], help_text='Optional device platform: i - ios, a - android, w - web', max_length=1, null=True)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd much rather see a small positive integer field for faster filtering on the database. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds like a good idea indeed. |
||
], | ||
options={ | ||
'verbose_name': 'FCM device', | ||
}, | ||
bases=('push_notifications.gcmdevice',), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
from .fields import HexIntegerField | ||
from .settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS | ||
|
||
|
||
CLOUD_MESSAGE_TYPES = ( | ||
("FCM", "Firebase Cloud Message"), | ||
("GCM", "Google Cloud Message"), | ||
|
@@ -124,7 +123,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: | ||
|
@@ -257,3 +256,29 @@ def send_message(self, message, **kwargs): | |
return webpush_send_message( | ||
uri=self.registration_id, message=message, browser=self.browser, | ||
auth=self.auth, p256dh=self.p256dh, application_id=self.application_id, **kwargs) | ||
|
||
|
||
class FCMDevice(GCMDevice): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration for existing users doesn't make sense. You should instead be renaming the current model to GCP no? |
||
PLATFORM_IOS = 'i' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't seem to be indented properly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not indented properly. 4 chars. |
||
PLATFORM_ANDROID = 'a' | ||
PLATFORM_WEB = 'w' | ||
|
||
PLATFORM_CHOICES = ( | ||
(PLATFORM_IOS, 'ios'), | ||
(PLATFORM_ANDROID, 'android'), | ||
(PLATFORM_WEB, 'web'), | ||
) | ||
platform = models.CharField( | ||
max_length=1, | ||
help_text=_("Optional device platform: i - ios, a - android, w - web"), | ||
choices=PLATFORM_CHOICES, | ||
null=True, | ||
blank=True | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.cloud_message_type = "FCM" | ||
|
||
class Meta: | ||
verbose_name = _("FCM device") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see https://github.com/jazzband/django-push-notifications/blob/master/CONTRIBUTING.md regarding single quotes