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