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 (1118B)


  1. const shout = {
  2. state: {
  3. messages: [],
  4. channel: { state: '' },
  5. joined: false
  6. },
  7. mutations: {
  8. setChannel (state, channel) {
  9. state.channel = channel
  10. },
  11. addMessage (state, message) {
  12. state.messages.push(message)
  13. state.messages = state.messages.slice(-19, 20)
  14. },
  15. setMessages (state, messages) {
  16. state.messages = messages.slice(-19, 20)
  17. },
  18. setJoined (state, joined) {
  19. state.joined = joined
  20. }
  21. },
  22. actions: {
  23. initializeShout (store, socket) {
  24. const channel = socket.channel('chat:public')
  25. channel.joinPush.receive('ok', () => {
  26. store.commit('setJoined', true)
  27. })
  28. channel.onClose(() => {
  29. store.commit('setJoined', false)
  30. })
  31. channel.onError(() => {
  32. store.commit('setJoined', false)
  33. })
  34. channel.on('new_msg', (msg) => {
  35. store.commit('addMessage', msg)
  36. })
  37. channel.on('messages', ({ messages }) => {
  38. store.commit('setMessages', messages)
  39. })
  40. channel.join()
  41. store.commit('setChannel', channel)
  42. }
  43. }
  44. }
  45. export default shout