This task encompasses the work of integrating the app with the new Push functionality in the Echo extension, as well as a few additional considerations regarding the use of Firebase.
- Add dependency to Firebase.
We must add the necessary library dependency, and add a minimal service class that will receive messages from Firebase.
- Make use of the new API in the Echo extension.
The Echo extension has a new API (echopushsubscriptions) that lets us subscribe and unsubscribe a device token that we will get from Firebase. As soon as we receive a token from Firebase, we should register it with the Echo API (making sure to unsubscribe any previous token). Echo will then use that token to broadcast notifications to the Firebase backend.
- Receive and respond to messages from Firebase.
The messages that we receive from Firebase will not be the actual Echo notifications, but simply a "ping" to tell us that new notification(s) exist for the current user. Upon receiving such a message, we should poll the regular API for retrieving notifications, exactly as we do today.
- Make sure to have fallbacks for various failure modes
If anything goes wrong with the push workflow, the app should automatically fall back to the current polling method of retrieving notifications. For example, if the API for registering the device token fails repeatedly.
Questions to be resolved:
- When exactly during the lifecycle of the app does Firebase issue the token?
- How often does Firebase re-issue a new token to the app?
- Does the Echo extension detect if the same token is registered more than once? (i.e. is it safe to re-issue the API call to register the same token, without the limited token slots filling up?)