hardlounge/client/components/Message.vue

111 lines
2.9 KiB
Vue
Raw Normal View History

<template>
<div
:id="'msg-' + message.id"
:class="['msg', message.type, {self: message.self, highlight: message.highlight}]"
2018-07-29 17:57:14 +00:00
:data-from="message.from && message.from.nick">
<span
:aria-label="message.time | localetime"
class="time tooltipped tooltipped-e">{{ messageTime }} </span>
<template v-if="message.type === 'unhandled'">
<span class="from">[{{ message.command }}]</span>
<span class="content">
<span
v-for="(param, id) in message.params"
2018-07-10 07:45:54 +00:00
: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">*** </span></span>
2018-12-17 10:29:49 +00:00
<Component
2018-07-09 10:44:12 +00:00
:is="messageComponent"
2018-07-19 17:44:24 +00:00
:network="network"
2018-07-29 17:57:14 +00:00
: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">* </span></span>
<span class="content">
<Username :user="message.from" />&#32;<ParsedMessage
2018-07-19 17:44:24 +00:00
:network="network"
: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" />
</span>
</template>
2018-07-09 10:44:12 +00:00
<template v-else>
<span
v-if="message.type === 'message'"
class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy">&lt;</span>
2018-07-29 17:57:14 +00:00
<Username :user="message.from" />
<span class="only-copy">&gt; </span>
</template>
</span>
<span
v-else
class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy">-</span>
<Username :user="message.from" />
<span class="only-copy">- </span>
</template>
</span>
<span class="content">
<ParsedMessage
2018-07-19 17:44:24 +00:00
: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" />
</span>
</template>
</div>
</template>
<script>
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";
const moment = require("moment");
const constants = require("../js/constants");
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,
2018-07-19 17:44:24 +00:00
network: Object,
keepScrollPosition: Function,
},
2018-07-09 10:44:12 +00:00
computed: {
messageTime() {
const format = this.$root.settings.showSeconds ? constants.timeFormats.msgWithSeconds : constants.timeFormats.msgDefault;
return moment(this.message.time).format(format);
},
2018-07-09 10:44:12 +00:00
messageComponent() {
return "message-" + this.message.type;
},
},
mounted() {
require("../js/renderPreview");
},
2018-07-09 10:44:12 +00:00
methods: {
isAction() {
return typeof MessageTypes["message-" + this.message.type] !== "undefined";
},
},
};
</script>