summaryrefslogtreecommitdiff
path: root/ui/src/lib/store
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/lib/store')
-rw-r--r--ui/src/lib/store/channels.js71
-rw-r--r--ui/src/lib/store/logins.js22
-rw-r--r--ui/src/lib/store/messages.js44
3 files changed, 0 insertions, 137 deletions
diff --git a/ui/src/lib/store/channels.js b/ui/src/lib/store/channels.js
deleted file mode 100644
index bb6c86c..0000000
--- a/ui/src/lib/store/channels.js
+++ /dev/null
@@ -1,71 +0,0 @@
-export class Channels {
- constructor() {
- this.channels = [];
- }
-
- setChannels(channels) {
- this.channels = [...channels];
- this.sort();
- return this;
- }
-
- addChannel(id, name) {
- this.channels = [...this.channels, { id, name }];
- this.sort();
- return this;
- }
-
- deleteChannel(id) {
- const channelIndex = this.channels.map((e) => e.id).indexOf(id);
- if (channelIndex !== -1) {
- this.channels.splice(channelIndex, 1);
- }
- return this;
- }
-
- sort() {
- this.channels.sort((a, b) => {
- if (a.name < b.name) {
- return -1;
- } else if (a.name > b.name) {
- return 1;
- }
- return 0;
- });
- }
-}
-
-export class ActiveChannel {
- constructor() {
- this.channel = null;
- }
-
- isSet() {
- return this.channel !== null;
- }
-
- get() {
- return this.channel;
- }
-
- is(id) {
- return this.channel === id;
- }
-
- set(id) {
- this.channel = id;
- return this;
- }
-
- deleteChannel(id) {
- if (this.is(id)) {
- return this.clear();
- }
- return this;
- }
-
- clear() {
- this.channel = null;
- return this;
- }
-}
diff --git a/ui/src/lib/store/logins.js b/ui/src/lib/store/logins.js
deleted file mode 100644
index 5b45206..0000000
--- a/ui/src/lib/store/logins.js
+++ /dev/null
@@ -1,22 +0,0 @@
-export class Logins {
- constructor() {
- this.logins = {};
- }
-
- addLogin(id, name) {
- this.logins[id] = name;
- return this;
- }
-
- setLogins(logins) {
- this.logins = {};
- for (let { id, name } of logins) {
- this.addLogin(id, name);
- }
- return this;
- }
-
- get(id) {
- return this.logins[id];
- }
-}
diff --git a/ui/src/lib/store/messages.js b/ui/src/lib/store/messages.js
deleted file mode 100644
index 931b8fb..0000000
--- a/ui/src/lib/store/messages.js
+++ /dev/null
@@ -1,44 +0,0 @@
-export class Messages {
- constructor() {
- this.channels = {};
- }
-
- inChannel(channel) {
- return this.channels[channel] = (this.channels[channel] || []);
- }
-
- addMessage(channel, id, at, sender, body) {
- this.updateChannel(channel, (messages) => [...messages, { id, at, sender, body }]);
- return this;
- }
-
- setMessages(messages) {
- this.channels = {};
- for (let { channel, id, at, sender, body } of messages) {
- this.inChannel(channel).push({ id, at, sender, body, });
- }
- for (let channel in this.channels) {
- this.channels[channel].sort((a, b) => a.at - b.at);
- }
- return this;
- }
-
-
- deleteMessage(message) {
- for (let channel in this.channels) {
- this.updateChannel(channel, (messages) => messages.filter((msg) => msg.id != message));
- }
- return this;
- }
-
- deleteChannel(id) {
- delete this.channels[id];
- return this;
- }
-
- updateChannel(channel, callback) {
- let messages = callback(this.inChannel(channel));
- messages.sort((a, b) => a.at - b.at);
- this.channels[channel] = messages;
- }
-}