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