hardlounge/client/components/Message.vue

151 lines
4.4 KiB
Vue
Raw Normal View History

<template>
<div
:id="'msg-' + message.id"
:class="[
'msg',
{
self: message.self,
highlight: message.highlight || focused,
'previous-source': isPreviousSource,
},
]"
2019-12-15 11:46:43 +00:00
:data-type="message.type"
:data-command="message.command"
:data-from="message.from && message.from.nick"
>
<span
aria-hidden="true"
:aria-label="messageTimeLocale"
class="time tooltipped tooltipped-e"
>{{ messageTime }}
</span>
<template v-if="message.type === 'unhandled'">
<span class="from">[{{ message.command }}]</span>
<span class="content">
2019-07-17 09:33:59 +00:00
<span v-for="(param, id) in message.params" :key="id">{{ param }} </span>
</span>
</template>
2018-07-09 10:44:12 +00:00
<template v-else-if="isAction()">
<span class="from"><span class="only-copy">***&nbsp;</span></span>
<component :is="messageComponent" :network="network" :message="message" />
2018-07-09 10:44:12 +00:00
</template>
2018-07-13 10:49:09 +00:00
<template v-else-if="message.type === 'action'">
<span class="from"><span class="only-copy">*&nbsp;</span></span>
<span class="content" dir="auto">
2020-04-24 07:20:40 +00: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 17:57:14 +00:00
:keep-scroll-position="keepScrollPosition"
:link="preview"
2020-03-09 16:39:05 +00:00
:channel="channel"
/>
</span>
</template>
2018-07-09 10:44:12 +00:00
<template v-else>
2019-07-17 09:33:59 +00:00
<span v-if="message.type === 'message'" class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy" aria-hidden="true">&lt;</span>
2020-04-24 07:20:40 +00:00
<Username :user="message.from" :network="network" :channel="channel" />
<span class="only-copy" aria-hidden="true">&gt;&nbsp;</span>
</template>
</span>
2019-10-22 16:44:05 +00:00
<span v-else-if="message.type === 'plugin'" class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy" aria-hidden="true">[</span>
2019-10-22 17:38:13 +00:00
{{ message.from.nick }}
<span class="only-copy" aria-hidden="true">]&nbsp;</span>
2019-10-22 16:44:05 +00:00
</template>
</span>
2019-07-17 09:33:59 +00:00
<span v-else class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy" aria-hidden="true">-</span>
2020-04-24 07:20:40 +00:00
<Username :user="message.from" :network="network" :channel="channel" />
<span class="only-copy" aria-hidden="true">-&nbsp;</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 08:46:39 +00: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 09:33:59 +00:00
<ParsedMessage :network="network" :message="message" />
2018-07-10 11:57:11 +00:00
<LinkPreview
v-for="preview in message.previews"
:key="preview.link"
2018-07-29 17:57:14 +00:00
:keep-scroll-position="keepScrollPosition"
:link="preview"
2020-03-09 16:39:05 +00:00
:channel="channel"
/>
</span>
</template>
</div>
</template>
<script>
2019-12-17 22:10:50 +00:00
const constants = require("../js/constants");
2020-01-08 09:11:44 +00:00
import localetime from "../js/helpers/localetime";
import dayjs from "dayjs";
import Username from "./Username.vue";
2018-07-10 11:57:11 +00:00
import LinkPreview from "./LinkPreview.vue";
import ParsedMessage from "./ParsedMessage.vue";
2018-07-09 10:44:12 +00:00
import MessageTypes from "./MessageTypes";
MessageTypes.ParsedMessage = ParsedMessage;
2018-07-10 11:57:11 +00:00
MessageTypes.LinkPreview = LinkPreview;
2018-07-09 10:44:12 +00:00
MessageTypes.Username = Username;
export default {
name: "Message",
2018-07-09 10:44:12 +00:00
components: MessageTypes,
props: {
message: Object,
2019-11-09 22:21:34 +00:00
channel: Object,
2018-07-19 17:44:24 +00:00
network: Object,
keepScrollPosition: Function,
isPreviousSource: Boolean,
focused: Boolean,
},
2018-07-09 10:44:12 +00:00
computed: {
2020-02-29 09:37:45 +00: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 09:37:45 +00:00
return constants.timeFormats[format];
},
messageTime() {
return dayjs(this.message.time).format(this.timeFormat);
},
2020-01-08 09:11:44 +00:00
messageTimeLocale() {
return localetime(this.message.time);
},
2018-07-09 10:44:12 +00:00
messageComponent() {
return "message-" + this.message.type;
},
},
methods: {
isAction() {
return typeof MessageTypes["message-" + this.message.type] !== "undefined";
},
},
};
</script>