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
20 changed files with 232 additions and 153 deletions

22
app.vue
View file

@ -12,22 +12,20 @@ import type { ContextMenuInterface } from './types/interfaces';
const banner = useState("banner", () => false); const banner = useState("banner", () => false);
const contextMenu = useState<ContextMenuInterface>("contextMenu"); const contextMenu = useState<ContextMenuInterface>("contextMenu", () => ({ show: false, pointerX: 0, pointerY: 0, items: [] }));
onMounted(() => { onMounted(() => {
loadPreferredThemes() 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) => { 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("click");
console.log("target:", e.target); console.log("target:", e.target);
console.log(e.target instanceof HTMLDivElement); 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) { if (e.target instanceof HTMLElement && e.target.classList.contains("message-text") && e.target.contentEditable) {
e.target.contentEditable = "false"; 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> </script>
<style> <style>

View file

@ -12,4 +12,8 @@ export default class Message {
this.userUuid = user_uuid; this.userUuid = user_uuid;
this.message = message; this.message = message;
} }
getTimestamp() {
return uuidToTimestamp(this.uuid);
}
} }

View file

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

View file

@ -1,22 +1,24 @@
<template> <template>
<div v-if="props.type == 'normal' || props.replyMessage" ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" <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="{ 'highlighted': (props.isMentioned || (props.replyMessage && props.message.member.user.uuid != me!.uuid && props.replyMessage?.member.user.uuid == me!.uuid)) }" 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"
:data-message-id="props.message.uuid" :editing.sync="props.editing"> :editing.sync="props.editing" :replying-to.sync="props.replyingTo">
<div v-if="props.replyMessage" class="message-reply-svg"> <div v-if="props.replyMessage" class="message-reply-svg">
<svg <svg
width="1.5em" height="1.5em" width="1.5em" height="1.5em"
viewBox="0 0 150 87.5" version="1.1" id="svg1" viewBox="0 0 150 87.5" version="1.1" id="svg1"
style="overflow: visible;"> style="overflow: visible;">
<defs id="defs1" /> <defs id="defs1" />
<g id="layer1" transform="translate(40,-35)"> <g id="layer1"
<g id="g3" transform="translate(-35,-20)"> transform="translate(40,-35)">
<g id="g3"
transform="translate(-35,-20)">
<path <path
style="stroke:var(--reply-text-color);stroke-width:8;stroke-opacity:1" style="stroke:var(--reply-text-color);stroke-width:8;stroke-opacity:1"
d="m 120,87.5 100,2.5e-5" d="m 120.02168,87.850978 100.76157,2.4e-5"
id="path3-5" /> id="path3-5" />
<path <path
style="stroke:var(--reply-text-color);stroke-width:8;stroke-opacity:1" style="stroke:var(--reply-text-color);stroke-width:8;stroke-opacity:1"
d="M 70,150 120,87.5" d="M 69.899501,174.963 120.2803,87.700931"
id="path3-5-2" /> id="path3-5-2" />
</g> </g>
</g> </g>
@ -27,36 +29,36 @@
:text="props.replyMessage?.message" :text="props.replyMessage?.message"
:reply-id="props.replyMessage.uuid" max-width="reply" /> :reply-id="props.replyMessage.uuid" max-width="reply" />
<div class="left-column"> <div class="left-column">
<Avatar :profile="props.message.member" class="message-author-avatar"/> <Avatar :profile="props.author" class="message-author-avatar" @contextmenu="showContextMenu($event, contextMenu, memberMenuItems)" />
</div> </div>
<div class="message-data"> <div class="message-data">
<div class="message-metadata"> <div class="message-metadata">
<span class="message-author-username" tabindex="0" :style="`color: ${generateIrcColor(props.message.member.user.uuid)}`"> <span class="message-author-username" tabindex="0" :style="`color: ${props.authorColor}`" @contextmenu="showContextMenu($event, contextMenu, memberMenuItems)">
{{ getDisplayName(props.message.member) }} {{ getDisplayName(props.author) }}
</span> </span>
<span class="message-date" :title="date.toString()"> <span class="message-date" :title="date.toString()">
<span v-if="getDayDifference(date, currentDate) === 1">Yesterday at</span> <span v-if="getDayDifference(date, currentDate) === 1">Yesterday at</span>
<span v-else-if="getDayDifference(date, currentDate) > 1 ">{{ date.toLocaleDateString(undefined) }},</span> <span v-else-if="getDayDifference(date, currentDate) > 1 ">{{ date.toLocaleDateString(undefined) }},</span>
{{ date.toLocaleTimeString(undefined, { hour12: getPreferredTimeFormat() == "12", timeStyle: "short" }) }} {{ date.toLocaleTimeString(undefined, { hour12: props.format == "12", timeStyle: "short" }) }}
</span> </span>
</div> </div>
<div class="message-text" v-html="sanitized" :hidden="hideText" tabindex="0"></div> <div class="message-text" v-html="sanitized" :hidden="hasEmbed" tabindex="0"></div>
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks" />
</div> </div>
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks" />
</div> </div>
<div v-else ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" <div v-else ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, messageMenuItems)" :id="props.last ? 'last-message' : undefined"
class="message grouped-message" :class="{ 'mentioned': props.replyMessage || props.isMentioned }" class="message grouped-message" :class="{ 'message-margin-bottom': props.marginBottom, 'mentioned': props.replyMessage || props.isMentioned }"
:data-message-id="props.message.uuid" :editing.sync="props.editing"> :data-message-id="props.messageId" :editing.sync="props.editing" :replying-to.sync="props.replyingTo">
<div class="left-column"> <div class="left-column">
<span :class="{ 'invisible': dateHidden }" class="message-date side-message-date" :title="date.toString()"> <span :class="{ 'invisible': dateHidden }" class="message-date side-message-date" :title="date.toString()">
{{ date.toLocaleTimeString(undefined, { hour12: getPreferredTimeFormat() == "12", timeStyle: "short" }) }} {{ date.toLocaleTimeString(undefined, { hour12: props.format == "12", timeStyle: "short" }) }}
</span> </span>
</div> </div>
<div class="message-data"> <div class="message-data">
<div class="message-text" :class="$style['message-text']" v-html="sanitized" :hidden="hideText" tabindex="0"></div> <div class="message-text" :class="$style['message-text']" v-html="sanitized" :hidden="hasEmbed" tabindex="0"></div>
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks"/>
</div> </div>
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks" />
</div> </div>
</template> </template>
@ -69,37 +71,35 @@ import MessageReply from './UserInterface/MessageReply.vue';
import type { ContextMenuInterface, ContextMenuItem } from '~/types/interfaces'; import type { ContextMenuInterface, ContextMenuItem } from '~/types/interfaces';
const { getDisplayName } = useProfile() const { getDisplayName } = useProfile()
const { getUser } = useAuth()
const route = useRoute();
const props = defineProps<MessageProps>(); const props = defineProps<MessageProps>();
const me = await getUser() const contextMenu = useState<ContextMenuInterface>("contextMenu");
const contextMenu = useState<ContextMenuInterface>("contextMenu", () => ({ show: false, pointerX: 0, pointerY: 0, items: [] }));
const messageElement = ref<HTMLDivElement>(); const messageElement = ref<HTMLDivElement>();
const dateHidden = ref<boolean>(true); const dateHidden = ref<boolean>(true);
const date = uuidToDate(props.message.uuid); const date = new Date(props.timestamp);
const currentDate: Date = new Date() const currentDate: Date = new Date()
console.log("[MSG] message to render:", props.message); console.log("[MSG] message to render:", props.message);
console.log("author:", props.message.member); console.log("author:", props.author);
console.log("[MSG] reply message:", props.replyMessage); console.log("[MSG] reply message:", props.replyMessage);
const linkRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g; const linkRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g;
const linkMatches = props.message.message.matchAll(linkRegex).map(link => link[0]); const linkMatches = props.message.message.matchAll(linkRegex).map(link => link[0]);
const mediaLinks = ref<string[]>([]); const mediaLinks: string[] = [];
console.log("link matches:", linkMatches); console.log("link matches:", linkMatches);
const hideText = ref(false); const hasEmbed = ref(false);
const sanitized = ref<string>(); const sanitized = ref<string>();
onMounted(async () => { onMounted(async () => {
const parsed = await parse(props.message.message, { gfm: true }); const parsed = await parse(props.text, { gfm: true });
sanitized.value = DOMPurify.sanitize(parsed, { sanitized.value = DOMPurify.sanitize(parsed, {
ALLOWED_TAGS: [ ALLOWED_TAGS: [
"strong", "em", "br", "blockquote", "strong", "em", "br", "blockquote",
@ -123,56 +123,46 @@ onMounted(async () => {
console.log("added listeners"); console.log("added listeners");
} }
const links: string[] = [];
for (const link of linkMatches) { for (const link of linkMatches) {
console.log("link:", link); console.log("link:", link);
try { try {
const res = await $fetch.raw(link); const res = await $fetch.raw(link);
if (res.ok && res.headers.get("content-type")?.match(/^image\/(apng|gif|jpeg|png|webp)$/)) { if (res.ok && res.headers.get("content-type")?.match(/^image\/(apng|gif|jpeg|png|webp)$/)) {
console.log("link is image"); console.log("link is image");
links.push(link); mediaLinks.push(link);
}
} catch (error) {
console.error(error);
} }
if (mediaLinks.length) {
mediaLinks.value = [...links]; hasEmbed.value = true
};
} catch (error) {
console.error(error);
} }
}
if (mediaLinks.value.length) { console.log("media links:", mediaLinks);
const nonLinks = props.message.message.split(linkRegex);
let invalidContent = false;
for (const nonLink of nonLinks) {
if (nonLink != "" && nonLink != "\n" && nonLink != "<br>") {
invalidContent = true;
break;
}
}
hideText.value = !invalidContent;
};
console.log("media links:", mediaLinks);
}); });
//function toggleTooltip(e: Event) { //function toggleTooltip(e: Event) {
// showHover.value = !showHover.value; // 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) } } { name: "Reply", icon: "lucide:reply", type: "normal", callback: () => { if (messageElement.value) replyToMessage(messageElement.value, props) } }
] ]
console.log("me:", me); console.log("me:", props.me);
if (props.message.member.user.uuid == me!.uuid) { if (props.author.user.uuid == props.me.uuid) {
// Inserts "edit" option at index 1 (below the "reply" option) // 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.message.member.user.uuid == 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) // 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) { function getDayDifference(date1: Date, date2: Date) {
const midnight1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate()); const midnight1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
const midnight2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate()); const midnight2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
@ -188,20 +178,14 @@ function getDayDifference(date1: Date, date2: Date) {
<style scoped> <style scoped>
.message { .message {
display: grid;
grid-template-columns: 4rem 1fr;
align-items: center;
text-align: left; text-align: left;
/* -4 dvw due to 2dvw of padding on both sides */ /* border: 1px solid lightcoral; */
width: calc(100% - 4dvw); display: grid;
grid-template-columns: 2rem 1fr;
align-items: center;
column-gap: 1dvw;
width: 100%;
overflow-wrap: anywhere; overflow-wrap: anywhere;
padding-top: .2rem;
padding-bottom: .2rem;
padding-left: 2dvw;
padding-right: 1dvw;
border-radius: 0 var(--minor-radius) var(--minor-radius) 0;
} }
.message-reply-preview { .message-reply-preview {
@ -217,6 +201,14 @@ function getDayDifference(date1: Date, date2: Date) {
margin-top: 1dvh; margin-top: 1dvh;
} }
.grouped-message {
margin-top: .3em;
}
#last-message {
margin-bottom: 2dvh;
}
.message-metadata { .message-metadata {
display: flex; display: flex;
gap: .5dvw; gap: .5dvw;
@ -225,9 +217,10 @@ function getDayDifference(date1: Date, date2: Date) {
.message-data { .message-data {
/* border: 1px solid white; */ /* border: 1px solid white; */
margin-left: .5dvw;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%; height: fit-content;
width: 100%; width: 100%;
grid-row: 2; grid-row: 2;
grid-column: 2; grid-column: 2;
@ -239,10 +232,15 @@ function getDayDifference(date1: Date, date2: Date) {
} }
.message-author-avatar { .message-author-avatar {
min-height: 2.5em; min-height: 2em;
max-height: 2.5em; max-height: 2em;
min-width: 2.5em; min-width: 2em;
max-width: 2.5em; max-width: 2em;
cursor: pointer;
}
.message-author-username {
cursor: pointer;
} }
.left-column { .left-column {
@ -253,11 +251,8 @@ function getDayDifference(date1: Date, date2: Date) {
white-space: nowrap; white-space: nowrap;
grid-row: 2; grid-row: 2;
grid-column: 1; grid-column: 1;
height: 100%;
align-items: start;
} }
.author-username { .author-username {
margin-right: .5dvw; margin-right: .5dvw;
color: white; color: white;
@ -271,7 +266,9 @@ function getDayDifference(date1: Date, date2: Date) {
.side-message-date { .side-message-date {
font-size: .625em; font-size: .625em;
margin-top: .4em; display: flex;
align-items: center;
align-content: center;
} }
/* /*
@ -281,11 +278,11 @@ function getDayDifference(date1: Date, date2: Date) {
} }
*/ */
.highlighted { .mentioned {
background-color: var(--chat-important-background-color); background-color: var(--chat-important-background-color);
} }
.highlighted:hover { .mentioned:hover {
background-color: var(--chat-important-highlighted-background-color); background-color: var(--chat-important-highlighted-background-color);
} }
@ -310,7 +307,6 @@ function getDayDifference(date1: Date, date2: Date) {
<style> <style>
/* class used in utils/replyToMessage.ts */
.replying-to { .replying-to {
background-color: var(--chat-featured-message-color); background-color: var(--chat-featured-message-color);
} }

View file

@ -1,12 +1,14 @@
<template> <template>
<div id="message-area"> <div id="message-area">
<div id="messages" ref="messagesElement"> <div id="messages" ref="messagesElement">
<Message v-for="(message, i) of messages" :key="message.uuid" <Message v-for="(message, i) of messages" :username="getDisplayName(message.member.user)" :key="message.uuid"
:text="message.message" :timestamp="messageTimestamps[message.uuid]" :img="message.member.user.avatar"
:format="timeFormat" :type="messagesType[message.uuid]"
:margin-bottom="(messages[i + 1] && messagesType[messages[i + 1].uuid] == 'normal') ?? false"
:last="i == messages.length - 1" :message-id="message.uuid" :author="message.member" :me="me"
:message="message" :is-reply="message.reply_to" :message="message" :is-reply="message.reply_to"
:reply-message="message.reply_to ? getReplyMessage(message.reply_to) : undefined" :author-color="`${generateIrcColor(message.member.user.uuid)}`"
:type="messagesType[message.uuid]" :reply-message="message.reply_to ? getReplyMessage(message.reply_to) : undefined" />
:editing="false"
:is-mentioned="false" />
</div> </div>
<div id="message-box" class="rounded-corners"> <div id="message-box" class="rounded-corners">
<form id="message-form" @submit="sendMessage"> <form id="message-form" @submit="sendMessage">
@ -318,6 +320,8 @@ router.beforeEach((to, from, next) => {
#message-area { #message-area {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding-left: 1dvw;
padding-right: 1dvw;
overflow: hidden; overflow: hidden;
flex-grow: 1; flex-grow: 1;
} }
@ -325,8 +329,8 @@ router.beforeEach((to, from, next) => {
#message-box { #message-box {
margin-top: auto; /* force it to the bottom of the screen */ margin-top: auto; /* force it to the bottom of the screen */
margin-bottom: 2dvh; margin-bottom: 2dvh;
margin-left: 2dvw; margin-left: 1dvw;
margin-right: 2dvw; margin-right: 1dvw;
padding-left: 2%; padding-left: 2%;
padding-right: 2%; padding-right: 2%;
@ -378,7 +382,8 @@ router.beforeEach((to, from, next) => {
overflow-y: scroll; overflow-y: scroll;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding-bottom: 1em; padding-left: 1dvw;
padding-right: 1dvw;
} }
.message-box-button { .message-box-button {

View file

@ -1,9 +1,6 @@
<template> <template>
<div class="media-container"> <div class="media-container">
<NuxtImg v-for="link of props.links" <NuxtImg v-for="link of props.links" class="media-item" :src="link" @click.prevent="createModal(link)" />
class="media-item"
:src="link"
@click.prevent="createModal(link)" />
</div> </div>
</template> </template>
@ -11,6 +8,7 @@
import { ModalBase } from '#components'; import { ModalBase } from '#components';
import { render } from 'vue'; import { render } from 'vue';
const props = defineProps<{ links: string[] }>(); const props = defineProps<{ links: string[] }>();
function createModal(link: string) { function createModal(link: string) {
@ -36,14 +34,14 @@ function createModal(link: string) {
<style scoped> <style scoped>
.media-container { .media-container {
display: flex; grid-column: 2;
flex-wrap: wrap; grid-row: 3;
gap: .2rem; margin-left: .5dvw;
max-width: 100%;
} }
.media-item { .media-item {
cursor: pointer; cursor: pointer;
max-width: 15dvw; max-width: 15dvw;
} }
</style> </style>

View file

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

View file

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

View file

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

View file

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

View file

@ -56,7 +56,7 @@ const showGuildSettings = ref(false);
//const servers = await fetchWithApi("/servers") as { uuid: string, name: string, description: string }[]; //const servers = await fetchWithApi("/servers") as { uuid: string, name: string, description: string }[];
//console.log("channelid: servers:", servers); //console.log("channelid: servers:", servers);
const { fetchMembers } = useApi(); const { fetchMembers, fetchMeMember } = useApi();
onMounted(async () => { onMounted(async () => {
console.log("mounting"); console.log("mounting");
@ -84,6 +84,14 @@ async function setArrayVariables() {
console.log("channels:", channels.value); console.log("channels:", channels.value);
channel.value = await fetchWithApi(`/channels/${route.params.channelId}`); channel.value = await fetchWithApi(`/channels/${route.params.channelId}`);
console.log("channel:", channel.value); 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) { function toggleGuildSettings(e: Event) {

View file

@ -9,7 +9,6 @@ complementaryColor = white
--sidebar-icon-gap: .25em; --sidebar-icon-gap: .25em;
--sidebar-margin: .5em; --sidebar-margin: .5em;
--minor-radius: .35em;
--standard-radius: .5em; --standard-radius: .5em;
--button-radius: .6em; --button-radius: .6em;
--guild-icon-radius: 15%; --guild-icon-radius: 15%;

View file

@ -10,15 +10,15 @@ complementaryColor = white
--reply-text-color: #969696; --reply-text-color: #969696;
--danger-text-color: #ff0000; --danger-text-color: #ff0000;
--chat-background-color: #383432; --chat-background-color: #2f2e2d;
--chat-highlighted-background-color: #4c4a48; --chat-highlighted-background-color: #3f3b38;
--chat-important-background-color: #ffcf5f38; --chat-important-background-color: #ffcf5f38;
--chat-important-highlighted-background-color: #ffa86f4f; --chat-important-highlighted-background-color: #ffa86f4f;
--chat-featured-message-color: #4f3f2f60; --chat-featured-message-color: #4f3f2f60;
--popup-background-color: #2f2828; --popup-background-color: #2f2828;
--popup-highlighted-background-color: #382f2f; --popup-highlighted-background-color: #382f2f;
--sidebar-background-color: #322f2d; --sidebar-background-color: #3e3a37;
--sidebar-highlighted-background-color: #46423b; --sidebar-highlighted-background-color: #46423b;
--topbar-background-color: #3a3733; --topbar-background-color: #3a3733;
--chatbox-background-color: #3a3733; --chatbox-background-color: #3a3733;

View file

@ -10,16 +10,16 @@ complementaryColor = white
--reply-text-color: #969696; --reply-text-color: #969696;
--danger-text-color: #ff0000; --danger-text-color: #ff0000;
--chat-background-color: #282624; --chat-background-color: #1f1e1d;
--chat-highlighted-background-color: #383430; --chat-highlighted-background-color: #2f2b28;
--chat-important-background-color: #ffc44f2f; --chat-important-background-color: #ffc44f2f;
--chat-important-highlighted-background-color: #ffa45f4a; --chat-important-highlighted-background-color: #ffa45f4a;
--chat-featured-message-color: #4f2f1f58; --chat-featured-message-color: #4f2f1f58;
--popup-background-color: #2f1f1f; --popup-background-color: #2f1f1f;
--popup-highlighted-background-color: #3f2f2f; --popup-highlighted-background-color: #3f2f2f;
--sidebar-background-color: #1f1e1d; --sidebar-background-color: #2e2a27;
--sidebar-highlighted-background-color: #2f2b28; --sidebar-highlighted-background-color: #36322b;
--topbar-background-color: #2a2723; --topbar-background-color: #2a2723;
--chatbox-background-color: #1a1713; --chatbox-background-color: #1a1713;

View file

@ -10,13 +10,13 @@ complementaryColor = black
--reply-text-color: #969696; --reply-text-color: #969696;
--danger-text-color: #ff0000; --danger-text-color: #ff0000;
--chat-background-color: #f0edeb; --chat-background-color: #f0ebe8;
--chat-highlighted-background-color: #aba8a4; --chat-highlighted-background-color: #e8e4e0;
--chat-important-background-color: #df5f0b26; --chat-important-background-color: #df5f0b26;
--chat-important-hightlighted-background-color: #df5f0b3d; --chat-important-hightlighted-background-color: #df5f0b3d;
--chat-featured-message-color: #e8ac841f; --chat-featured-message-color: #e8ac841f;
--popup-background-color: #b8b4b0; --popup-background-color: #e8e4e0;
--popup-highlighted-background-color: #a6a4a2; --popup-highlighted-background-color: #dfdbd6;
--sidebar-background-color: #dbd8d4; --sidebar-background-color: #dbd8d4;
--sidebar-highlighted-background-color: #d4d0ca; --sidebar-highlighted-background-color: #d4d0ca;

View file

@ -1,9 +1,21 @@
import type { MessageResponse, UserResponse } from "./interfaces"; import type { GuildMemberResponse, MessageResponse, UserResponse } from "./interfaces";
export interface MessageProps { export interface MessageProps {
message: MessageResponse, class?: string,
replyMessage?: MessageResponse, img?: string | null,
author: GuildMemberResponse
text: string,
timestamp: number,
format: "12" | "24",
type: "normal" | "grouped", type: "normal" | "grouped",
marginBottom: boolean,
authorColor: string,
last: boolean,
messageId: string,
replyingTo?: boolean,
editing?: boolean, editing?: boolean,
me: UserResponse
message: MessageResponse,
replyMessage?: MessageResponse
isMentioned?: boolean, isMentioned?: boolean,
} }

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

@ -9,7 +9,7 @@ export default (element: HTMLDivElement, props: MessageProps) => {
const messageBox = document.getElementById("message-box") as HTMLDivElement; const messageBox = document.getElementById("message-box") as HTMLDivElement;
if (messageBox) { if (messageBox) {
const div = document.createElement("div"); const div = document.createElement("div");
const messageReply = h(MessageReply, { author: getDisplayName(props.message.member), text: props.message.message || "", id: props.message.uuid, replyId: props.replyMessage?.uuid || element.dataset.messageId!, maxWidth: "full" }); const messageReply = h(MessageReply, { author: getDisplayName(props.author), text: props.text || "", id: props.message.uuid, replyId: props.replyMessage?.uuid || element.dataset.messageId!, maxWidth: "full" });
messageBox.prepend(div); messageBox.prepend(div);
render(messageReply, div); render(messageReply, div);
const message = document.querySelector(`.message[data-message-id='${props.message.uuid}']`); const message = document.querySelector(`.message[data-message-id='${props.message.uuid}']`);

View file

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