aboutsummaryrefslogtreecommitdiff
path: root/src/components/chat_list_item/chat_list_item.js
blob: e5032176f3850c62ee1b9a1a161e66fbd1b65117 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { mapState } from 'vuex'
import StatusBody from '../status_content/status_content.vue'
import fileType from 'src/services/file_type/file_type.service'
import UserAvatar from '../user_avatar/user_avatar.vue'
import AvatarList from '../avatar_list/avatar_list.vue'
import Timeago from '../timeago/timeago.vue'
import ChatTitle from '../chat_title/chat_title.vue'

const ChatListItem = {
  name: 'ChatListItem',
  props: [
    'chat'
  ],
  components: {
    UserAvatar,
    AvatarList,
    Timeago,
    ChatTitle,
    StatusBody
  },
  computed: {
    ...mapState({
      currentUser: state => state.users.currentUser
    }),
    attachmentInfo () {
      if (this.chat.lastMessage.attachments.length === 0) { return }

      const types = this.chat.lastMessage.attachments.map(file => fileType.fileType(file.mimetype))
      if (types.includes('video')) {
        return this.$t('file_type.video')
      } else if (types.includes('audio')) {
        return this.$t('file_type.audio')
      } else if (types.includes('image')) {
        return this.$t('file_type.image')
      } else {
        return this.$t('file_type.file')
      }
    },
    messageForStatusContent () {
      const message = this.chat.lastMessage
      const messageEmojis = message ? message.emojis : []
      const isYou = message && message.account_id === this.currentUser.id
      const content = message ? (this.attachmentInfo || message.content) : ''
      const messagePreview = isYou ? `<i>${this.$t('chats.you')}</i> ${content}` : content
      return {
        summary: '',
        emojis: messageEmojis,
        raw_html: messagePreview,
        text: messagePreview,
        attachments: []
      }
    }
  },
  methods: {
    openChat (_e) {
      if (this.chat.id) {
        this.$router.push({
          name: 'chat',
          params: {
            username: this.currentUser.screen_name,
            recipient_id: this.chat.account.id
          }
        })
      }
    }
  }
}

export default ChatListItem