2018-12-12 18:00:01 -08:00
|
|
|
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
2020-10-19 12:35:46 -07:00
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
2020-10-20 11:18:23 -07:00
|
|
|
import {
|
|
|
|
faBullhorn,
|
|
|
|
faTimes
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
2020-10-19 12:35:46 -07:00
|
|
|
|
|
|
|
library.add(
|
2020-10-20 11:18:23 -07:00
|
|
|
faBullhorn,
|
|
|
|
faTimes
|
2020-10-19 12:35:46 -07:00
|
|
|
)
|
2018-12-12 18:00:01 -08:00
|
|
|
|
2018-01-26 06:11:34 -08:00
|
|
|
const chatPanel = {
|
2018-12-28 11:39:54 -08:00
|
|
|
props: [ 'floating' ],
|
2017-12-05 02:02:41 -08:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
currentMessage: '',
|
2018-04-10 14:17:05 -07:00
|
|
|
channel: null,
|
2018-04-24 00:48:30 -07:00
|
|
|
collapsed: true
|
2017-12-05 02:02:41 -08:00
|
|
|
}
|
|
|
|
},
|
2017-12-05 02:47:10 -08:00
|
|
|
computed: {
|
|
|
|
messages () {
|
|
|
|
return this.$store.state.chat.messages
|
|
|
|
}
|
2017-12-05 02:02:41 -08:00
|
|
|
},
|
|
|
|
methods: {
|
2017-12-05 02:49:40 -08:00
|
|
|
submit (message) {
|
2019-07-05 00:02:14 -07:00
|
|
|
this.$store.state.chat.channel.push('new_msg', { text: message }, 10000)
|
2017-12-05 02:49:40 -08:00
|
|
|
this.currentMessage = ''
|
2018-04-10 14:17:05 -07:00
|
|
|
},
|
|
|
|
togglePanel () {
|
|
|
|
this.collapsed = !this.collapsed
|
2018-12-16 15:52:27 -08:00
|
|
|
},
|
|
|
|
userProfileLink (user) {
|
2018-12-29 06:25:45 -08:00
|
|
|
return generateProfileLink(user.id, user.username, this.$store.state.instance.restrictedNicknames)
|
2017-12-05 02:02:41 -08:00
|
|
|
}
|
2021-03-03 06:46:53 -08:00
|
|
|
},
|
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 02:02:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-26 06:11:34 -08:00
|
|
|
export default chatPanel
|