about summary refs log tree commit diff
path: root/app/javascript/mastodon/settings.js
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2017-12-09 22:18:45 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-12-09 14:18:45 +0100
commitcdae7e4c8b24bfa6f5e7650887b142d7b1a56a7b (patch)
tree1aaf0c9ac599b67055b2ac78b58a1e60ed211eee /app/javascript/mastodon/settings.js
parent3a52c90de12b39440264cce2ce218f9c4d7c6ebe (diff)
Move push notifications settings (regression from #5879) (#5941)
* Move push notifications settings

* fix typo `setf` -> `set`
Diffstat (limited to 'app/javascript/mastodon/settings.js')
-rw-r--r--app/javascript/mastodon/settings.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/javascript/mastodon/settings.js b/app/javascript/mastodon/settings.js
new file mode 100644
index 000000000..dbd969cb1
--- /dev/null
+++ b/app/javascript/mastodon/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');