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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<template>
<ListItem
:id="id"
:key="source.key"
class="list-item-style envelope"
:title="source.displayName"
:to="{ name: 'contact', params: { selectedGroup: selectedGroup, selectedContact: source.key } }">
<!-- @slot Icon slot -->
<template #icon>
<div class="app-content-list-item-icon">
<BaseAvatar :display-name="source.displayName" :url="avatarUrl" :size="40" />
</div>
</template>
<template #subtitle>
<div class="envelope__subtitle">
<span class="envelope__subtitle__subject">
{{ source.email }}
</span>
</div>
</template>
</ListItem>
</template>
<script>
import { NcListItem as ListItem } from '@nextcloud/vue'
import BaseAvatar from '@nextcloud/vue/dist/Components/NcAvatar'
export default {
name: 'ContactsListItem',
components: {
ListItem,
BaseAvatar,
},
props: {
index: {
type: Number,
required: true,
},
source: {
type: Object,
required: true,
},
},
data() {
return {
avatarUrl: undefined,
}
},
computed: {
selectedGroup() {
return this.$route.params.selectedGroup
},
selectedContact() {
return this.$route.params.selectedContact
},
// usable and valid html id for scrollTo
id() {
return window.btoa(this.source.key).slice(0, -2)
},
},
watch: {
async source() {
await this.loadAvatarUrl()
},
},
async mounted() {
await this.loadAvatarUrl()
},
methods: {
async loadAvatarUrl() {
this.avatarUrl = undefined
if (this.source.photo) {
const photoUrl = await this.source.getPhotoUrl()
if (!photoUrl) {
console.warn('contact has an invalid photo')
// Invalid photo data
return
}
this.avatarUrl = photoUrl
} else if (this.source.url) {
this.avatarUrl = `${this.source.url}?photo`
}
},
},
}
</script>
<style lang="scss" scoped>
.envelope {
.app-content-list-item-icon {
height: 40px; // To prevent some unexpected spacing below the avatar
}
&__subtitle {
display: flex;
gap: 4px;
&__subject {
color: var(--color-main-text);
line-height: 130%;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
.list-item-style {
list-style: none;
}
</style>
|