2018-07-12 19:24:35 +00:00
|
|
|
<template>
|
2019-04-13 20:44:04 +00:00
|
|
|
<!-- TODO: move closed style to it's own class -->
|
2018-07-12 19:24:35 +00:00
|
|
|
<div
|
2019-11-20 20:54:00 +00:00
|
|
|
v-if="isChannelVisible"
|
2019-08-03 19:03:45 +00:00
|
|
|
ref="element"
|
2019-02-07 07:24:53 +00:00
|
|
|
:class="[
|
2019-12-04 06:58:23 +00:00
|
|
|
'channel-list-item',
|
2019-11-26 20:50:40 +00:00
|
|
|
{active: active},
|
2019-07-17 09:33:59 +00:00
|
|
|
{'parted-channel': channel.type === 'channel' && channel.state === 0},
|
2019-11-26 22:27:11 +00:00
|
|
|
{'has-draft': channel.pendingMessage},
|
2021-05-06 01:51:35 +00:00
|
|
|
{'has-unread': channel.unread},
|
|
|
|
{'has-highlight': channel.highlight},
|
2019-12-19 13:22:04 +00:00
|
|
|
{
|
|
|
|
'not-secure':
|
|
|
|
channel.type === 'lobby' && network.status.connected && !network.status.secure,
|
|
|
|
},
|
|
|
|
{'not-connected': channel.type === 'lobby' && !network.status.connected},
|
2022-02-11 01:56:17 +00:00
|
|
|
{'is-muted': channel.muted},
|
2019-02-07 07:24:53 +00:00
|
|
|
]"
|
2018-10-05 09:14:30 +00:00
|
|
|
:aria-label="getAriaLabel()"
|
|
|
|
:title="getAriaLabel()"
|
2019-01-02 12:09:50 +00:00
|
|
|
:data-name="channel.name"
|
2019-12-04 06:58:23 +00:00
|
|
|
:data-type="channel.type"
|
2018-07-12 19:24:35 +00:00
|
|
|
:aria-controls="'#chan-' + channel.id"
|
2019-11-26 20:50:40 +00:00
|
|
|
:aria-selected="active"
|
2022-06-19 00:25:21 +00:00
|
|
|
:style="channel.closed ? {transition: 'none', opacity: 0.4} : undefined"
|
2019-02-25 05:38:13 +00:00
|
|
|
role="tab"
|
2019-10-17 16:56:44 +00:00
|
|
|
@click="click"
|
2019-11-09 22:21:34 +00:00
|
|
|
@contextmenu.prevent="openContextMenu"
|
2019-02-25 05:38:13 +00:00
|
|
|
>
|
2022-06-19 00:25:21 +00:00
|
|
|
<slot :network="network" :channel="channel" :active-channel="activeChannel" />
|
2018-07-12 19:24:35 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
2020-03-16 17:58:40 +00:00
|
|
|
import eventbus from "../js/eventbus";
|
2019-11-20 20:54:00 +00:00
|
|
|
import isChannelCollapsed from "../js/helpers/isChannelCollapsed";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {ClientNetwork, ClientChan} from "../js/types";
|
|
|
|
import {computed, defineComponent, PropType} from "vue";
|
|
|
|
import {useStore} from "../js/store";
|
|
|
|
import {switchToChannel} from "../js/router";
|
2019-03-03 19:43:57 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2018-07-12 19:24:35 +00:00
|
|
|
name: "ChannelWrapper",
|
|
|
|
props: {
|
2022-06-19 00:25:21 +00:00
|
|
|
network: {
|
|
|
|
type: Object as PropType<ClientNetwork>,
|
|
|
|
required: true,
|
2019-11-02 19:40:59 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
channel: {
|
|
|
|
type: Object as PropType<ClientChan>,
|
|
|
|
required: true,
|
2019-11-20 20:54:00 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
active: Boolean,
|
|
|
|
isFiltering: Boolean,
|
2019-11-02 19:40:59 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup(props) {
|
|
|
|
const store = useStore();
|
|
|
|
const activeChannel = computed(() => store.state.activeChannel);
|
|
|
|
const isChannelVisible = computed(
|
|
|
|
() => props.isFiltering || !isChannelCollapsed(props.network, props.channel)
|
|
|
|
);
|
|
|
|
|
|
|
|
const getAriaLabel = () => {
|
|
|
|
const extra: string[] = [];
|
|
|
|
const type = props.channel.type;
|
2018-10-05 09:14:30 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (props.channel.unread > 0) {
|
|
|
|
if (props.channel.unread > 1) {
|
|
|
|
extra.push(`${props.channel.unread} unread messages`);
|
2021-04-21 01:04:31 +00:00
|
|
|
} else {
|
2022-06-19 00:25:21 +00:00
|
|
|
extra.push(`${props.channel.unread} unread message`);
|
2021-04-21 01:04:31 +00:00
|
|
|
}
|
2018-10-05 09:14:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (props.channel.highlight > 0) {
|
|
|
|
if (props.channel.highlight > 1) {
|
|
|
|
extra.push(`${props.channel.highlight} mentions`);
|
2021-04-21 01:04:31 +00:00
|
|
|
} else {
|
2022-06-19 00:25:21 +00:00
|
|
|
extra.push(`${props.channel.highlight} mention`);
|
2021-04-21 01:04:31 +00:00
|
|
|
}
|
2018-10-05 09:14:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
return `${type}: ${props.channel.name} ${extra.length ? `(${extra.join(", ")})` : ""}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
const click = () => {
|
|
|
|
if (props.isFiltering) {
|
2020-02-10 15:43:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
switchToChannel(props.channel);
|
|
|
|
};
|
|
|
|
|
|
|
|
const openContextMenu = (event: MouseEvent) => {
|
2020-03-16 17:58:40 +00:00
|
|
|
eventbus.emit("contextmenu:channel", {
|
2019-11-23 14:26:20 +00:00
|
|
|
event: event,
|
2022-06-19 00:25:21 +00:00
|
|
|
channel: props.channel,
|
|
|
|
network: props.network,
|
2019-11-23 14:26:20 +00:00
|
|
|
});
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
activeChannel,
|
|
|
|
isChannelVisible,
|
|
|
|
getAriaLabel,
|
|
|
|
click,
|
|
|
|
openContextMenu,
|
|
|
|
};
|
2018-10-05 09:14:30 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2018-07-12 19:24:35 +00:00
|
|
|
</script>
|