django-push-notifications icon indicating copy to clipboard operation
django-push-notifications copied to clipboard

changing `active` state on the `push_notifications_gcmdevice` table

Open Avramo opened this issue 3 years ago • 7 comments

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)?

Avramo avatar Jul 19 '21 16:07 Avramo

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

Have you found an answer to this?

Pro1ooEgor avatar Oct 26 '21 17:10 Pro1ooEgor

Unfortunately not. I'd appreciate any leads though. Thanks

On Tue, Oct 26, 2021 at 8:07 PM Egor Novik @.***> wrote:

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

Have you found an answer to this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jazzband/django-push-notifications/issues/616#issuecomment-952138837, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANT6QH3EVGK5YBYZMAVGS23UI3N4FANCNFSM5AUBTXUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Avramo avatar Oct 27 '21 14:10 Avramo

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

Pro1ooEgor avatar Oct 28 '21 12:10 Pro1ooEgor

Great, I'll check it out, thanks!

On Thu, Oct 28, 2021 at 3:35 PM Egor Novik @.***> wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jazzband/django-push-notifications/issues/616#issuecomment-953802064, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANT6QH7VRJJJ7FZR4PDJKMDUJE7RBANCNFSM5AUBTXUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Avramo avatar Oct 28 '21 12:10 Avramo

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

Avramo avatar Oct 29 '21 13:10 Avramo

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?

henderson2350 avatar Jul 13 '22 15:07 henderson2350

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 avatar Jul 25 '22 01:07 jamaalscarlett

@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 avatar Aug 15 '23 22:08 jamaalscarlett