aboutsummaryrefslogtreecommitdiff
path: root/src/components/shout_panel/shout_panel.js
blob: fb0c5aa2136a6950c91cad8d651bd3fa475b4a1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
import { library } from '@fortawesome/fontawesome-svg-core'
import {
  faBullhorn,
  faTimes
} from '@fortawesome/free-solid-svg-icons'

library.add(
  faBullhorn,
  faTimes
)

const shoutPanel = {
  props: ['floating'],
  data () {
    return {
      currentMessage: '',
      channel: null,
      collapsed: true
    }
  },
  computed: {
    messages () {
      return this.$store.state.shout.messages
    }
  },
  methods: {
    submit (message) {
      this.$store.state.shout.channel.push('new_msg', { text: message }, 10000)
      this.currentMessage = ''
    },
    togglePanel () {
      this.collapsed = !this.collapsed
    },
    userProfileLink (user) {
      return generateProfileLink(user.id, user.username, this.$store.state.instance.restrictedNicknames)
    }
  },
  watch: {
    messages (newVal) {
      const scrollEl = this.$el.querySelector('.chat-window')
      if (!scrollEl) return
      if (scrollEl.scrollTop + scrollEl.offsetHeight + 20 > scrollEl.scrollHeight) {
        this.$nextTick(() => {
          if (!scrollEl) return
          scrollEl.scrollTop = scrollEl.scrollHeight - scrollEl.offsetHeight
        })
      }
    }
  }
}

export default shoutPanel