moncycle.app icon indicating copy to clipboard operation
moncycle.app copied to clipboard

Minimal changes required for the iOS offline mode

Open Limezy opened this issue 1 year ago • 0 comments

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

  1. Compare each of them with the days modified in the app since timestampLatestSyncAction and use a Last Write Win (LWW) approach to chose which one to use in case of conflict
  2. 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_modif for that date (this requires a change on the POST /observation endpoint, refer to #66 )
  3. Change in app all days where the server version of the day has "won" the comparison, using the server dernier_modif value as the stored timestamp for that day.
  4. Replace timestampLatestSyncAction with timestampSyncAction value
  5. 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

Limezy avatar Jul 21 '24 10:07 Limezy