logo

pleroma-fe

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

chat_new.js (1924B)


  1. import { mapState, mapGetters } from 'vuex'
  2. import BasicUserCard from '../basic_user_card/basic_user_card.vue'
  3. import UserAvatar from '../user_avatar/user_avatar.vue'
  4. import { library } from '@fortawesome/fontawesome-svg-core'
  5. import {
  6. faSearch,
  7. faChevronLeft
  8. } from '@fortawesome/free-solid-svg-icons'
  9. library.add(
  10. faSearch,
  11. faChevronLeft
  12. )
  13. const chatNew = {
  14. components: {
  15. BasicUserCard,
  16. UserAvatar
  17. },
  18. data () {
  19. return {
  20. suggestions: [],
  21. userIds: [],
  22. loading: false,
  23. query: ''
  24. }
  25. },
  26. async created () {
  27. const { chats } = await this.backendInteractor.chats()
  28. chats.forEach(chat => this.suggestions.push(chat.account))
  29. },
  30. computed: {
  31. users () {
  32. return this.userIds.map(userId => this.findUser(userId))
  33. },
  34. availableUsers () {
  35. if (this.query.length !== 0) {
  36. return this.users
  37. } else {
  38. return this.suggestions
  39. }
  40. },
  41. ...mapState({
  42. currentUser: state => state.users.currentUser,
  43. backendInteractor: state => state.api.backendInteractor
  44. }),
  45. ...mapGetters(['findUser'])
  46. },
  47. methods: {
  48. goBack () {
  49. this.$emit('cancel')
  50. },
  51. goToChat (user) {
  52. this.$router.push({ name: 'chat', params: { recipient_id: user.id } })
  53. },
  54. onInput () {
  55. this.search(this.query)
  56. },
  57. addUser (user) {
  58. this.selectedUserIds.push(user.id)
  59. this.query = ''
  60. },
  61. removeUser (userId) {
  62. this.selectedUserIds = this.selectedUserIds.filter(id => id !== userId)
  63. },
  64. search (query) {
  65. if (!query) {
  66. this.loading = false
  67. return
  68. }
  69. this.loading = true
  70. this.userIds = []
  71. this.$store.dispatch('search', { q: query, resolve: true, type: 'accounts' })
  72. .then(data => {
  73. this.loading = false
  74. this.userIds = data.accounts.map(a => a.id)
  75. })
  76. }
  77. }
  78. }
  79. export default chatNew