moncycle.app
moncycle.app copied to clipboard
Minimal changes required for the iOS offline mode
Refactoring this as a parent issue to gather minimal changes required for the iOS offline mode (and PWA offline mode too)
When the iOS app will trigger a sync action :
- The iOS app will keep in memory the timestamp of that sync action it just triggered (
timestampSyncAction) - The iOS app will fetch from /api/constante the timestamp of the latest update that was done on server side (refer to #64), called (
timestampLatestUpdateServer) - The iOS app will have in memory the latest server timestamp (
timestampLatestSyncAction) on which its last sync was successfully made
If timestampLatestSyncAction < timestampLatestUpdateServer, it means there were some changes on the server that the iOS app don't know yet. Therefore, the iOS app will have to pull and receive the observations for all days modified on the server since timestampLatestSyncAction.
(This is the reason behind issue #65)
After receiving all these days, the iOS app will
- Compare each of them with the days modified in the app since
timestampLatestSyncActionand use a Last Write Win (LWW) approach to chose which one to use in case of conflict - Push to the server all days where the iOS version of the day has "won" the comparison, using the iOS app timestamp as a
dernier_modiffor that date (this requires a change on the POST /observation endpoint, refer to #66 ) - Change in app all days where the server version of the day has "won" the comparison, using the server
dernier_modifvalue as the stored timestamp for that day. - Replace
timestampLatestSyncActionwithtimestampSyncActionvalue - At this point, all days will be the same on both side, and all days will have the same timestamp (
dernier_modif) on both sides, which is very important to avoid sync infinite loops