hardlounge/client/components/Chat.vue

238 lines
5.6 KiB
Vue
Raw Normal View History

<template>
<div id="chat-container" class="window" :data-current-channel="channel.name" lang="">
2018-07-08 13:42:54 +00:00
<div
id="chat"
:class="{
'hide-motd': !$store.state.settings.motd,
'colored-nicks': $store.state.settings.coloredNicks,
2020-02-29 09:51:12 +00:00
'time-seconds': $store.state.settings.showSeconds,
'time-12h': $store.state.settings.use12hClock,
}"
>
<div
:id="'chan-' + channel.id"
2019-12-04 06:58:23 +00:00
class="chat-view"
:data-type="channel.type"
:aria-label="channel.name"
role="tabpanel"
>
<div class="header">
<SidebarToggle />
<span class="title" :aria-label="'Currently open ' + channel.type">{{
channel.name
}}</span>
<div v-if="channel.editTopic === true" class="topic-container">
<input
2019-12-19 13:06:33 +00:00
ref="topicInput"
:value="channel.topic"
class="topic-input"
placeholder="Set channel topic"
2020-08-29 08:46:11 +00:00
enterkeyhint="done"
@keyup.enter="saveTopic"
@keyup.esc="channel.editTopic = false"
/>
<span aria-label="Save topic" class="save-topic" @click="saveTopic">
<span type="button" aria-label="Save topic"></span>
</span>
</div>
<span
v-else
:title="channel.topic"
:class="{topic: true, empty: !channel.topic}"
@dblclick="editTopic"
2019-07-17 09:33:59 +00:00
><ParsedMessage
v-if="channel.topic"
:network="network"
:text="channel.topic"
/></span>
2019-12-31 16:21:34 +00:00
<MessageSearchForm
v-if="
$store.state.settings.searchEnabled &&
['channel', 'query'].includes(channel.type)
"
2019-12-31 16:21:34 +00:00
:network="network"
:channel="channel"
/>
<button
class="mentions"
aria-label="Open your mentions"
@click="openMentions"
/>
2019-11-09 22:21:34 +00:00
<button
class="menu"
aria-label="Open the context menu"
@click="openContextMenu"
/>
<span
v-if="channel.type === 'channel'"
class="rt-tooltip tooltipped tooltipped-w"
aria-label="Toggle user list"
>
<button
class="rt"
aria-label="Toggle user list"
@click="$store.commit('toggleUserlist')"
/>
</span>
</div>
2019-07-17 09:33:59 +00:00
<div v-if="channel.type === 'special'" class="chat-content">
<div class="chat">
<div class="messages">
<div class="msg">
<component
:is="specialComponent"
2018-07-19 17:44:24 +00:00
:network="network"
:channel="channel"
/>
</div>
</div>
</div>
2018-07-10 09:16:24 +00:00
</div>
2019-07-17 09:33:59 +00:00
<div v-else class="chat-content">
<div
2019-07-17 09:33:59 +00:00
:class="[
'scroll-down tooltipped tooltipped-w tooltipped-no-touch',
{'scroll-down-shown': !channel.scrolledToBottom},
]"
aria-label="Jump to recent messages"
@click="$refs.messageList.jumpToBottom()"
>
<div class="scroll-down-arrow" />
</div>
<ChatUserList v-if="channel.type === 'channel'" :channel="channel" />
<MessageList
ref="messageList"
:network="network"
:channel="channel"
:focused="focused"
/>
</div>
</div>
</div>
2018-08-31 10:43:21 +00:00
<div
v-if="$store.state.currentUserVisibleError"
2018-10-16 10:21:16 +00:00
id="user-visible-error"
@click="hideUserVisibleError"
2019-07-17 09:33:59 +00:00
>
{{ $store.state.currentUserVisibleError }}
2019-07-17 09:33:59 +00:00
</div>
<ChatInput :network="network" :channel="channel" />
</div>
</template>
<script>
2019-11-09 22:21:34 +00:00
import socket from "../js/socket";
2020-03-16 17:58:40 +00:00
import eventbus from "../js/eventbus";
2018-07-12 08:41:40 +00:00
import ParsedMessage from "./ParsedMessage.vue";
import MessageList from "./MessageList.vue";
2018-07-08 13:42:54 +00:00
import ChatInput from "./ChatInput.vue";
import ChatUserList from "./ChatUserList.vue";
import SidebarToggle from "./SidebarToggle.vue";
2019-12-31 16:21:34 +00:00
import MessageSearchForm from "./MessageSearchForm.vue";
2018-07-10 09:16:24 +00:00
import ListBans from "./Special/ListBans.vue";
2019-04-14 11:44:44 +00:00
import ListInvites from "./Special/ListInvites.vue";
2018-07-10 09:37:48 +00:00
import ListChannels from "./Special/ListChannels.vue";
2018-07-11 07:54:32 +00:00
import ListIgnored from "./Special/ListIgnored.vue";
export default {
name: "Chat",
components: {
2018-07-12 08:41:40 +00:00
ParsedMessage,
MessageList,
2018-07-08 13:42:54 +00:00
ChatInput,
ChatUserList,
SidebarToggle,
2019-12-31 16:21:34 +00:00
MessageSearchForm,
},
props: {
network: Object,
channel: Object,
focused: String,
},
2018-07-10 09:16:24 +00:00
computed: {
specialComponent() {
2018-07-10 09:37:48 +00:00
switch (this.channel.special) {
2019-07-17 09:33:59 +00:00
case "list_bans":
return ListBans;
case "list_invites":
return ListInvites;
case "list_channels":
return ListChannels;
case "list_ignored":
return ListIgnored;
2018-07-10 09:16:24 +00:00
}
2018-12-17 10:29:49 +00:00
return undefined;
2018-07-10 09:16:24 +00:00
},
},
2019-10-17 16:56:44 +00:00
watch: {
2019-11-11 19:18:55 +00:00
channel() {
this.channelChanged();
2019-10-17 16:56:44 +00:00
},
2019-12-19 13:06:33 +00:00
"channel.editTopic"(newValue) {
if (newValue) {
this.$nextTick(() => {
this.$refs.topicInput.focus();
});
}
},
2019-10-17 16:56:44 +00:00
},
mounted() {
this.channelChanged();
2019-12-19 13:06:33 +00:00
if (this.channel.editTopic) {
this.$nextTick(() => {
this.$refs.topicInput.focus();
});
}
2019-10-17 16:56:44 +00:00
},
methods: {
2019-11-11 19:18:55 +00:00
channelChanged() {
2019-10-17 16:56:44 +00:00
// Triggered when active channel is set or changed
this.channel.highlight = 0;
this.channel.unread = 0;
socket.emit("open", this.channel.id);
if (this.channel.usersOutdated) {
this.channel.usersOutdated = false;
socket.emit("names", {
target: this.channel.id,
});
}
},
hideUserVisibleError() {
this.$store.commit("currentUserVisibleError", null);
},
editTopic() {
if (this.channel.type === "channel") {
this.channel.editTopic = true;
}
},
saveTopic() {
this.channel.editTopic = false;
2019-12-19 13:06:33 +00:00
const newTopic = this.$refs.topicInput.value;
if (this.channel.topic !== newTopic) {
const target = this.channel.id;
const text = `/raw TOPIC ${this.channel.name} :${newTopic}`;
socket.emit("input", {target, text});
}
},
2019-11-09 22:21:34 +00:00
openContextMenu(event) {
2020-03-16 17:58:40 +00:00
eventbus.emit("contextmenu:channel", {
2019-11-23 14:26:20 +00:00
event: event,
channel: this.channel,
network: this.network,
});
2019-11-09 22:21:34 +00:00
},
openMentions(event) {
2020-03-16 17:58:40 +00:00
eventbus.emit("mentions:toggle", {
event: event,
});
},
},
};
</script>