thelounge/client/components/Message.vue

143 lines
4.1 KiB
Vue
Raw Normal View History

<template>
<div
:id="'msg-' + message.id"
:class="[
'msg',
{self: message.self, highlight: message.highlight, 'previous-source': isPreviousSource},
]"
2019-12-15 12:46:43 +01:00
:data-type="message.type"
:data-command="message.command"
:data-from="message.from && message.from.nick"
>
2020-01-08 10:11:44 +01:00
<span :aria-label="messageTimeLocale" class="time tooltipped tooltipped-e"
2019-07-17 11:33:59 +02:00
>{{ messageTime }}
</span>
<template v-if="message.type === 'unhandled'">
<span class="from">[{{ message.command }}]</span>
<span class="content">
2019-07-17 11:33:59 +02:00
<span v-for="(param, id) in message.params" :key="id">{{ param }} </span>
</span>
</template>
2018-07-09 12:44:12 +02:00
<template v-else-if="isAction()">
<span class="from"><span class="only-copy">*** </span></span>
<component :is="messageComponent" :network="network" :message="message" />
2018-07-09 12:44:12 +02:00
</template>
2018-07-13 12:49:09 +02:00
<template v-else-if="message.type === 'action'">
<span class="from"><span class="only-copy">* </span></span>
<span class="content" dir="auto">
2020-04-24 09:20:40 +02:00
<Username
:user="message.from"
:network="network"
:channel="channel"
dir="auto"
/>&#32;<ParsedMessage :message="message" />
<LinkPreview
v-for="preview in message.previews"
:key="preview.link"
2018-07-29 19:57:14 +02:00
:keep-scroll-position="keepScrollPosition"
:link="preview"
2020-03-09 17:39:05 +01:00
:channel="channel"
/>
</span>
</template>
2018-07-09 12:44:12 +02:00
<template v-else>
2019-07-17 11:33:59 +02:00
<span v-if="message.type === 'message'" class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy">&lt;</span>
2020-04-24 09:20:40 +02:00
<Username :user="message.from" :network="network" :channel="channel" />
<span class="only-copy">&gt; </span>
</template>
</span>
2019-10-22 18:44:05 +02:00
<span v-else-if="message.type === 'plugin'" class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy">[</span>
2019-10-22 19:38:13 +02:00
{{ message.from.nick }}
2019-10-22 18:44:05 +02:00
<span class="only-copy">] </span>
</template>
</span>
2019-07-17 11:33:59 +02:00
<span v-else class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy">-</span>
2020-04-24 09:20:40 +02:00
<Username :user="message.from" :network="network" :channel="channel" />
<span class="only-copy">- </span>
</template>
</span>
<span class="content" dir="auto">
<span
v-if="message.showInActive"
aria-label="This message was shown in your active channel"
class="msg-shown-in-active tooltipped tooltipped-e"
><span></span
></span>
2020-04-24 10:46:39 +02:00
<span
v-if="message.statusmsgGroup"
:aria-label="`This message was only shown to users with ${message.statusmsgGroup} mode`"
class="msg-statusmsg tooltipped tooltipped-e"
><span>{{ message.statusmsgGroup }}</span></span
>
2019-07-17 11:33:59 +02:00
<ParsedMessage :network="network" :message="message" />
2018-07-10 13:57:11 +02:00
<LinkPreview
v-for="preview in message.previews"
:key="preview.link"
2018-07-29 19:57:14 +02:00
:keep-scroll-position="keepScrollPosition"
:link="preview"
2020-03-09 17:39:05 +01:00
:channel="channel"
/>
</span>
</template>
</div>
</template>
<script>
2019-12-17 23:10:50 +01:00
const constants = require("../js/constants");
2020-01-08 10:11:44 +01:00
import localetime from "../js/helpers/localetime";
import dayjs from "dayjs";
import Username from "./Username.vue";
2018-07-10 13:57:11 +02:00
import LinkPreview from "./LinkPreview.vue";
import ParsedMessage from "./ParsedMessage.vue";
2018-07-09 12:44:12 +02:00
import MessageTypes from "./MessageTypes";
MessageTypes.ParsedMessage = ParsedMessage;
2018-07-10 13:57:11 +02:00
MessageTypes.LinkPreview = LinkPreview;
2018-07-09 12:44:12 +02:00
MessageTypes.Username = Username;
export default {
name: "Message",
2018-07-09 12:44:12 +02:00
components: MessageTypes,
props: {
message: Object,
2019-11-09 23:21:34 +01:00
channel: Object,
2018-07-19 19:44:24 +02:00
network: Object,
keepScrollPosition: Function,
isPreviousSource: Boolean,
},
2018-07-09 12:44:12 +02:00
computed: {
2020-02-29 10:37:45 +01:00
timeFormat() {
let format;
if (this.$store.state.settings.use12hClock) {
format = this.$store.state.settings.showSeconds ? "msg12hWithSeconds" : "msg12h";
} else {
format = this.$store.state.settings.showSeconds ? "msgWithSeconds" : "msgDefault";
}
2020-02-29 10:37:45 +01:00
return constants.timeFormats[format];
},
messageTime() {
return dayjs(this.message.time).format(this.timeFormat);
},
2020-01-08 10:11:44 +01:00
messageTimeLocale() {
return localetime(this.message.time);
},
2018-07-09 12:44:12 +02:00
messageComponent() {
return "message-" + this.message.type;
},
},
methods: {
isAction() {
return typeof MessageTypes["message-" + this.message.type] !== "undefined";
},
},
};
</script>