vendredi 22 février 2019

Backend/App: Pattern for Changed Text Detection

I am implementing an Android app in Cordova which communicates with a REST API backend. The app uses i18n by Cordova using JSON dictionaries with translations. However, some more dynamic texts are provided by the backend to enable flexibility such that they can be changed without the need of updating the app.

For accepting the Terms of Service and the Data Protection Policy, a mechanism is required which detects whether the user already accepted the current version. As there is no user profile in the backend (just an ID derived by the device ID), it should be implemented client-side.

Approach 1: My approach was to just take a hash (MD5, SHA3 or similar) of the text and store it with a accepted flag into the local storage. If the user restarts the app, the hash from the backend's response is recalculated and compared. If the hash changed, the user needs to re-accept the terms.

However, this solution does not work well with i18n. Because if the user changes the language, the text received also changes and as a result, the user needs to reaccept the terms though the terms did not necessarily change.

Of course, the idea could be simply extended to hash the text of all given languages. Although I think it is not a well-designed and extensible solution.

Approach 2: My next idea was to generate a server-based identification attribute for each text, like a GUID. This could be implemented in a way such that each update (there's an POST endpoint for that) of a text bundle (multiple languages) automatically generates a new GUID. The same GUID is then sent—independent of the desired text language—to the app.

What do you think about the approaches? Are there any more broadly used and straightforward concepts for that?

Aucun commentaire:

Enregistrer un commentaire