diff --git a/classes/Message.ts b/classes/Message.ts index de0d12b..a782d6a 100644 --- a/classes/Message.ts +++ b/classes/Message.ts @@ -12,8 +12,4 @@ export default class Message { this.userUuid = user_uuid; this.message = message; } - - getTimestamp() { - return uuidToTimestamp(this.uuid); - } } \ No newline at end of file diff --git a/components/Message.vue b/components/Message.vue index c926616..c6207a1 100644 --- a/components/Message.vue +++ b/components/Message.vue @@ -1,24 +1,22 @@ @@ -71,33 +69,37 @@ import MessageReply from './UserInterface/MessageReply.vue'; import type { ContextMenuInterface, ContextMenuItem } from '~/types/interfaces'; const { getDisplayName } = useProfile() +const { getUser } = useAuth() const props = defineProps(); +const me = await getUser() + const contextMenu = useState("contextMenu", () => ({ show: false, pointerX: 0, pointerY: 0, items: [] })); const messageElement = ref(); const dateHidden = ref(true); -const date = new Date(props.timestamp); +const date = uuidToDate(props.message.uuid); + const currentDate: Date = new Date() console.log("[MSG] message to render:", props.message); -console.log("author:", props.author); +console.log("author:", props.message.member); 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 linkMatches = props.message.message.matchAll(linkRegex).map(link => link[0]); -const mediaLinks: string[] = []; +const mediaLinks = ref([]); console.log("link matches:", linkMatches); -const hasEmbed = ref(false); +const hideText = ref(false); const sanitized = ref(); onMounted(async () => { - const parsed = await parse(props.text, { gfm: true }); + const parsed = await parse(props.message.message, { gfm: true }); sanitized.value = DOMPurify.sanitize(parsed, { ALLOWED_TAGS: [ "strong", "em", "br", "blockquote", @@ -121,23 +123,35 @@ onMounted(async () => { console.log("added listeners"); } + const links: string[] = []; for (const link of linkMatches) { - console.log("link:", link); - try { - const res = await $fetch.raw(link); - if (res.ok && res.headers.get("content-type")?.match(/^image\/(apng|gif|jpeg|png|webp)$/)) { - console.log("link is image"); - mediaLinks.push(link); + console.log("link:", link); + try { + const res = await $fetch.raw(link); + if (res.ok && res.headers.get("content-type")?.match(/^image\/(apng|gif|jpeg|png|webp)$/)) { + console.log("link is image"); + links.push(link); + } + } catch (error) { + console.error(error); } - if (mediaLinks.length) { - hasEmbed.value = true - }; - } catch (error) { - console.error(error); - } -} -console.log("media links:", mediaLinks); + mediaLinks.value = [...links]; + } + + if (mediaLinks.value.length) { + const nonLinks = props.message.message.split(linkRegex); + let invalidContent = false; + for (const nonLink of nonLinks) { + if (nonLink != "" && nonLink != "\n" && nonLink != "
") { + invalidContent = true; + break; + } + } + hideText.value = !invalidContent; + }; + + console.log("media links:", mediaLinks); }); //function toggleTooltip(e: Event) { @@ -148,13 +162,13 @@ const menuItems: 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) { +console.log("me:", me); +if (props.message.member.user.uuid == 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) */ } }); } -if (props.author?.user.uuid == props.me.uuid /* || check message delete permission*/) { +if (props.message.member.user.uuid == 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: () => {} }); } @@ -174,14 +188,20 @@ function getDayDifference(date1: Date, date2: Date) { \ No newline at end of file diff --git a/public/themes/layout/gorb.css b/public/themes/layout/gorb.css index 7b8e88b..1cee0b4 100644 --- a/public/themes/layout/gorb.css +++ b/public/themes/layout/gorb.css @@ -9,6 +9,7 @@ complementaryColor = white --sidebar-icon-gap: .25em; --sidebar-margin: .5em; + --minor-radius: .35em; --standard-radius: .5em; --button-radius: .6em; --guild-icon-radius: 15%; diff --git a/public/themes/style/ash.css b/public/themes/style/ash.css index 495fa15..e33fbf6 100644 --- a/public/themes/style/ash.css +++ b/public/themes/style/ash.css @@ -10,15 +10,15 @@ complementaryColor = white --reply-text-color: #969696; --danger-text-color: #ff0000; - --chat-background-color: #2f2e2d; - --chat-highlighted-background-color: #3f3b38; + --chat-background-color: #383432; + --chat-highlighted-background-color: #4c4a48; --chat-important-background-color: #ffcf5f38; --chat-important-highlighted-background-color: #ffa86f4f; --chat-featured-message-color: #4f3f2f60; --popup-background-color: #2f2828; --popup-highlighted-background-color: #382f2f; - --sidebar-background-color: #3e3a37; + --sidebar-background-color: #322f2d; --sidebar-highlighted-background-color: #46423b; --topbar-background-color: #3a3733; --chatbox-background-color: #3a3733; diff --git a/public/themes/style/dark.css b/public/themes/style/dark.css index d23ed76..420e8c9 100644 --- a/public/themes/style/dark.css +++ b/public/themes/style/dark.css @@ -10,16 +10,16 @@ complementaryColor = white --reply-text-color: #969696; --danger-text-color: #ff0000; - --chat-background-color: #1f1e1d; - --chat-highlighted-background-color: #2f2b28; + --chat-background-color: #282624; + --chat-highlighted-background-color: #383430; --chat-important-background-color: #ffc44f2f; --chat-important-highlighted-background-color: #ffa45f4a; --chat-featured-message-color: #4f2f1f58; --popup-background-color: #2f1f1f; --popup-highlighted-background-color: #3f2f2f; - --sidebar-background-color: #2e2a27; - --sidebar-highlighted-background-color: #36322b; + --sidebar-background-color: #1f1e1d; + --sidebar-highlighted-background-color: #2f2b28; --topbar-background-color: #2a2723; --chatbox-background-color: #1a1713; diff --git a/public/themes/style/light.css b/public/themes/style/light.css index 78bf2f9..cd1f55b 100644 --- a/public/themes/style/light.css +++ b/public/themes/style/light.css @@ -10,13 +10,13 @@ complementaryColor = black --reply-text-color: #969696; --danger-text-color: #ff0000; - --chat-background-color: #f0ebe8; - --chat-highlighted-background-color: #e8e4e0; + --chat-background-color: #f0edeb; + --chat-highlighted-background-color: #aba8a4; --chat-important-background-color: #df5f0b26; --chat-important-hightlighted-background-color: #df5f0b3d; --chat-featured-message-color: #e8ac841f; - --popup-background-color: #e8e4e0; - --popup-highlighted-background-color: #dfdbd6; + --popup-background-color: #b8b4b0; + --popup-highlighted-background-color: #a6a4a2; --sidebar-background-color: #dbd8d4; --sidebar-highlighted-background-color: #d4d0ca; diff --git a/types/props.ts b/types/props.ts index f25ae8d..5796d83 100644 --- a/types/props.ts +++ b/types/props.ts @@ -1,21 +1,9 @@ -import type { GuildMemberResponse, MessageResponse, UserResponse } from "./interfaces"; +import type { MessageResponse, UserResponse } from "./interfaces"; export interface MessageProps { - class?: string, - img?: string | null, - author: GuildMemberResponse - text: string, - timestamp: number, - format: "12" | "24", - type: "normal" | "grouped", - marginBottom: boolean, - authorColor: string, - last: boolean, - messageId: string, - replyingTo?: boolean, - editing?: boolean, - me: UserResponse message: MessageResponse, - replyMessage?: MessageResponse + replyMessage?: MessageResponse, + type: "normal" | "grouped", + editing?: boolean, isMentioned?: boolean, } \ No newline at end of file diff --git a/utils/replyToMessage.ts b/utils/replyToMessage.ts index 83f4eda..1ff4df7 100644 --- a/utils/replyToMessage.ts +++ b/utils/replyToMessage.ts @@ -9,7 +9,7 @@ export default (element: HTMLDivElement, props: MessageProps) => { const messageBox = document.getElementById("message-box") as HTMLDivElement; if (messageBox) { const div = document.createElement("div"); - const messageReply = h(MessageReply, { author: getDisplayName(props.author), text: props.text || "", id: props.message.uuid, replyId: props.replyMessage?.uuid || element.dataset.messageId!, maxWidth: "full" }); + 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" }); messageBox.prepend(div); render(messageReply, div); const message = document.querySelector(`.message[data-message-id='${props.message.uuid}']`);