diff options
author | beatrix <beatrix.bitrot@gmail.com> | 2018-01-05 18:29:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 18:29:57 -0500 |
commit | f441770e50621ac59a7b022ee2127964935b2b8d (patch) | |
tree | bd7bca6f161424f2fa6c6595fe70bb2d7df1074f /app/javascript/flavours/glitch/util/settings.js | |
parent | b4e667f86b645a1ddaa7944b61c2d6ca3b9e3981 (diff) | |
parent | 72b99f6ee416888ad4ea041c4cf90390c75e6861 (diff) |
Merge pull request #290 from chriswmartin/web-push-updates
Web push updates
Diffstat (limited to 'app/javascript/flavours/glitch/util/settings.js')
-rw-r--r-- | app/javascript/flavours/glitch/util/settings.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/util/settings.js b/app/javascript/flavours/glitch/util/settings.js new file mode 100644 index 000000000..dbd969cb1 --- /dev/null +++ b/app/javascript/flavours/glitch/util/settings.js @@ -0,0 +1,46 @@ +export default class Settings { + + constructor(keyBase = null) { + this.keyBase = keyBase; + } + + generateKey(id) { + return this.keyBase ? [this.keyBase, `id${id}`].join('.') : id; + } + + set(id, data) { + const key = this.generateKey(id); + try { + const encodedData = JSON.stringify(data); + localStorage.setItem(key, encodedData); + return data; + } catch (e) { + return null; + } + } + + get(id) { + const key = this.generateKey(id); + try { + const rawData = localStorage.getItem(key); + return JSON.parse(rawData); + } catch (e) { + return null; + } + } + + remove(id) { + const data = this.get(id); + if (data) { + const key = this.generateKey(id); + try { + localStorage.removeItem(key); + } catch (e) { + } + } + return data; + } + +} + +export const pushNotificationsSetting = new Settings('mastodon_push_notification_data'); |