Notalib / LYT

m.e17.dk
GNU Lesser General Public License v3.0
10 stars 12 forks source link

Implement user-specific settings #654

Closed saebekassebil closed 8 years ago

saebekassebil commented 10 years ago

A "Settings Manager" have been implemented, that takes care of talking to localStorage (through a thin wrapper). This Settings Manager gets initialized on each new user session, both for guests and members. The new database scheme is quite simply a dictionary of memberIDs.

Furthermore I've removed the "prefix" thingy from the store (before called 'cache'). It doesn't really make any sense, as there is no risk of collision since localStorage is domain-specific. I think we should remove the prefixes lyt/ and session/ but I'll need to talk to the rest of the team about that.

I've removed any special handling of QUOTA_EXCEEDED exceptions. All modern browsers have a (user-adjustable) limit on about 3Mb. Since 1 users settings is stored in less than 200 bytes, thats at least:

~300.000b / ~200b = ~1500 users

And it shouldn't be anything we need to worry about. iOS, however throws when trying to store data, when it's in Private Mode. I handle this be catching errors with code 22 (most browsers) or 1014 (Firefox)

This proved a quite substantial pull request, although it ought to be simple. That's because we have no real sense of "session" or "state" in the application, and it's hard to tell where the user is in the program-flow. I've attached the settings manager to the LYT.session namespace, since that made the most sense, although I'm not entirely sure about this.

Fixes #390

e.g.: Note that this is just for the local device (localStorage y'know), but it would be trivial to implement a settings-sync with a database server - I think we should consider implementing it.