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

changing active state on the push_notifications_gcmdevice table #616

Closed
Avramo opened this issue Jul 19, 2021 · 8 comments
Closed

changing active state on the push_notifications_gcmdevice table #616

Avramo opened this issue Jul 19, 2021 · 8 comments

Comments

@Avramo
Copy link

Avramo commented Jul 19, 2021

Hi!

I use django with django-push-notifications.
When sending push notifications, I would like to know which users did/didn't get the message.

Currently I use this code after sending the notifications to know how many were sent/not sent:

    all_users = queryset.count()
    active_fcm = GCMDevice.objects.filter(user_id__in=queryset.values_list('id', flat=True), active=True).count()
    return Response({
        'sent': active_fcm, 
        'not_sent': all_users - active_fcm
        }, status=status.HTTP_201_CREATED)

I noticed this is not 100% accurate as the active field does not always reflect the actual users' status.
I removed the app and the active field was still True.

When and how does the active column in the push_notifications_gcmdevice table change?

Also what does device.send_message() return, and what is the meaning of success (ie. sent, active, or received)?

@Pro1ooEgor
Copy link

Pro1ooEgor commented Oct 26, 2021

When and how does the active column in the push_notifications_gcmdevice table change?

Have you found an answer to this?

@Avramo
Copy link
Author

Avramo commented Oct 27, 2021 via email

@Pro1ooEgor
Copy link

Hi. Today I found answer. It's interesting because out team found a lead in the documentation of another library (fcm-django). It says there:

Functionality:

  • automatic device pruning: devices to which notifications fail to send are marked as inactive

And I went to look at the code of current library, where found same behavior.
https://github.com/jazzband/django-push-notifications/blob/master/push_notifications/gcm.py#:~:text=def%20_cm_handle_response(registration_ids,return%20response

There is a comment there

If error is NotRegistered or InvalidRegistration, then we will deactivate devices
because this registration ID is no more valid and can't be used to send messages,
otherwise raise error

I think it would be nice to have a description of this moment in the readme file

@Avramo
Copy link
Author

Avramo commented Oct 28, 2021 via email

@Avramo
Copy link
Author

Avramo commented Oct 29, 2021

So I looked at the docs you mentioned and it seems that the active field should be automatically updated after sending a message.
In my original question I noted that I found this not to be the case.
Does this take time to update, could that be why I was not seeing the updates happen?

If error is NotRegistered or InvalidRegistration, then we will deactivate devices

What happens if the user just deletes the app, or switches phones, would the message to them fail with one of these errors?
Do I need to unregister the user?
Bottom line is, how can I be sure of who got the message?
Thanks

@henderson2350
Copy link

Is there a way to tell if a user has ENABLED push notifications on their device? not just whether or not the device has been registered?

@jamaalscarlett
Copy link
Member

That would have to be handled via your android/ios/webapp. i.e. on the device, if the user disables notifications, you should send a request to your server to update the device model

@jamaalscarlett
Copy link
Member

@henderson2350 I just tried this with FCM. Even when I disable app notifications on the phone, the notification is sent successfully from the backend. The blocking is occurring on the phone, so the detection would need to occur there.

@jamaalscarlett jamaalscarlett closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants