summaryrefslogtreecommitdiff
path: root/hi-ui/src/store/messages.js
diff options
context:
space:
mode:
Diffstat (limited to 'hi-ui/src/store/messages.js')
-rw-r--r--hi-ui/src/store/messages.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/hi-ui/src/store/messages.js b/hi-ui/src/store/messages.js
index f9e0856..931b8fb 100644
--- a/hi-ui/src/store/messages.js
+++ b/hi-ui/src/store/messages.js
@@ -4,16 +4,22 @@ export class Messages {
}
inChannel(channel) {
- return this.channels[channel] || [];
+ return this.channels[channel] = (this.channels[channel] || []);
}
- addMessage(channel, at, sender, body) {
- this.updateChannel(channel, (messages) => [...messages, { at, sender, body }]);
+ addMessage(channel, id, at, sender, body) {
+ this.updateChannel(channel, (messages) => [...messages, { id, at, sender, body }]);
return this;
}
- addMessages(channel, payloads) {
- this.updateChannel(channel, (messages) => [...messages, ...payloads]);
+ 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;
}