2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
2022-11-03 05:13:12 +00:00
|
|
|
<div :class="thumbnailBoxClass" :style="{ height: size, width: size }">
|
2019-10-29 18:06:21 +00:00
|
|
|
<img
|
2022-10-27 19:32:23 +00:00
|
|
|
v-if="!imgError && src"
|
2019-10-29 18:06:21 +00:00
|
|
|
:src="src"
|
2020-02-05 05:57:22 +00:00
|
|
|
:class="thumbnailClass"
|
2022-10-27 19:32:23 +00:00
|
|
|
@error="onImgError"
|
2019-10-29 18:06:21 +00:00
|
|
|
/>
|
|
|
|
<Avatar
|
|
|
|
v-else
|
2022-08-03 08:41:33 +00:00
|
|
|
:username="userNameWithoutEmoji"
|
2020-02-05 05:57:22 +00:00
|
|
|
:class="thumbnailClass"
|
2019-11-14 08:16:43 +00:00
|
|
|
:size="avatarSize"
|
2019-12-16 12:53:14 +00:00
|
|
|
/>
|
2021-10-05 09:05:32 +00:00
|
|
|
<img
|
2022-10-27 19:32:23 +00:00
|
|
|
v-if="badgeSrc"
|
2021-10-05 09:05:32 +00:00
|
|
|
class="source-badge"
|
|
|
|
:style="badgeStyle"
|
2022-10-27 19:32:23 +00:00
|
|
|
:src="`/integrations/channels/badges/${badgeSrc}.png`"
|
|
|
|
alt="Badge"
|
2021-09-09 18:30:52 +00:00
|
|
|
/>
|
2020-07-04 06:12:47 +00:00
|
|
|
<div
|
|
|
|
v-if="showStatusIndicator"
|
|
|
|
:class="`source-badge user-online-status user-online-status--${status}`"
|
|
|
|
:style="statusStyle"
|
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
/**
|
|
|
|
* Thumbnail Component
|
|
|
|
* Src - source for round image
|
|
|
|
* Size - Size of the thumbnail
|
|
|
|
* Badge - Chat source indication { fb / telegram }
|
2022-10-27 19:32:23 +00:00
|
|
|
* Username - Username for avatar
|
2019-08-14 09:48:44 +00:00
|
|
|
*/
|
2019-10-29 18:06:21 +00:00
|
|
|
import Avatar from './Avatar';
|
2022-08-03 08:41:33 +00:00
|
|
|
import { removeEmoji } from 'shared/helpers/emoji';
|
2019-10-29 18:06:21 +00:00
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
export default {
|
2019-10-29 18:06:21 +00:00
|
|
|
components: {
|
|
|
|
Avatar,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
props: {
|
|
|
|
src: {
|
|
|
|
type: String,
|
2020-02-02 17:04:16 +00:00
|
|
|
default: '',
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: '40px',
|
|
|
|
},
|
|
|
|
badge: {
|
|
|
|
type: String,
|
2022-10-27 19:32:23 +00:00
|
|
|
default: '',
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2019-10-29 18:06:21 +00:00
|
|
|
username: {
|
|
|
|
type: String,
|
2020-02-02 17:04:16 +00:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
status: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
2019-10-29 18:06:21 +00:00
|
|
|
},
|
2020-02-05 05:57:22 +00:00
|
|
|
hasBorder: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-12-01 07:15:39 +00:00
|
|
|
shouldShowStatusAlways: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-07-09 08:33:55 +00:00
|
|
|
variant: {
|
|
|
|
type: String,
|
|
|
|
default: 'circle',
|
|
|
|
},
|
2019-10-29 18:06:21 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
imgError: false,
|
|
|
|
};
|
|
|
|
},
|
2019-11-14 08:16:43 +00:00
|
|
|
computed: {
|
2022-08-03 08:41:33 +00:00
|
|
|
userNameWithoutEmoji() {
|
|
|
|
return removeEmoji(this.username);
|
|
|
|
},
|
2020-07-04 06:12:47 +00:00
|
|
|
showStatusIndicator() {
|
2021-12-01 07:15:39 +00:00
|
|
|
if (this.shouldShowStatusAlways) return true;
|
2020-07-04 06:12:47 +00:00
|
|
|
return this.status === 'online' || this.status === 'busy';
|
|
|
|
},
|
2019-11-14 08:16:43 +00:00
|
|
|
avatarSize() {
|
|
|
|
return Number(this.size.replace(/\D+/g, ''));
|
|
|
|
},
|
2022-10-27 19:32:23 +00:00
|
|
|
badgeSrc() {
|
|
|
|
return {
|
|
|
|
instagram_direct_message: 'instagram-dm',
|
|
|
|
facebook: 'messenger',
|
|
|
|
'twitter-tweet': 'twitter-tweet',
|
|
|
|
'twitter-dm': 'twitter-dm',
|
|
|
|
whatsapp: 'whatsapp',
|
|
|
|
sms: 'sms',
|
|
|
|
'Channel::Line': 'line',
|
|
|
|
'Channel::Telegram': 'telegram',
|
|
|
|
'Channel::WebWidget': '',
|
|
|
|
}[this.badge];
|
|
|
|
},
|
2019-11-14 08:16:43 +00:00
|
|
|
badgeStyle() {
|
2021-10-06 14:04:34 +00:00
|
|
|
const size = Math.floor(this.avatarSize / 3);
|
|
|
|
const badgeSize = `${size + 2}px`;
|
|
|
|
const borderRadius = `${size / 2}px`;
|
|
|
|
return { width: badgeSize, height: badgeSize, borderRadius };
|
2019-11-14 08:16:43 +00:00
|
|
|
},
|
2020-02-02 17:04:16 +00:00
|
|
|
statusStyle() {
|
|
|
|
const statusSize = `${this.avatarSize / 4}px`;
|
|
|
|
return { width: statusSize, height: statusSize };
|
|
|
|
},
|
2020-02-05 05:57:22 +00:00
|
|
|
thumbnailClass() {
|
|
|
|
const classname = this.hasBorder ? 'border' : '';
|
2022-07-09 08:33:55 +00:00
|
|
|
const variant =
|
|
|
|
this.variant === 'circle' ? 'thumbnail-rounded' : 'thumbnail-square';
|
|
|
|
return `user-thumbnail ${classname} ${variant}`;
|
2020-02-05 05:57:22 +00:00
|
|
|
},
|
2022-11-03 05:13:12 +00:00
|
|
|
thumbnailBoxClass() {
|
|
|
|
const boxClass = this.variant === 'circle' ? 'is-rounded' : '';
|
|
|
|
return `user-thumbnail-box ${boxClass}`;
|
|
|
|
},
|
2019-11-14 08:16:43 +00:00
|
|
|
},
|
2020-05-31 10:46:22 +00:00
|
|
|
watch: {
|
2022-10-27 19:32:23 +00:00
|
|
|
src(value, oldValue) {
|
|
|
|
if (value !== oldValue && this.imgError) {
|
|
|
|
this.imgError = false;
|
|
|
|
}
|
2020-05-31 10:46:22 +00:00
|
|
|
},
|
|
|
|
},
|
2019-10-29 18:06:21 +00:00
|
|
|
methods: {
|
|
|
|
onImgError() {
|
|
|
|
this.imgError = true;
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
};
|
2019-10-16 09:06:17 +00:00
|
|
|
</script>
|
2019-12-15 18:23:04 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.user-thumbnail-box {
|
2021-12-01 09:48:41 +00:00
|
|
|
flex: 0 0 auto;
|
|
|
|
max-width: 100%;
|
2019-12-15 18:23:04 +00:00
|
|
|
position: relative;
|
|
|
|
|
2022-11-03 05:13:12 +00:00
|
|
|
&.is-rounded {
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
|
2019-12-15 18:23:04 +00:00
|
|
|
.user-thumbnail {
|
|
|
|
border-radius: 50%;
|
2022-07-09 08:33:55 +00:00
|
|
|
&.thumbnail-square {
|
|
|
|
border-radius: var(--border-radius-large);
|
|
|
|
}
|
2019-12-15 18:23:04 +00:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
2020-02-05 05:57:22 +00:00
|
|
|
box-sizing: border-box;
|
2021-10-06 09:17:44 +00:00
|
|
|
object-fit: cover;
|
2020-02-05 05:57:22 +00:00
|
|
|
|
|
|
|
&.border {
|
|
|
|
border: 1px solid white;
|
|
|
|
}
|
2019-12-15 18:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.source-badge {
|
2021-10-06 14:04:34 +00:00
|
|
|
background: white;
|
|
|
|
border-radius: var(--border-radius-small);
|
2021-12-01 09:48:41 +00:00
|
|
|
bottom: var(--space-minus-micro);
|
2021-10-06 14:04:34 +00:00
|
|
|
box-shadow: var(--shadow-small);
|
2021-12-01 09:48:41 +00:00
|
|
|
height: var(--space-slab);
|
2021-10-06 14:04:34 +00:00
|
|
|
padding: var(--space-micro);
|
2019-12-15 18:23:04 +00:00
|
|
|
position: absolute;
|
2021-12-01 09:48:41 +00:00
|
|
|
right: 0;
|
|
|
|
width: var(--space-slab);
|
2019-12-15 18:23:04 +00:00
|
|
|
}
|
2020-02-02 17:04:16 +00:00
|
|
|
|
2020-07-04 06:12:47 +00:00
|
|
|
.user-online-status {
|
2020-02-02 17:04:16 +00:00
|
|
|
border-radius: 50%;
|
2021-12-01 09:48:41 +00:00
|
|
|
bottom: var(--space-micro);
|
2020-02-02 17:04:16 +00:00
|
|
|
|
|
|
|
&:after {
|
|
|
|
content: ' ';
|
|
|
|
}
|
|
|
|
}
|
2020-07-04 06:12:47 +00:00
|
|
|
|
|
|
|
.user-online-status--online {
|
2021-12-01 09:48:41 +00:00
|
|
|
background: var(--g-400);
|
2020-07-04 06:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.user-online-status--busy {
|
2022-04-11 11:57:28 +00:00
|
|
|
background: var(--y-500);
|
2021-12-01 09:48:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.user-online-status--offline {
|
|
|
|
background: var(--s-500);
|
2020-07-04 06:12:47 +00:00
|
|
|
}
|
2019-12-15 18:23:04 +00:00
|
|
|
}
|
|
|
|
</style>
|