logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

shout.js (790B)


  1. import { defineStore } from 'pinia'
  2. export const useShoutStore = defineStore('shout', {
  3. state: () => ({
  4. messages: [],
  5. channel: { state: '' },
  6. joined: false
  7. }),
  8. actions: {
  9. initializeShout (socket) {
  10. const channel = socket.channel('chat:public')
  11. channel.joinPush.receive('ok', () => {
  12. this.joined = true
  13. })
  14. channel.onClose(() => {
  15. this.joined = false
  16. })
  17. channel.onError(() => {
  18. this.joined = false
  19. })
  20. channel.on('new_msg', (msg) => {
  21. this.messages.push(msg)
  22. this.messages = this.messages.slice(-19, 20)
  23. })
  24. channel.on('messages', ({ messages }) => {
  25. this.messages = messages.slice(-19, 20)
  26. })
  27. channel.join()
  28. this.channel = channel
  29. }
  30. }
  31. })