summaryrefslogtreecommitdiff
path: root/src/db.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.js')
-rw-r--r--src/db.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/db.js b/src/db.js
new file mode 100644
index 0000000..145b144
--- /dev/null
+++ b/src/db.js
@@ -0,0 +1,29 @@
+// Ideally, we should write to a file and read it at app start in case of crashes.
+// An actual SQL database would probably be overkill.
+
+/** @type Array<{ name: string, number: string }> */
+const subscriptions = [];
+
+/**
+ * @param {string} number
+ * @param {string} name
+ */
+export function subscribe(number, name) {
+ subscriptions.push({ name, number });
+}
+
+/**
+ * @param {string} number
+ */
+export function isSubscribed(number) {
+ return subscriptions.some(s => s.number == number);
+}
+
+export function getSubscriptions() {
+ /** @type Array<{ name: string, number: string }> */
+ const clone = [];
+ for (const subscription of subscriptions) {
+ clone.push({ ...subscription });
+ }
+ return clone;
+} \ No newline at end of file