2018-07-08 10:50:11 +00:00
|
|
|
<template>
|
|
|
|
<span
|
2022-11-27 14:59:46 +00:00
|
|
|
:class="['user', {[nickColor]: store.state.settings.coloredNicks}, {active: active}]"
|
2018-07-08 10:50:11 +00:00
|
|
|
:data-name="user.nick"
|
2018-07-11 07:33:11 +00:00
|
|
|
role="button"
|
2020-01-27 09:44:36 +00:00
|
|
|
v-on="onHover ? {mouseenter: hover} : {}"
|
2019-11-23 14:26:20 +00:00
|
|
|
@click.prevent="openContextMenu"
|
|
|
|
@contextmenu.prevent="openContextMenu"
|
2020-09-01 08:39:36 +00:00
|
|
|
><slot>{{ mode }}{{ user.nick }}</slot></span
|
2019-07-17 09:33:59 +00:00
|
|
|
>
|
2018-07-08 10:50:11 +00:00
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import {computed, defineComponent, PropType} from "vue";
|
2024-03-01 08:06:58 +00:00
|
|
|
import {UserInMessage} from "../../shared/types/msg";
|
2020-03-16 17:58:40 +00:00
|
|
|
import eventbus from "../js/eventbus";
|
2019-11-16 17:24:03 +00:00
|
|
|
import colorClass from "../js/helpers/colorClass";
|
2024-03-01 08:06:58 +00:00
|
|
|
import type {ClientChan, ClientNetwork} from "../js/types";
|
2022-11-27 14:59:46 +00:00
|
|
|
import {useStore} from "../js/store";
|
2019-11-05 10:36:44 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
type UsernameUser = Partial<UserInMessage> & {
|
|
|
|
mode?: string;
|
|
|
|
nick: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default defineComponent({
|
2018-07-08 10:50:11 +00:00
|
|
|
name: "Username",
|
|
|
|
props: {
|
2022-06-19 00:25:21 +00:00
|
|
|
user: {
|
|
|
|
// TODO: UserInMessage shouldn't be necessary here.
|
|
|
|
type: Object as PropType<UsernameUser | UserInMessage>,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-07-10 20:29:53 +00:00
|
|
|
active: Boolean,
|
2022-06-19 00:25:21 +00:00
|
|
|
onHover: {
|
|
|
|
type: Function as PropType<(user: UserInMessage) => void>,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
channel: {type: Object as PropType<ClientChan>, required: false},
|
|
|
|
network: {type: Object as PropType<ClientNetwork>, required: false},
|
2018-07-10 23:25:21 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup(props) {
|
|
|
|
const mode = computed(() => {
|
2020-09-01 08:39:36 +00:00
|
|
|
// Message objects have a singular mode, but user objects have modes array
|
2022-06-19 00:25:21 +00:00
|
|
|
if (props.user.modes) {
|
|
|
|
return props.user.modes[0];
|
2020-09-01 08:39:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
return props.user.mode;
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: Nick must be ! because our user prop union includes UserInMessage
|
|
|
|
const nickColor = computed(() => colorClass(props.user.nick!));
|
|
|
|
|
|
|
|
const hover = () => {
|
|
|
|
if (props.onHover) {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
|
|
return props.onHover(props.user as UserInMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const openContextMenu = (event: Event) => {
|
2020-03-16 17:58:40 +00:00
|
|
|
eventbus.emit("contextmenu:user", {
|
2019-11-23 14:26:20 +00:00
|
|
|
event: event,
|
2022-06-19 00:25:21 +00:00
|
|
|
user: props.user,
|
|
|
|
network: props.network,
|
|
|
|
channel: props.channel,
|
2019-11-23 14:26:20 +00:00
|
|
|
});
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
2022-11-27 14:59:46 +00:00
|
|
|
const store = useStore();
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
return {
|
|
|
|
mode,
|
|
|
|
nickColor,
|
|
|
|
hover,
|
|
|
|
openContextMenu,
|
2022-11-27 14:59:46 +00:00
|
|
|
store,
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
2018-07-08 10:50:11 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2018-07-08 10:50:11 +00:00
|
|
|
</script>
|