Compare commits

..

14 commits

Author SHA1 Message Date
b0d96faa6f
feat: add ability to open member context menu by right-clicking on avatar
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-11 00:10:26 +02:00
f1eda2da75
feat: handle setting of default context menu state variable only in app.vue
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-11 00:04:18 +02:00
ce57b8e7db
feat: remove global context menu event listener and handler to allow regular context menu where a custom one isn't needed 2025-08-11 00:03:47 +02:00
0540f22f5d
feat: move context menu to the left of the cursor if any part of it is beyond the right side of the viewport
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
2025-08-07 09:01:18 +02:00
51f8c28c54
feat: initialize meMember useState variable on channel load 2025-08-07 09:00:02 +02:00
86af8145b4
feat: make it so opening context menu on an element isn't overridden by another context menu listener on an ancestor of that element 2025-08-07 08:59:20 +02:00
fdfffd78e7
feat: add function to fetch logged-in user's member object for a guild in API composable 2025-08-07 08:58:17 +02:00
0dc485ca77
feat: add functions to kick and ban a member in API composable 2025-08-07 08:57:54 +02:00
e5bdf63f2a
feat: remove context menu on global mousedown only if the context menu useState variable's show value is set to true 2025-08-07 08:57:02 +02:00
46a135de22
feat: add context menu for usernames in members list sidebar 2025-08-07 08:56:07 +02:00
25c5a0e4a8
feat: add context menu for usernames in chat 2025-08-07 08:55:33 +02:00
0d0dccaf84
style(ui): set cursor for usernames in members list sidebar to pointer 2025-08-07 08:54:31 +02:00
dc4494a1db
style(ui): set cursor for usernames in chat to pointer 2025-08-07 08:54:00 +02:00
1bc7877a8b
feat: add util to create context menu items for when right-clicking members in chat or in sidebar 2025-08-07 08:53:11 +02:00
11 changed files with 121 additions and 47 deletions

22
app.vue
View file

@ -12,22 +12,20 @@ import type { ContextMenuInterface } from './types/interfaces';
const banner = useState("banner", () => false);
const contextMenu = useState<ContextMenuInterface>("contextMenu");
const contextMenu = useState<ContextMenuInterface>("contextMenu", () => ({ show: false, pointerX: 0, pointerY: 0, items: [] }));
onMounted(() => {
loadPreferredThemes()
document.removeEventListener("contextmenu", contextMenuHandler);
document.addEventListener("contextmenu", (e) => {
if (e.target instanceof Element && e.target.classList.contains("default-contextmenu")) return;
contextMenuHandler(e);
});
document.addEventListener("mousedown", (e) => {
if (e.target instanceof HTMLElement && e.target.closest("#context-menu")) return;
if (e.target instanceof HTMLElement && e.target.classList.contains("context-menu-item")) return;
console.log("click");
console.log("target:", e.target);
console.log(e.target instanceof HTMLDivElement);
removeContextMenu(contextMenu);
if (contextMenu.value.show) {
console.log("context menu is shown, hiding");
removeContextMenu(contextMenu);
}
if (e.target instanceof HTMLElement && e.target.classList.contains("message-text") && e.target.contentEditable) {
e.target.contentEditable = "false";
}
@ -52,14 +50,6 @@ onMounted(() => {
});
});
function contextMenuHandler(e: MouseEvent) {
e.preventDefault();
//console.log("Opened context menu");
//createContextMenu(e, [
// { name: "Wah", callback: () => { return } }
//]);
}
</script>
<style>

View file

@ -1,5 +1,5 @@
<template>
<div class="member-item" @click.prevent="showModalPopup" tabindex="0">
<div class="member-item" @click.prevent="showModalPopup" tabindex="0" @contextmenu="showContextMenu($event, contextMenu, menuItems)">
<Avatar :profile="props.member" class="member-avatar"/>
<span class="member-display-name" :style="`color: ${generateIrcColor(props.member.user.uuid)}`">
{{ getDisplayName(props.member) }}
@ -11,14 +11,18 @@
<script lang="ts" setup>
import { ModalProfilePopup } from '#components';
import type { GuildMemberResponse } from '~/types/interfaces';
import type { ContextMenuInterface, GuildMemberResponse } from '~/types/interfaces';
const { getDisplayName } = useProfile()
const contextMenu = useState<ContextMenuInterface>("contextMenu");
const props = defineProps<{
member: GuildMemberResponse
}>();
const menuItems = await createMemberContextMenuItems(props.member, props.member.guild_uuid);
const modalPopupVisible = ref<boolean>(false);
function showModalPopup() {
@ -31,6 +35,7 @@ function hideModalPopup() {
</script>
<style>
.member-item {
position: relative;
}
@ -41,4 +46,9 @@ function hideModalPopup() {
min-width: 2.3em;
max-width: 2.3em;
}
.member-display-name {
cursor: pointer;
}
</style>

View file

@ -1,5 +1,5 @@
<template>
<div v-if="props.type == 'normal' || props.replyMessage" ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" :id="props.last ? 'last-message' : undefined"
<div v-if="props.type == 'normal' || props.replyMessage" ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, messageMenuItems)" :id="props.last ? 'last-message' : undefined"
class="message normal-message" :class="{ 'mentioned': (props.replyMessage || props.isMentioned) && props.message.member.user.uuid != props.me.uuid && props.replyMessage?.member.user.uuid == props.me.uuid }" :data-message-id="props.messageId"
:editing.sync="props.editing" :replying-to.sync="props.replyingTo">
<div v-if="props.replyMessage" class="message-reply-svg">
@ -29,11 +29,11 @@
:text="props.replyMessage?.message"
:reply-id="props.replyMessage.uuid" max-width="reply" />
<div class="left-column">
<Avatar :profile="props.author" class="message-author-avatar"/>
<Avatar :profile="props.author" class="message-author-avatar" @contextmenu="showContextMenu($event, contextMenu, memberMenuItems)" />
</div>
<div class="message-data">
<div class="message-metadata">
<span class="message-author-username" tabindex="0" :style="`color: ${props.authorColor}`">
<span class="message-author-username" tabindex="0" :style="`color: ${props.authorColor}`" @contextmenu="showContextMenu($event, contextMenu, memberMenuItems)">
{{ getDisplayName(props.author) }}
</span>
<span class="message-date" :title="date.toString()">
@ -47,7 +47,7 @@
</div>
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks" />
</div>
<div v-else ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" :id="props.last ? 'last-message' : undefined"
<div v-else ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, messageMenuItems)" :id="props.last ? 'last-message' : undefined"
class="message grouped-message" :class="{ 'message-margin-bottom': props.marginBottom, 'mentioned': props.replyMessage || props.isMentioned }"
:data-message-id="props.messageId" :editing.sync="props.editing" :replying-to.sync="props.replyingTo">
<div class="left-column">
@ -72,9 +72,11 @@ import type { ContextMenuInterface, ContextMenuItem } from '~/types/interfaces';
const { getDisplayName } = useProfile()
const route = useRoute();
const props = defineProps<MessageProps>();
const contextMenu = useState<ContextMenuInterface>("contextMenu", () => ({ show: false, pointerX: 0, pointerY: 0, items: [] }));
const contextMenu = useState<ContextMenuInterface>("contextMenu");
const messageElement = ref<HTMLDivElement>();
@ -144,21 +146,23 @@ console.log("media links:", mediaLinks);
// showHover.value = !showHover.value;
//}
const menuItems: ContextMenuItem[] = [
const messageMenuItems: ContextMenuItem[] = [
{ name: "Reply", icon: "lucide:reply", type: "normal", callback: () => { if (messageElement.value) replyToMessage(messageElement.value, props) } }
]
console.log("me:", props.me);
if (props.author?.user.uuid == props.me.uuid) {
if (props.author.user.uuid == props.me.uuid) {
// Inserts "edit" option at index 1 (below the "reply" option)
menuItems.splice(1, 0, { name: "Edit (WIP)", icon: "lucide:square-pen", type: "normal", callback: () => { /* if (messageElement.value) editMessage(messageElement.value, props) */ } });
messageMenuItems.splice(Math.min(1, messageMenuItems.length), 0, { name: "Edit (WIP)", icon: "lucide:square-pen", type: "normal", callback: () => { /* if (messageElement.value) editMessage(messageElement.value, props) */ } });
}
if (props.author?.user.uuid == props.me.uuid /* || check message delete permission*/) {
if (props.author.user.uuid == props.me.uuid /* || check message delete permission*/) {
// Inserts "edit" option at index 2 (below the "edit" option)
menuItems.splice(2, 0, { name: "Delete (WIP)", icon: "lucide:trash", type: "danger", callback: () => {} });
messageMenuItems.splice(Math.min(2, messageMenuItems.length), 0, { name: "Delete (WIP)", icon: "lucide:trash", type: "danger", callback: () => {} });
}
const memberMenuItems = await createMemberContextMenuItems(props.author, route.params.serverId as string);
function getDayDifference(date1: Date, date2: Date) {
const midnight1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
const midnight2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
@ -232,6 +236,11 @@ function getDayDifference(date1: Date, date2: Date) {
max-height: 2em;
min-width: 2em;
max-width: 2em;
cursor: pointer;
}
.message-author-username {
cursor: pointer;
}
.left-column {

View file

@ -40,8 +40,7 @@ function copyInvite(type: "link" | "code") {
if (!invite.value) return;
if (type == "link") {
const runtimeConfig = useRuntimeConfig();
const inviteUrl = URL.parse(`invite/${invite.value}`, `${window.location.protocol}//${window.location.host}${runtimeConfig.app.baseURL}`);
const inviteUrl = URL.parse(`invite/${invite.value}`, `${window.location.protocol}//${window.location.host}`);
if (inviteUrl) {
navigator.clipboard.writeText(inviteUrl.href);
}

View file

@ -34,8 +34,7 @@
<span class="theme-title" :style="{color:`${layout.complementaryColor}`}">
{{ layout.displayName }}
</span>
<!-- this breaks if it's a nuxtimg, i don't know why -->
<img class="layout-preview" :src="layout.previewImageUrl"></img>
<NuxtImg class="layout-preview" :src="layout.previewImageUrl"></NuxtImg>
</div>
</div>
</div>
@ -61,8 +60,8 @@ import { settingSave, settingsLoad } from '#imports';
const runtimeConfig = useRuntimeConfig()
const baseURL = runtimeConfig.app.baseURL;
const styleFolder = `${baseURL}/themes/style`
const layoutFolder = `${baseURL}/themes/layout`
const styleFolder = `${baseURL}themes/style`
const layoutFolder = `${baseURL}themes/layout`
const timeFormatTextStrings = ["Auto", "12-Hour", "24-Hour"]
@ -116,7 +115,6 @@ async function parseTheme(url: string): Promise<Theme | void> {
break
case "previewImageUrl":
previewImageUrl = `${layoutFolder}/${lineArray[1].trim()}`
console.log(previewImageUrl)
break
}
}

View file

@ -18,6 +18,10 @@ onMounted(() => {
if (contextMenu) {
contextMenu.style.left = props.pointerX.toString() + "px";
contextMenu.style.top = props.pointerY.toString() + "px";
const rect = contextMenu.getBoundingClientRect();
if (rect.right > (window.innerWidth || document.documentElement.clientWidth)) {
contextMenu.style.left = (props.pointerX - contextMenu.clientWidth).toString() + "px";
}
}
});

View file

@ -1,5 +1,5 @@
<template>
<div ref="resizableSidebar" class="resizable-sidebar"
<div ref="resizableSidebar" class="resizable-sidebar" @contextmenu="showContextMenu($event, contextMenu, menuItems)"
:style="{
'width': storedWidth ? storedWidth : props.width,
'min-width': props.minWidth,
@ -49,10 +49,6 @@ onMounted(() => {
if (resizableSidebar.value && widthResizer.value) {
widthResizer.value.addEventListener("pointerdown", (e) => {
e.preventDefault();
if (e.button == 2) {
showContextMenu(e, contextMenu.value, menuItems);
return
};
document.body.style.cursor = "ew-resize";
function handleMove(pointer: PointerEvent) {
if (resizableSidebar.value) {

View file

@ -25,6 +25,17 @@ export const useApi = () => {
return await fetchWithApi("/me")
}
async function fetchMeMember(guildId: string): Promise<GuildMemberResponse | undefined> {
const { getUser } = useAuth();
const me = await getUser();
if (me) {
const members = await fetchMembers(guildId);
const meMember = members.objects.find(member => member.user.uuid == me.uuid);
return meMember;
}
}
async function fetchChannels(guildId: string): Promise<ChannelResponse[]> {
return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`));
}
@ -47,6 +58,14 @@ export const useApi = () => {
async function fetchMember(guildId: string, memberId: string): Promise<GuildMemberResponse | undefined> {
return await fetchWithApi(`/guilds/${guildId}/members/${memberId}`);
}
async function kickMember(memberId: string) {
return await fetchWithApi(`/members/${memberId}`, { method: "DELETE" });
}
async function banMember(guildId: string, memberId: string) {
//
}
async function fetchUsers() {
return await fetchWithApi(`/users`);
@ -114,10 +133,13 @@ export const useApi = () => {
fetchGuild,
fetchMyGuilds,
fetchMe,
fetchMeMember,
fetchChannels,
fetchChannel,
fetchMembers,
fetchMember,
kickMember,
banMember,
fetchUsers,
fetchUser,
fetchFriends,

View file

@ -56,7 +56,7 @@ const showGuildSettings = ref(false);
//const servers = await fetchWithApi("/servers") as { uuid: string, name: string, description: string }[];
//console.log("channelid: servers:", servers);
const { fetchMembers } = useApi();
const { fetchMembers, fetchMeMember } = useApi();
onMounted(async () => {
console.log("mounting");
@ -84,6 +84,14 @@ async function setArrayVariables() {
console.log("channels:", channels.value);
channel.value = await fetchWithApi(`/channels/${route.params.channelId}`);
console.log("channel:", channel.value);
const meMember = useState<GuildMemberResponse | undefined>("meMember");
console.log("[CHANNEL] meMember:", meMember.value);
if (!meMember.value) {
console.log("[CHANNEL] meMember is uninitialized, initializing");
const fetchedMeMember = await fetchMeMember(route.params.serverId as string);
meMember.value = fetchedMeMember;
console.log("[CHANNEL] meMember set to:", fetchedMeMember);
}
}
function toggleGuildSettings(e: Event) {

View file

@ -0,0 +1,33 @@
import { Permission } from "~/types/enums";
import type { ContextMenuItem, GuildMemberResponse } from "~/types/interfaces";
export default async (member: GuildMemberResponse, guildId: string) => {
const menuItems: ContextMenuItem[] = [];
const { fetchMeMember } = useApi();
const me = useState<GuildMemberResponse | undefined>("me");
if (!me.value) {
const fetchedMe = await fetchMeMember(member.guild_uuid);
me.value = fetchedMe;
}
const { banMember, kickMember } = useApi();
console.log("[MENUITEM] hi");
console.log("[MENUITEM] member:", member.user.username);
console.log("[MENUITEM] me:", me.value?.user.username);
if (me.value && member.uuid != me.value.uuid) {
console.log("[MENUITEM] member is not me");
if (hasPermission(me.value, Permission.KickMember)) {
console.log("[MENUITEM] has kick member permission");
menuItems.splice(Math.min(3, menuItems.length), 0, { name: "Kick", icon: "lucide:user-x", type: "danger", callback: async () => await kickMember(member.uuid) });
}
if (hasPermission(me.value, Permission.BanMember)) {
console.log("[MENUITEM] has ban permission");
menuItems.splice(Math.min(4, menuItems.length), 0, { name: "Ban (WIP)", icon: "lucide:ban", type: "danger", callback: async () => await banMember(guildId, member.uuid) });
}
}
console.log("[MENUITEM] returning menu items:", menuItems);
return menuItems;
}

View file

@ -3,10 +3,15 @@ import ContextMenu from "~/components/UserInterface/ContextMenu.vue";
import type { ContextMenuInterface, ContextMenuItem } from "~/types/interfaces";
export default (e: MouseEvent | PointerEvent, contextMenu: ContextMenuInterface, menuItems: ContextMenuItem[]) => {
console.log("Showing context menu");
contextMenu.show = true;
contextMenu.pointerX = e.clientX;
contextMenu.pointerY = e.clientY;
contextMenu.items = menuItems;
console.log("Showed");
e.preventDefault();
e.stopPropagation();
console.log("Menu items:", menuItems);
if (menuItems.length) {
console.log("Showing context menu");
contextMenu.show = true;
contextMenu.pointerX = e.clientX;
contextMenu.pointerY = e.clientY;
contextMenu.items = menuItems;
console.log("Showed");
}
}