My expectation, from the docs, was that calling unregisterApp() should always result in the receiver's onUnregistered method being called.
It's not, and I think that could be a problem.
Suppose I use onUnregistered to make an API call to my remote server to disable push messages. So something like:
@AndroidEntryPoint
class UnifiedPushBroadcastReceiver : MessagingReceiver() {
@Inject
lateinit var api: RemoteApi
// ...
override fun onUnregistered(context: Context, instance: String) {
api.unsubscribePush(instance) // HTTP DELETE /api/v1/push/:instance
}
}
Elsewhere in my code I allow the user to log out from their account, and as part of the log out logic I have this:
suspend fun logout(context: Context, account: Account) {
// ...
UnifiedPush.unregisterApp(context, account.unifiedPushInstance)
// ...
}
My expectation is the call to unregisterApp() will send the broadcast message, onUnregistered will be called, and an RPC to the server to unsubscribe from push messages will be sent.
However...
unregisterApp() may return early, without sending the broadcast message. If I'm reading the code correctly this can happen if the user deletes the app they're using as the push distributor.
For example, suppose:
- The user installs my app
- My app tells them to install a push distributor
- They decide to install ntfy
- After trying my app they decide they don't want to use it any more
- They uninstall ntfy
- They log out of my app, then uninstall it
Because they uninstalled ntfy before logging out of my app onUnregistered is not called, and the push subscription is never deleted from the server.
My expectation, from the docs, was that calling
unregisterApp()should always result in the receiver'sonUnregisteredmethod being called.It's not, and I think that could be a problem.
Suppose I use
onUnregisteredto make an API call to my remote server to disable push messages. So something like:Elsewhere in my code I allow the user to log out from their account, and as part of the log out logic I have this:
My expectation is the call to
unregisterApp()will send the broadcast message,onUnregisteredwill be called, and an RPC to the server to unsubscribe from push messages will be sent.However...
unregisterApp()may return early, without sending the broadcast message. If I'm reading the code correctly this can happen if the user deletes the app they're using as the push distributor.For example, suppose:
Because they uninstalled ntfy before logging out of my app
onUnregisteredis not called, and the push subscription is never deleted from the server.