ChatHistory.vue
2.49 KB
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
70
71
72
73
74
75
76
<template>
<div class="chat-history">
<v-toolbar dense class="chat-history-toolbar">
<v-text-field flat solo full-width clearable prepend-icon="search" label="Search"></v-text-field>
</v-toolbar>
<vue-perfect-scrollbar class="chat-history--scrollbar">
<v-divider></v-divider>
<v-list two-line class="chat-history--list">
<v-subheader>History</v-subheader>
<template v-for="(item, index) in chats">
<v-divider :key="index"></v-divider>
<v-list-tile class="chat-list" avatar :key="item.title + index" :to="chatRoute(item.uuid)">
<v-list-tile-avatar :color="randomAvatarColor(item)">
<img :src="item.user.avatar" v-if="item.users.length === 1">
<span v-else class="white--text headline">{{ firstLetter(item.title)}}</span>
</v-list-tile-avatar>
<v-list-tile-content>
<v-list-tile-title> {{computeTitle(item)}}</v-list-tile-title>
<v-list-tile-sub-title>Some Latest message</v-list-tile-sub-title>
</v-list-tile-content>
<v-list-tile-action>
<v-list-tile-action-text>
{{ formatChatTime(item.created_at) }}
</v-list-tile-action-text>
<v-circle dot small :color="chatStatusColor(item)"></v-circle>
</v-list-tile-action>
</v-list-tile>
</template>
</v-list>
</vue-perfect-scrollbar>
</div>
</template>
<script>
import { Groups } from '@/api/chat';
import { getUserById } from '@/api/user';
import VCircle from '@/components/circle/VCircle';
import Util from '@/util';
import VuePerfectScrollbar from 'vue-perfect-scrollbar';
export default {
components: {
VuePerfectScrollbar,
VCircle
},
data: () => ({
chats: Groups,
}),
methods: {
chatRoute (id) {
return '/chat/messaging/' + id;
},
firstLetter (title) {
return title.charAt(0);
},
formatChatTime (s) {
return new Date(s).toLocaleDateString();
},
computeTitle (item) {
let username = (item.users.length === 1) ? getUserById(item.users[0]).username : '';
return item.users.length === 1 ? username : item.title;
},
randomAvatarColor (item) {
return item.users.length === 1
? ''
: Util.randomElement(['blue', 'indigo', 'success', 'error', 'pink']);
},
chatStatusColor (item) {
return Util.randomElement(['blue', 'indigo', 'success', 'error', 'pink']);
}
}
};
</script>