Files
dredgegram/resources/js/pages/Messages/Show.vue
T
dredgy cc225414e0
linter / quality (push) Canceled after 0s
tests / ci (8.3) (push) Canceled after 0s
tests / ci (8.4) (push) Canceled after 0s
tests / ci (8.5) (push) Canceled after 0s
Initial Commit
2026-08-28 23:20:23 +10:00

268 lines
7.1 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, computed } from 'vue';
import { Link } from '@inertiajs/vue3';
import AppLayout from '@/layouts/AppLayout.vue';
import Avatar from '@/components/dredge/Avatar.vue';
import { proxyImage } from '@/lib/proxyImage';
import type { ThreadDetail, ThreadMessage } from '@/types/dredge.types';
defineOptions({
layout: AppLayout,
});
const props = defineProps<{
threadId: string;
}>();
const ME = 'generictravelphotos';
const thread = ref<ThreadDetail | null>(null);
const loading = ref(true);
const error = ref<string | null>(null);
const threadName = computed(() => {
if (!thread.value) return '';
if (thread.value.thread_title) return thread.value.thread_title;
return thread.value.participants.map((p) => p.username).join(', ') || 'Unknown';
});
async function fetchThread() {
loading.value = true;
error.value = null;
try {
const response = await fetch(`/api/threads/${props.threadId}`);
if (!response.ok) {
throw new Error('Failed to load thread');
}
thread.value = await response.json();
} catch (e) {
error.value = 'Could not load this conversation.';
} finally {
loading.value = false;
}
}
function avatarFor(username: string | null): string | null {
if (!thread.value || !username) return null;
return thread.value.participants.find((p) => p.username === username)?.profile_pic_url ?? null;
}
function isSystemMessage(message: ThreadMessage): boolean {
return !message.text && !message.shared_url;
}
function systemLabel(message: ThreadMessage): string {
if (message.item_type?.includes('REACTION')) return 'Reacted to a message';
return 'Sent an attachment';
}
onMounted(fetchThread);
</script>
<template>
<section class="thread">
<header class="thread__header">
<Link href="/messages" class="thread__back" aria-label="Back to messages">
<span class="mdi mdi-arrow-left"></span>
</Link>
<span class="thread__title">{{ threadName }}</span>
</header>
<p v-if="loading" class="thread__status">Loading conversation</p>
<p v-else-if="error" class="thread__status" role="alert">{{ error }}</p>
<div v-else class="thread__messages">
<div
v-for="message in thread!.messages"
:key="message.id"
class="bubble-row"
:class="{ 'bubble-row--me': message.username === ME }"
>
<Avatar
v-if="message.username !== ME"
size="sm"
:src="avatarFor(message.username)"
:alt="`${message.username}'s profile picture`"
/>
<div class="bubble">
<p v-if="message.replied_to_text" class="bubble__reply">
{{ message.replied_to_text }}
</p>
<p v-if="message.text" class="bubble__text">{{ message.text }}</p>
<a
v-if="message.shared_url"
:href="message.shared_url"
target="_blank"
rel="noopener noreferrer"
class="bubble__share"
>
<img
v-if="message.shared_preview_image"
:src="proxyImage(message.shared_preview_image)"
alt=""
class="bubble__share-image"
/>
<span class="bubble__share-body">
<span v-if="message.shared_title" class="bubble__share-title">
{{ message.shared_title }}
</span>
<span v-if="message.shared_caption" class="bubble__share-caption">
{{ message.shared_caption }}
</span>
</span>
</a>
<p v-if="isSystemMessage(message)" class="bubble__system">
{{ systemLabel(message) }}
</p>
<div v-if="message.reactions?.length" class="bubble__reactions">
<span
v-for="(reaction, i) in message.reactions"
:key="i"
class="bubble__reaction"
>
{{ reaction.emoji }}
</span>
</div>
</div>
</div>
</div>
</section>
</template>
<style scoped>
.thread {
display: flex;
flex-direction: column;
gap: 1rem;
}
.thread__header {
display: flex;
align-items: center;
gap: 0.75rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid var(--line);
}
.thread__back {
display: flex;
align-items: center;
justify-content: center;
width: 2.2rem;
height: 2.2rem;
border-radius: 50%;
color: inherit;
text-decoration: none;
}
.thread__back:hover {
background: var(--panel);
}
.thread__title {
font-weight: 600;
font-size: 1rem;
}
.thread__status {
color: var(--sediment-dim);
}
.thread__messages {
display: flex;
flex-direction: column;
gap: 0.6rem;
}
.bubble-row {
display: flex;
align-items: flex-end;
gap: 0.5rem;
}
.bubble-row--me {
flex-direction: row-reverse;
}
.bubble {
max-width: 70%;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
padding: 0.55rem 0.8rem;
font-size: 0.88rem;
line-height: 1.4;
}
.bubble-row--me .bubble {
background: var(--bioluminum);
color: #04141a;
border-color: transparent;
}
.bubble__reply {
font-size: 0.75rem;
color: var(--sediment-dim);
border-left: 2px solid var(--haze);
padding-left: 0.5rem;
margin-bottom: 0.3rem;
}
.bubble-row--me .bubble__reply {
color: rgba(4, 20, 26, 0.7);
border-left-color: rgba(4, 20, 26, 0.4);
}
.bubble__text {
white-space: pre-wrap;
word-break: break-word;
}
.bubble__system {
font-style: italic;
color: var(--sediment-dim);
}
.bubble-row--me .bubble__system {
color: rgba(4, 20, 26, 0.7);
}
.bubble__share {
display: flex;
gap: 0.6rem;
text-decoration: none;
color: inherit;
background: rgba(0, 0, 0, 0.15);
border-radius: 8px;
padding: 0.4rem;
margin-top: 0.3rem;
}
.bubble__share-image {
width: 48px;
height: 48px;
object-fit: cover;
border-radius: 6px;
flex-shrink: 0;
}
.bubble__share-body {
display: flex;
flex-direction: column;
min-width: 0;
justify-content: center;
}
.bubble__share-title {
font-weight: 600;
font-size: 0.82rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bubble__share-caption {
font-size: 0.75rem;
opacity: 0.8;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bubble__reactions {
margin-top: 0.3rem;
display: flex;
gap: 0.2rem;
}
.bubble__reaction {
font-size: 0.85rem;
}
</style>