2020-01-29 13:37:25 -06:00
|
|
|
<template>
|
2020-10-18 02:58:20 -05:00
|
|
|
<div class="thvuemwp" :class="{ isMe }" v-size="{ max: [400, 500] }">
|
2020-10-17 06:12:00 -05:00
|
|
|
<MkAvatar class="avatar" :user="message.user"/>
|
2020-01-29 13:37:25 -06:00
|
|
|
<div class="content">
|
2020-10-17 06:12:00 -05:00
|
|
|
<div class="balloon" :class="{ noText: message.text == null }" >
|
2020-12-25 19:47:36 -06:00
|
|
|
<button class="delete-button" v-if="isMe" :title="$ts.delete" @click="del">
|
2020-02-13 00:53:02 -06:00
|
|
|
<img src="/assets/remove.png" alt="Delete"/>
|
2020-01-29 13:37:25 -06:00
|
|
|
</button>
|
|
|
|
<div class="content" v-if="!message.isDeleted">
|
2020-12-18 19:55:52 -06:00
|
|
|
<Mfm class="text" v-if="message.text" ref="text" :text="message.text" :i="$i"/>
|
2020-01-29 13:37:25 -06:00
|
|
|
<div class="file" v-if="message.file">
|
|
|
|
<a :href="message.file.url" rel="noopener" target="_blank" :title="message.file.name">
|
2020-07-18 10:24:07 -05:00
|
|
|
<img v-if="message.file.type.split('/')[0] == 'image'" :src="message.file.url" :alt="message.file.name"/>
|
2020-01-29 13:37:25 -06:00
|
|
|
<p v-else>{{ message.file.name }}</p>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="content" v-else>
|
2020-12-25 19:47:36 -06:00
|
|
|
<p class="is-deleted">{{ $ts.deleted }}</p>
|
2020-01-29 13:37:25 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div></div>
|
2020-10-17 06:12:00 -05:00
|
|
|
<MkUrlPreview v-for="url in urls" :url="url" :key="url" style="margin: 8px 0;"/>
|
2020-01-29 13:37:25 -06:00
|
|
|
<footer>
|
|
|
|
<template v-if="isGroup">
|
2020-12-25 19:47:36 -06:00
|
|
|
<span class="read" v-if="message.reads.length > 0">{{ $ts.messageRead }} {{ message.reads.length }}</span>
|
2020-01-29 13:37:25 -06:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2020-12-25 19:47:36 -06:00
|
|
|
<span class="read" v-if="isMe && message.isRead">{{ $ts.messageRead }}</span>
|
2020-01-29 13:37:25 -06:00
|
|
|
</template>
|
2020-10-17 06:12:00 -05:00
|
|
|
<MkTime :time="message.createdAt"/>
|
|
|
|
<template v-if="message.is_edited"><Fa icon="pencil-alt"/></template>
|
2020-01-29 13:37:25 -06:00
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 06:12:00 -05:00
|
|
|
import { defineComponent } from 'vue';
|
2020-03-22 00:38:33 -05:00
|
|
|
import { parse } from '../../../mfm/parse';
|
|
|
|
import { unique } from '../../../prelude/array';
|
2020-10-17 06:12:00 -05:00
|
|
|
import MkUrlPreview from '@/components/url-preview.vue';
|
|
|
|
import * as os from '@/os';
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
export default defineComponent({
|
2020-03-22 00:38:33 -05:00
|
|
|
components: {
|
|
|
|
MkUrlPreview
|
|
|
|
},
|
2020-01-29 13:37:25 -06:00
|
|
|
props: {
|
|
|
|
message: {
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
isGroup: {
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isMe(): boolean {
|
2020-12-18 19:55:52 -06:00
|
|
|
return this.message.userId === this.$i.id;
|
2020-01-29 13:37:25 -06:00
|
|
|
},
|
|
|
|
urls(): string[] {
|
|
|
|
if (this.message.text) {
|
|
|
|
const ast = parse(this.message.text);
|
|
|
|
return unique(ast
|
2020-08-01 23:49:28 -05:00
|
|
|
.filter(t => ((t.node.type === 'url' || t.node.type === 'link') && t.node.props.url && !t.node.props.silent))
|
2020-01-29 13:37:25 -06:00
|
|
|
.map(t => t.node.props.url));
|
|
|
|
} else {
|
2020-08-01 23:49:28 -05:00
|
|
|
return [];
|
2020-01-29 13:37:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
del() {
|
2020-10-17 06:12:00 -05:00
|
|
|
os.api('messaging/messages/delete', {
|
2020-01-29 13:37:25 -06:00
|
|
|
messageId: this.message.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.thvuemwp {
|
|
|
|
$me-balloon-color: var(--accent);
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
background-color: transparent;
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
display: block;
|
|
|
|
width: 54px;
|
|
|
|
height: 54px;
|
|
|
|
transition: all 0.1s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .content {
|
|
|
|
min-width: 0;
|
|
|
|
|
|
|
|
> .balloon {
|
|
|
|
position: relative;
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 0;
|
|
|
|
min-height: 38px;
|
|
|
|
border-radius: 16px;
|
|
|
|
max-width: 100%;
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
content: "";
|
|
|
|
pointer-events: none;
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
& + * {
|
|
|
|
clear: both;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
> .delete-button {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .delete-button {
|
|
|
|
display: none;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
top: -4px;
|
|
|
|
right: -4px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
cursor: pointer;
|
|
|
|
outline: none;
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
box-shadow: none;
|
|
|
|
background: transparent;
|
|
|
|
|
|
|
|
> img {
|
|
|
|
vertical-align: bottom;
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .content {
|
|
|
|
max-width: 100%;
|
|
|
|
|
|
|
|
> .is-deleted {
|
|
|
|
display: block;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
2021-03-02 07:57:16 -06:00
|
|
|
overflow: hidden;
|
2020-01-29 13:37:25 -06:00
|
|
|
overflow-wrap: break-word;
|
|
|
|
font-size: 1em;
|
|
|
|
color: rgba(#000, 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
|
|
|
display: block;
|
|
|
|
margin: 0;
|
|
|
|
padding: 12px 18px;
|
2021-03-02 07:57:16 -06:00
|
|
|
overflow: hidden;
|
2020-01-29 13:37:25 -06:00
|
|
|
overflow-wrap: break-word;
|
|
|
|
word-break: break-word;
|
|
|
|
font-size: 1em;
|
|
|
|
color: rgba(#000, 0.8);
|
|
|
|
|
|
|
|
& + .file {
|
|
|
|
> a {
|
|
|
|
border-radius: 0 0 16px 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .file {
|
|
|
|
> a {
|
|
|
|
display: block;
|
|
|
|
max-width: 100%;
|
|
|
|
border-radius: 16px;
|
2021-03-02 07:57:16 -06:00
|
|
|
overflow: hidden;
|
2020-01-29 13:37:25 -06:00
|
|
|
text-decoration: none;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: none;
|
|
|
|
|
|
|
|
> p {
|
|
|
|
background: #ccc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> * {
|
|
|
|
display: block;
|
|
|
|
margin: 0;
|
|
|
|
width: 100%;
|
|
|
|
max-height: 512px;
|
|
|
|
object-fit: contain;
|
2020-03-28 08:10:14 -05:00
|
|
|
box-sizing: border-box;
|
2020-01-29 13:37:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
> p {
|
|
|
|
padding: 30px;
|
|
|
|
text-align: center;
|
|
|
|
color: #555;
|
|
|
|
background: #ddd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
display: block;
|
|
|
|
margin: 2px 0 0 0;
|
2020-02-14 12:25:54 -06:00
|
|
|
font-size: 0.65em;
|
2020-01-29 13:37:25 -06:00
|
|
|
|
|
|
|
> .read {
|
|
|
|
margin: 0 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> [data-icon] {
|
|
|
|
margin-left: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
&:not(.isMe) {
|
2020-03-20 07:58:04 -05:00
|
|
|
padding-left: var(--margin);
|
2020-01-29 13:37:25 -06:00
|
|
|
|
|
|
|
> .content {
|
|
|
|
padding-left: 16px;
|
|
|
|
padding-right: 32px;
|
|
|
|
|
|
|
|
> .balloon {
|
2020-03-20 08:42:35 -05:00
|
|
|
$color: var(--messageBg);
|
2020-01-29 13:37:25 -06:00
|
|
|
background: $color;
|
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
&.noText {
|
2020-01-29 13:37:25 -06:00
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
&:not(.noText):before {
|
2020-01-29 13:37:25 -06:00
|
|
|
left: -14px;
|
|
|
|
border-top: solid 8px transparent;
|
|
|
|
border-right: solid 8px $color;
|
|
|
|
border-bottom: solid 8px transparent;
|
|
|
|
border-left: solid 8px transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .content {
|
|
|
|
> .text {
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
&.isMe {
|
2020-01-29 13:37:25 -06:00
|
|
|
flex-direction: row-reverse;
|
2020-03-20 07:58:04 -05:00
|
|
|
padding-right: var(--margin);
|
2020-01-29 13:37:25 -06:00
|
|
|
|
|
|
|
> .content {
|
|
|
|
padding-right: 16px;
|
|
|
|
padding-left: 32px;
|
|
|
|
text-align: right;
|
|
|
|
|
|
|
|
> .balloon {
|
|
|
|
background: $me-balloon-color;
|
|
|
|
text-align: left;
|
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
&.noText {
|
2020-01-29 13:37:25 -06:00
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
&:not(.noText):before {
|
2020-01-29 13:37:25 -06:00
|
|
|
right: -14px;
|
|
|
|
left: auto;
|
|
|
|
border-top: solid 8px transparent;
|
|
|
|
border-right: solid 8px transparent;
|
|
|
|
border-bottom: solid 8px transparent;
|
|
|
|
border-left: solid 8px $me-balloon-color;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .content {
|
|
|
|
|
|
|
|
> p.is-deleted {
|
|
|
|
color: rgba(#fff, 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
2020-10-17 06:12:00 -05:00
|
|
|
&, ::v-deep(*) {
|
2020-01-29 13:37:25 -06:00
|
|
|
color: #fff !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
text-align: right;
|
|
|
|
|
|
|
|
> .read {
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-18 02:58:20 -05:00
|
|
|
|
|
|
|
&.max-width_400px {
|
|
|
|
> .avatar {
|
|
|
|
width: 48px;
|
|
|
|
height: 48px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .content {
|
|
|
|
> .balloon {
|
|
|
|
> .content {
|
|
|
|
> .text {
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.max-width_500px {
|
|
|
|
> .content {
|
|
|
|
> .balloon {
|
|
|
|
> .content {
|
|
|
|
> .text {
|
|
|
|
padding: 8px 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 13:37:25 -06:00
|
|
|
}
|
|
|
|
</style>
|