aboutsummaryrefslogtreecommitdiff
path: root/src/modules/shout.js
diff options
context:
space:
mode:
authorIlja <ilja@ilja.space>2022-02-26 02:08:13 +0100
committerIlja <ilja@ilja.space>2022-02-26 02:08:13 +0100
commitd0c4ad22cd5a93f69c689f3c8c75546c35861740 (patch)
tree15b535925b4ce0ea851e27ace32afde9db6a29c1 /src/modules/shout.js
parent819b76026101ddc0363118f240049a0019ebb4d6 (diff)
parent0300db6c6356c536694a9fcbb32a52abc81c52d5 (diff)
Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma-fe into feat/report-notification
Diffstat (limited to 'src/modules/shout.js')
-rw-r--r--src/modules/shout.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/modules/shout.js b/src/modules/shout.js
new file mode 100644
index 00000000..507a4d83
--- /dev/null
+++ b/src/modules/shout.js
@@ -0,0 +1,33 @@
+const shout = {
+ state: {
+ messages: [],
+ channel: { state: '' }
+ },
+ mutations: {
+ setChannel (state, channel) {
+ state.channel = channel
+ },
+ addMessage (state, message) {
+ state.messages.push(message)
+ state.messages = state.messages.slice(-19, 20)
+ },
+ setMessages (state, messages) {
+ state.messages = messages.slice(-19, 20)
+ }
+ },
+ actions: {
+ initializeShout (store, socket) {
+ const channel = socket.channel('chat:public')
+ channel.on('new_msg', (msg) => {
+ store.commit('addMessage', msg)
+ })
+ channel.on('messages', ({ messages }) => {
+ store.commit('setMessages', messages)
+ })
+ channel.join()
+ store.commit('setChannel', channel)
+ }
+ }
+}
+
+export default shout