Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
2844452002
55 changed files with 5448 additions and 0 deletions
17
resources/js/components/ChatAvatar.vue
Normal file
17
resources/js/components/ChatAvatar.vue
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<script setup>
|
||||
import { Users } from '@lucide/vue';
|
||||
import { PersonAvatar } from '@inhaus/ui';
|
||||
|
||||
/** Bild eines Gesprächs: Person bei Direktnachrichten, Symbol bei Gruppen */
|
||||
defineProps({
|
||||
conversation: { type: Object, required: true },
|
||||
size: { type: String, default: 'ih:size-10' },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PersonAvatar v-if="conversation.person" :person="conversation.person" :class="size" />
|
||||
<span v-else class="ih:grid ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand-soft ih:text-brand-text" :class="size" aria-hidden="true">
|
||||
<Users class="ih:size-[45%]" />
|
||||
</span>
|
||||
</template>
|
||||
199
resources/js/components/Composer.vue
Normal file
199
resources/js/components/Composer.vue
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
<script setup>
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
import { File as FileGlyph, Image as ImageGlyph, LoaderCircle, Paperclip, Pencil, SendHorizontal, Smile, X } from '@lucide/vue';
|
||||
import { toast } from '@inhaus/ui';
|
||||
import EmojiPicker from './EmojiPicker.vue';
|
||||
import GifPicker from './GifPicker.vue';
|
||||
import Popup from './Popup.vue';
|
||||
import { fileSize } from '../lib/format';
|
||||
|
||||
const props = defineProps({
|
||||
replyTo: { type: Object, default: null },
|
||||
editing: { type: Object, default: null },
|
||||
maxUploadMb: { type: Number, default: 25 },
|
||||
sending: { type: Boolean, default: false },
|
||||
});
|
||||
const emit = defineEmits(['send', 'save-edit', 'cancel', 'typing']);
|
||||
|
||||
const text = ref('');
|
||||
const files = ref([]);
|
||||
const input = ref(null);
|
||||
const fileInput = ref(null);
|
||||
const popup = ref(null); // 'emoji' | 'gif'
|
||||
const canSend = computed(() => !props.sending && (text.value.trim() || files.value.length));
|
||||
|
||||
// Beim Bearbeiten den Text übernehmen
|
||||
watch(() => props.editing, (message) => {
|
||||
text.value = message?.body ?? '';
|
||||
nextTick(focus);
|
||||
});
|
||||
watch(() => props.replyTo, (message) => message && nextTick(focus));
|
||||
|
||||
function focus() {
|
||||
input.value?.focus();
|
||||
resize();
|
||||
}
|
||||
|
||||
function resize() {
|
||||
const el = input.value;
|
||||
|
||||
if (!el) return;
|
||||
|
||||
el.style.height = 'auto';
|
||||
el.style.height = `${Math.min(el.scrollHeight, 180)}px`;
|
||||
}
|
||||
|
||||
let lastTyping = 0;
|
||||
function onInput() {
|
||||
resize();
|
||||
|
||||
if (Date.now() - lastTyping > 3000 && text.value.trim()) {
|
||||
lastTyping = Date.now();
|
||||
emit('typing');
|
||||
}
|
||||
}
|
||||
|
||||
function addFiles(list) {
|
||||
for (const file of list) {
|
||||
if (file.size > props.maxUploadMb * 1024 * 1024) {
|
||||
toast.error(`„${file.name}“ ist größer als ${props.maxUploadMb} MB.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (files.value.length >= 10) {
|
||||
toast.error('Höchstens 10 Dateien je Nachricht.');
|
||||
break;
|
||||
}
|
||||
|
||||
files.value.push({ file, url: file.type.startsWith('image/') ? URL.createObjectURL(file) : null });
|
||||
}
|
||||
|
||||
focus();
|
||||
}
|
||||
|
||||
function onPaste(event) {
|
||||
const pasted = [...(event.clipboardData?.files ?? [])];
|
||||
|
||||
if (pasted.length) {
|
||||
event.preventDefault();
|
||||
addFiles(pasted);
|
||||
}
|
||||
}
|
||||
|
||||
function removeFile(index) {
|
||||
const [removed] = files.value.splice(index, 1);
|
||||
removed?.url && URL.revokeObjectURL(removed.url);
|
||||
}
|
||||
|
||||
function submit() {
|
||||
if (props.editing) {
|
||||
text.value.trim() && emit('save-edit', text.value.trim());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canSend.value) return;
|
||||
|
||||
emit('send', { body: text.value, files: files.value.map((f) => f.file) });
|
||||
files.value.forEach((f) => f.url && URL.revokeObjectURL(f.url));
|
||||
files.value = [];
|
||||
text.value = '';
|
||||
nextTick(resize);
|
||||
}
|
||||
|
||||
function onKeydown(event) {
|
||||
// Enter sendet, Umschalt+Enter macht eine neue Zeile
|
||||
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
|
||||
event.preventDefault();
|
||||
submit();
|
||||
}
|
||||
|
||||
if (event.key === 'Escape' && (props.editing || props.replyTo)) emit('cancel');
|
||||
}
|
||||
|
||||
function insertEmoji(emoji) {
|
||||
const el = input.value;
|
||||
const start = el?.selectionStart ?? text.value.length;
|
||||
const end = el?.selectionEnd ?? text.value.length;
|
||||
text.value = text.value.slice(0, start) + emoji + text.value.slice(end);
|
||||
nextTick(() => {
|
||||
el?.focus();
|
||||
el?.setSelectionRange(start + emoji.length, start + emoji.length);
|
||||
});
|
||||
}
|
||||
|
||||
function pickGif(gif) {
|
||||
popup.value = null;
|
||||
emit('send', { gifUrl: gif.url });
|
||||
}
|
||||
|
||||
const toggle = (name) => (popup.value = popup.value === name ? null : name);
|
||||
|
||||
defineExpose({ addFiles, focus });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="ih:border-t ih:bg-card ih:p-3">
|
||||
<!-- Antworten / Bearbeiten -->
|
||||
<div v-if="replyTo || editing" class="ih:mb-2 ih:flex ih:items-start ih:gap-2 ih:rounded-md ih:border-l-3 ih:border-brand ih:bg-muted ih:px-3 ih:py-1.5 ih:text-[13px]">
|
||||
<Pencil v-if="editing" class="ih:mt-0.5 ih:size-3.5 ih:shrink-0 ih:text-brand-text" />
|
||||
<span class="ih:min-w-0 ih:flex-1">
|
||||
<span class="ih:block ih:font-semibold">{{ editing ? 'Nachricht bearbeiten' : `Antwort an ${replyTo.user?.name ?? ''}` }}</span>
|
||||
<span v-if="replyTo" class="ih:line-clamp-1 ih:text-muted-foreground">{{ replyTo.body || (replyTo.gif_url ? 'GIF' : 'Datei') }}</span>
|
||||
</span>
|
||||
<button type="button" class="ih:rounded ih:p-0.5 ih:text-muted-foreground ih:hover:text-foreground" aria-label="Abbrechen" @click="emit('cancel')"><X class="ih:size-4" /></button>
|
||||
</div>
|
||||
|
||||
<!-- Ausgewählte Dateien -->
|
||||
<ul v-if="files.length" class="ih:mb-2 ih:flex ih:gap-2 ih:overflow-x-auto ih:pb-1">
|
||||
<li v-for="(f, i) in files" :key="i" class="ih:relative ih:shrink-0">
|
||||
<img v-if="f.url" :src="f.url" :alt="f.file.name" class="ih:size-16 ih:rounded-md ih:border ih:object-cover" />
|
||||
<span v-else class="ih:flex ih:h-16 ih:w-36 ih:items-center ih:gap-2 ih:rounded-md ih:border ih:bg-muted ih:px-2 ih:text-xs">
|
||||
<FileGlyph class="ih:size-5 ih:shrink-0 ih:text-muted-foreground" />
|
||||
<span class="ih:min-w-0"><span class="ih:block ih:truncate ih:font-medium">{{ f.file.name }}</span>{{ fileSize(f.file.size) }}</span>
|
||||
</span>
|
||||
<button type="button" class="ih:absolute ih:-top-1.5 ih:-right-1.5 ih:grid ih:size-5 ih:place-items-center ih:rounded-full ih:bg-foreground ih:text-background" :aria-label="`${f.file.name} entfernen`" @click="removeFile(i)"><X class="ih:size-3" /></button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="ih:relative ih:flex ih:items-end ih:gap-1">
|
||||
<Popup v-if="popup === 'emoji'" @close="popup = null"><EmojiPicker @pick="insertEmoji" /></Popup>
|
||||
<Popup v-if="popup === 'gif'" @close="popup = null"><GifPicker @pick="pickGif" /></Popup>
|
||||
|
||||
<template v-if="!editing">
|
||||
<button type="button" data-popup-toggle class="ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground" :class="{ 'ih:bg-muted ih:text-foreground': popup === 'emoji' }" aria-label="Emoji einfügen" :aria-expanded="popup === 'emoji'" @click="toggle('emoji')"><Smile class="ih:size-5" /></button>
|
||||
<button type="button" data-popup-toggle class="ih:grid ih:h-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:px-2 ih:text-xs ih:font-bold ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground" :class="{ 'ih:bg-muted ih:text-foreground': popup === 'gif' }" aria-label="GIF senden" :aria-expanded="popup === 'gif'" @click="toggle('gif')">GIF</button>
|
||||
<button type="button" class="ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground" aria-label="Datei anhängen" @click="fileInput?.click()"><Paperclip class="ih:size-5" /></button>
|
||||
<input ref="fileInput" type="file" multiple class="ih:hidden" @change="addFiles([...$event.target.files]); $event.target.value = ''" />
|
||||
</template>
|
||||
|
||||
<textarea
|
||||
ref="input"
|
||||
v-model="text"
|
||||
rows="1"
|
||||
maxlength="5000"
|
||||
:placeholder="editing ? 'Nachricht bearbeiten' : 'Nachricht schreiben'"
|
||||
aria-label="Nachricht"
|
||||
class="ih:max-h-[180px] ih:min-h-10 ih:flex-1 ih:resize-none ih:rounded-2xl ih:border ih:border-input ih:bg-background ih:px-4 ih:py-2 ih:text-[15px] ih:leading-snug ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none"
|
||||
@input="onInput"
|
||||
@keydown="onKeydown"
|
||||
@paste="onPaste"
|
||||
/>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand ih:text-brand-foreground ih:transition-opacity ih:disabled:opacity-40"
|
||||
:disabled="editing ? !text.trim() : !canSend"
|
||||
:aria-label="editing ? 'Speichern' : 'Senden'"
|
||||
@click="submit"
|
||||
>
|
||||
<LoaderCircle v-if="sending" class="ih:size-5 ih:animate-spin" />
|
||||
<SendHorizontal v-else class="ih:size-5" />
|
||||
</button>
|
||||
</div>
|
||||
<p class="ih:mt-1.5 ih:hidden ih:text-[11px] ih:text-muted-foreground ih:sm:block">
|
||||
<kbd class="ih:font-sans">Enter</kbd> senden · <kbd class="ih:font-sans">Umschalt + Enter</kbd> neue Zeile · Bilder lassen sich auch einfügen oder hierher ziehen
|
||||
<ImageGlyph class="ih:inline ih:size-3" />
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
105
resources/js/components/ConversationInfo.vue
Normal file
105
resources/js/components/ConversationInfo.vue
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Crown, EyeOff, LoaderCircle, LogOut, UserMinus, UserPlus } from '@lucide/vue';
|
||||
import { Button, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, Input, PersonAvatar, Switch, toast } from '@inhaus/ui';
|
||||
import PeopleSelect from './PeopleSelect.vue';
|
||||
import { api } from '../lib/api';
|
||||
|
||||
/** Einstellungen eines Gesprächs: Stummschalten, Mitglieder (Gruppen), Verlassen bzw. Ausblenden */
|
||||
const props = defineProps({
|
||||
conversation: { type: Object, required: true },
|
||||
me: { type: Object, required: true },
|
||||
});
|
||||
const open = defineModel('open', { type: Boolean, default: false });
|
||||
const emit = defineEmits(['updated', 'left']);
|
||||
|
||||
const isGroup = computed(() => props.conversation.type === 'group');
|
||||
const name = ref('');
|
||||
const adding = ref([]);
|
||||
const busy = ref(false);
|
||||
|
||||
watch(open, (value) => {
|
||||
if (value) {
|
||||
name.value = props.conversation.name;
|
||||
adding.value = [];
|
||||
}
|
||||
});
|
||||
|
||||
async function run(action, message) {
|
||||
busy.value = true;
|
||||
|
||||
try {
|
||||
const data = await action();
|
||||
emit('updated', data.conversations);
|
||||
message && toast.success(message);
|
||||
} catch (error) {
|
||||
toast.error(error.message);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const rename = () => run(() => api.updateConversation(props.conversation.id, { name: name.value.trim() }), 'Gruppe umbenannt');
|
||||
const mute = (muted) => run(() => api.updateConversation(props.conversation.id, { muted }), muted ? 'Stummgeschaltet – keine Benachrichtigungen mehr' : 'Benachrichtigungen wieder an');
|
||||
const add = () => run(() => api.addMembers(props.conversation.id, adding.value.map((p) => p.id)), 'Hinzugefügt').then(() => (adding.value = []));
|
||||
const removeMember = (member) => window.confirm(`${member.name} aus der Gruppe entfernen?`) && run(() => api.removeMember(props.conversation.id, member.id));
|
||||
const toggleAdmin = (member) => run(() => api.setAdmin(props.conversation.id, member.id, !member.admin));
|
||||
|
||||
async function leave() {
|
||||
if (!window.confirm(isGroup.value ? 'Gruppe verlassen? Sie sehen die Nachrichten danach nicht mehr.' : 'Gespräch aus Ihrer Liste entfernen? Mit der nächsten Nachricht erscheint es wieder.')) return;
|
||||
|
||||
await run(() => api.leave(props.conversation.id));
|
||||
open.value = false;
|
||||
emit('left');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<DialogContent class="ih:max-h-[85dvh] ih:overflow-y-auto ih:sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ conversation.name }}</DialogTitle>
|
||||
<DialogDescription>{{ isGroup ? `Gruppe mit ${conversation.members.length} Mitgliedern` : 'Direktnachricht' }}</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div class="ih:grid ih:gap-5">
|
||||
<form v-if="isGroup && conversation.is_admin" class="ih:flex ih:gap-2" @submit.prevent="rename">
|
||||
<Input v-model="name" maxlength="100" aria-label="Name der Gruppe" />
|
||||
<Button type="submit" variant="outline" :disabled="busy || !name.trim() || name.trim() === conversation.name">Umbenennen</Button>
|
||||
</form>
|
||||
|
||||
<label class="ih:flex ih:items-center ih:justify-between ih:gap-3 ih:text-sm">
|
||||
<span><span class="ih:font-medium">Stummschalten</span><span class="ih:block ih:text-xs ih:text-muted-foreground">Keine Glocke und kein Push für dieses Gespräch.</span></span>
|
||||
<Switch :model-value="conversation.muted" :disabled="busy" @update:model-value="mute" />
|
||||
</label>
|
||||
|
||||
<section v-if="isGroup" class="ih:grid ih:gap-2">
|
||||
<h3 class="ih:text-sm ih:font-semibold">Mitglieder</h3>
|
||||
<ul class="ih:-mx-2 ih:grid">
|
||||
<li v-for="member in conversation.members" :key="member.id" class="ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:px-2 ih:py-1.5 ih:hover:bg-muted/60">
|
||||
<PersonAvatar :person="member" class="ih:size-8 ih:text-[11px]" />
|
||||
<span class="ih:min-w-0 ih:flex-1 ih:text-sm">
|
||||
<span class="ih:font-medium">{{ member.name }}</span><span v-if="member.id === me.id" class="ih:text-muted-foreground"> (Sie)</span>
|
||||
<span v-if="member.admin" class="ih:ml-1.5 ih:inline-flex ih:items-center ih:gap-0.5 ih:text-xs ih:text-brand-text"><Crown class="ih:size-3" /> Admin</span>
|
||||
</span>
|
||||
<template v-if="conversation.is_admin && member.id !== me.id">
|
||||
<button type="button" class="ih:rounded ih:p-1.5 ih:text-muted-foreground ih:hover:bg-accent ih:hover:text-foreground" :title="member.admin ? 'Admin-Rechte entziehen' : 'Zum Admin machen'" :aria-label="member.admin ? `${member.name}: Admin-Rechte entziehen` : `${member.name} zum Admin machen`" @click="toggleAdmin(member)"><Crown class="ih:size-4" /></button>
|
||||
<button type="button" class="ih:rounded ih:p-1.5 ih:text-muted-foreground ih:hover:bg-accent ih:hover:text-destructive" :aria-label="`${member.name} entfernen`" @click="removeMember(member)"><UserMinus class="ih:size-4" /></button>
|
||||
</template>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="conversation.is_admin" class="ih:grid ih:gap-2 ih:rounded-md ih:border ih:p-3">
|
||||
<span class="ih:flex ih:items-center ih:gap-1.5 ih:text-sm ih:font-medium"><UserPlus class="ih:size-4" /> Personen hinzufügen</span>
|
||||
<PeopleSelect v-model="adding" multiple :exclude="conversation.members.map((m) => m.id)" />
|
||||
<Button v-if="adding.length" size="sm" class="ih:justify-self-start" :disabled="busy" @click="add"><LoaderCircle v-if="busy" class="ih:animate-spin" /> {{ adding.length }} hinzufügen</Button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Button variant="outline" class="ih:justify-self-start ih:text-destructive ih:hover:text-destructive" :disabled="busy" @click="leave">
|
||||
<component :is="isGroup ? LogOut : EyeOff" /> {{ isGroup ? 'Gruppe verlassen' : 'Aus der Liste entfernen' }}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
64
resources/js/components/ConversationList.vue
Normal file
64
resources/js/components/ConversationList.vue
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { BellOff, MessageSquarePlus, Search, UsersRound } from '@lucide/vue';
|
||||
import { Button } from '@inhaus/ui';
|
||||
import ChatAvatar from './ChatAvatar.vue';
|
||||
import { listTime } from '../lib/format';
|
||||
|
||||
const props = defineProps({
|
||||
conversations: { type: Array, required: true },
|
||||
activeId: { type: Number, default: null },
|
||||
canCreateGroups: { type: Boolean, default: false },
|
||||
});
|
||||
const emit = defineEmits(['open', 'new-chat', 'new-group']);
|
||||
|
||||
const query = ref('');
|
||||
const filtered = computed(() => {
|
||||
const q = query.value.trim().toLowerCase();
|
||||
|
||||
return q ? props.conversations.filter((c) => [c.name, ...c.members.map((m) => m.name)].join(' ').toLowerCase().includes(q)) : props.conversations;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="ih:flex ih:h-full ih:min-h-0 ih:flex-col">
|
||||
<div class="ih:flex ih:items-center ih:gap-2 ih:border-b ih:p-3">
|
||||
<h1 class="ih:flex-1 ih:text-lg ih:font-semibold ih:tracking-tight">Nachrichten</h1>
|
||||
<Button v-if="canCreateGroups" variant="ghost" size="icon" title="Neue Gruppe" aria-label="Neue Gruppe" @click="emit('new-group')"><UsersRound /></Button>
|
||||
<Button size="icon" title="Neue Nachricht" aria-label="Neue Nachricht" @click="emit('new-chat')"><MessageSquarePlus /></Button>
|
||||
</div>
|
||||
<div class="ih:border-b ih:p-3">
|
||||
<div class="ih:relative">
|
||||
<Search class="ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground" />
|
||||
<input v-model="query" type="search" placeholder="Gespräche durchsuchen" aria-label="Gespräche durchsuchen" class="ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none" />
|
||||
</div>
|
||||
</div>
|
||||
<ul class="ih:min-h-0 ih:flex-1 ih:overflow-y-auto" aria-label="Gespräche">
|
||||
<li v-for="c in filtered" :key="c.id">
|
||||
<button
|
||||
type="button"
|
||||
class="ih:flex ih:w-full ih:items-center ih:gap-3 ih:px-3 ih:py-2.5 ih:text-left ih:transition-colors"
|
||||
:class="c.id === activeId ? 'ih:bg-brand-soft' : 'ih:hover:bg-accent/60'"
|
||||
:aria-current="c.id === activeId ? 'true' : undefined"
|
||||
@click="emit('open', c.id)"
|
||||
>
|
||||
<ChatAvatar :conversation="c" size="ih:size-11" />
|
||||
<span class="ih:min-w-0 ih:flex-1">
|
||||
<span class="ih:flex ih:items-baseline ih:gap-2">
|
||||
<span class="ih:min-w-0 ih:flex-1 ih:truncate ih:text-sm" :class="c.unread ? 'ih:font-semibold' : 'ih:font-medium'">{{ c.name }}</span>
|
||||
<span class="ih:shrink-0 ih:text-[11px] ih:text-muted-foreground ih:tabular-nums">{{ listTime(c.last_message_at) }}</span>
|
||||
</span>
|
||||
<span class="ih:flex ih:items-center ih:gap-2">
|
||||
<span class="ih:min-w-0 ih:flex-1 ih:truncate ih:text-[13px]" :class="c.unread ? 'ih:text-foreground' : 'ih:text-muted-foreground'">{{ c.preview ?? (c.type === 'group' ? `${c.members.length} Mitglieder` : 'Noch keine Nachrichten') }}</span>
|
||||
<BellOff v-if="c.muted" class="ih:size-3.5 ih:shrink-0 ih:text-muted-foreground" aria-label="Stummgeschaltet" />
|
||||
<span v-if="c.unread" class="ih:grid ih:h-5 ih:min-w-5 ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand ih:px-1.5 ih:text-[11px] ih:font-semibold ih:text-brand-foreground ih:tabular-nums" :aria-label="`${c.unread} ungelesen`">{{ c.unread > 99 ? '99+' : c.unread }}</span>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="!filtered.length" class="ih:p-6 ih:text-center ih:text-sm ih:text-muted-foreground">
|
||||
{{ query ? 'Nichts gefunden.' : 'Noch keine Gespräche. Oben rechts eine neue Nachricht beginnen.' }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
28
resources/js/components/EmojiPicker.vue
Normal file
28
resources/js/components/EmojiPicker.vue
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { EMOJI_GROUPS } from '../lib/emojis';
|
||||
|
||||
const emit = defineEmits(['pick']);
|
||||
const group = ref(0);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="ih:flex ih:border-b ih:px-1" role="tablist" aria-label="Emoji-Gruppen">
|
||||
<button
|
||||
v-for="(g, i) in EMOJI_GROUPS"
|
||||
:key="g.label"
|
||||
type="button"
|
||||
role="tab"
|
||||
:aria-selected="group === i"
|
||||
:title="g.label"
|
||||
class="ih:grid ih:size-9 ih:place-items-center ih:text-lg ih:transition-opacity"
|
||||
:class="group === i ? 'ih:border-b-2 ih:border-brand' : 'ih:opacity-60 ih:hover:opacity-100'"
|
||||
@click="group = i"
|
||||
>{{ g.icon }}</button>
|
||||
</div>
|
||||
<div class="ih:grid ih:max-h-60 ih:grid-cols-8 ih:gap-0.5 ih:overflow-y-auto ih:p-2" role="tabpanel" :aria-label="EMOJI_GROUPS[group].label">
|
||||
<button v-for="emoji in EMOJI_GROUPS[group].emojis" :key="emoji" type="button" class="ih:grid ih:aspect-square ih:place-items-center ih:rounded ih:text-xl ih:hover:bg-accent" :aria-label="emoji" @click="emit('pick', emoji)">{{ emoji }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
51
resources/js/components/GifPicker.vue
Normal file
51
resources/js/components/GifPicker.vue
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<script setup>
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { LoaderCircle, Search } from '@lucide/vue';
|
||||
import { api } from '../lib/api';
|
||||
|
||||
const emit = defineEmits(['pick']);
|
||||
const query = ref('');
|
||||
const gifs = ref([]);
|
||||
const giphy = ref(false);
|
||||
const loading = ref(false);
|
||||
let timer;
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
|
||||
try {
|
||||
const data = await api.gifs(query.value);
|
||||
gifs.value = data.gifs;
|
||||
giphy.value = data.giphy;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(query, () => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(load, 300);
|
||||
});
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="ih:border-b ih:p-2">
|
||||
<div class="ih:relative">
|
||||
<Search class="ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground" />
|
||||
<input v-model="query" type="search" placeholder="GIFs suchen" aria-label="GIFs suchen" autofocus class="ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:outline-none" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="ih:max-h-72 ih:overflow-y-auto ih:p-2">
|
||||
<div v-if="loading && !gifs.length" class="ih:grid ih:place-items-center ih:py-8"><LoaderCircle class="ih:size-5 ih:animate-spin ih:text-muted-foreground" /></div>
|
||||
<div v-else-if="gifs.length" class="ih:columns-2 ih:gap-1.5">
|
||||
<button v-for="gif in gifs" :key="gif.url" type="button" class="ih:mb-1.5 ih:block ih:w-full ih:overflow-hidden ih:rounded ih:bg-muted ih:hover:ring-2 ih:hover:ring-brand" :title="gif.title" @click="emit('pick', gif)">
|
||||
<img :src="gif.preview" :alt="gif.title" loading="lazy" class="ih:block ih:w-full" :style="gif.width && gif.height ? { aspectRatio: `${gif.width} / ${gif.height}` } : {}" />
|
||||
</button>
|
||||
</div>
|
||||
<p v-else class="ih:py-6 ih:text-center ih:text-sm ih:text-muted-foreground">{{ query ? 'Keine GIFs gefunden.' : 'Noch keine GIFs in der Sammlung.' }}</p>
|
||||
</div>
|
||||
<p v-if="giphy" class="ih:border-t ih:px-3 ih:py-1.5 ih:text-[10px] ih:text-muted-foreground">Mit Suche über GIPHY – Suchbegriffe gehen an GIPHY.</p>
|
||||
</div>
|
||||
</template>
|
||||
124
resources/js/components/MessageBubble.vue
Normal file
124
resources/js/components/MessageBubble.vue
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { CornerUpLeft, Download, Pencil, SmilePlus, Trash2 } from '@lucide/vue';
|
||||
import { FileIcon, PersonAvatar } from '@inhaus/ui';
|
||||
import { fileSize, linkify, messageTime, onlyEmoji } from '../lib/format';
|
||||
|
||||
const props = defineProps({
|
||||
message: { type: Object, required: true },
|
||||
showAuthor: { type: Boolean, default: true },
|
||||
showAvatar: { type: Boolean, default: true },
|
||||
group: { type: Boolean, default: false },
|
||||
reactions: { type: Array, required: true },
|
||||
read: { type: Boolean, default: false },
|
||||
});
|
||||
const emit = defineEmits(['react', 'reply', 'edit', 'delete', 'jump']);
|
||||
|
||||
const m = computed(() => props.message);
|
||||
const bigEmoji = computed(() => !m.value.attachments.length && !m.value.reply_to && onlyEmoji(m.value.body));
|
||||
const images = computed(() => m.value.attachments.filter((a) => a.image));
|
||||
const files = computed(() => m.value.attachments.filter((a) => !a.image));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Systemmeldung (Gruppe erstellt, Person hinzugefügt …) -->
|
||||
<div v-if="m.kind === 'system'" class="ih:my-3 ih:text-center">
|
||||
<span class="ih:inline-block ih:rounded-full ih:bg-muted ih:px-3 ih:py-1 ih:text-xs ih:text-muted-foreground">{{ m.body }}</span>
|
||||
</div>
|
||||
|
||||
<div v-else :id="`nachricht-${m.id}`" class="ih:group ih:flex ih:items-end ih:gap-2" :class="[m.mine ? 'ih:flex-row-reverse' : '', showAuthor ? 'ih:mt-3' : 'ih:mt-0.5']">
|
||||
<div v-if="group && !m.mine" class="ih:w-8 ih:shrink-0">
|
||||
<PersonAvatar v-if="showAvatar && m.user" :person="m.user" class="ih:size-8 ih:text-[11px]" />
|
||||
</div>
|
||||
|
||||
<div class="ih:flex ih:max-w-[min(34rem,80%)] ih:min-w-0 ih:flex-col" :class="m.mine ? 'ih:items-end' : 'ih:items-start'">
|
||||
<span v-if="group && !m.mine && showAuthor" class="ih:mb-0.5 ih:px-3 ih:text-xs ih:font-medium ih:text-muted-foreground">{{ m.user?.name ?? 'Gelöschtes Konto' }}</span>
|
||||
|
||||
<div class="ih:relative ih:flex ih:items-center ih:gap-1" :class="m.mine ? 'ih:flex-row-reverse' : ''">
|
||||
<!-- Blase -->
|
||||
<div
|
||||
v-if="m.deleted"
|
||||
class="ih:rounded-2xl ih:border ih:border-dashed ih:px-3 ih:py-2 ih:text-sm ih:text-muted-foreground ih:italic"
|
||||
>Nachricht gelöscht</div>
|
||||
<div
|
||||
v-else
|
||||
class="ih:min-w-0 ih:overflow-hidden ih:text-[15px] ih:leading-snug"
|
||||
:class="bigEmoji || m.kind === 'gif' ? '' : [m.mine ? 'ih:rounded-2xl ih:rounded-br-md ih:bg-brand ih:text-brand-foreground' : 'ih:rounded-2xl ih:rounded-bl-md ih:border ih:bg-card', images.length && !m.body ? '' : 'ih:px-3 ih:py-2']"
|
||||
>
|
||||
<button
|
||||
v-if="m.reply_to"
|
||||
type="button"
|
||||
class="ih:mb-1.5 ih:block ih:w-full ih:rounded-md ih:border-l-3 ih:px-2 ih:py-1 ih:text-left ih:text-[13px]"
|
||||
:class="m.mine ? 'ih:border-white/60 ih:bg-white/15' : 'ih:border-brand ih:bg-muted'"
|
||||
@click="emit('jump', m.reply_to.id)"
|
||||
>
|
||||
<span class="ih:block ih:font-semibold">{{ m.reply_to.name }}</span>
|
||||
<span class="ih:line-clamp-2 ih:opacity-80">{{ m.reply_to.text }}</span>
|
||||
</button>
|
||||
|
||||
<img v-if="m.kind === 'gif'" :src="m.gif_url" alt="GIF" loading="lazy" class="ih:max-h-60 ih:rounded-2xl" />
|
||||
|
||||
<div v-if="images.length" class="ih:grid ih:gap-0.5" :class="images.length > 1 ? 'ih:grid-cols-2' : ''">
|
||||
<a v-for="img in images" :key="img.id" :href="img.url" target="_blank" rel="noopener" class="ih:block ih:overflow-hidden ih:bg-muted" :title="img.name">
|
||||
<img :src="img.url" :alt="img.name" loading="lazy" class="ih:block ih:max-h-72 ih:w-full ih:object-cover" :style="img.width ? { aspectRatio: `${img.width} / ${img.height}` } : {}" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<a
|
||||
v-for="file in files"
|
||||
:key="file.id"
|
||||
:href="file.url"
|
||||
class="ih:my-1 ih:flex ih:items-center ih:gap-2.5 ih:rounded-lg ih:p-2 ih:no-underline"
|
||||
:class="m.mine ? 'ih:bg-white/15 ih:hover:bg-white/25' : 'ih:bg-muted ih:hover:bg-accent'"
|
||||
>
|
||||
<FileIcon :extension="file.name.split('.').pop()" class="ih:shrink-0" />
|
||||
<span class="ih:min-w-0 ih:flex-1">
|
||||
<span class="ih:block ih:truncate ih:text-sm ih:font-medium">{{ file.name }}</span>
|
||||
<span class="ih:block ih:text-xs ih:opacity-75">{{ fileSize(file.size) }}</span>
|
||||
</span>
|
||||
<Download class="ih:size-4 ih:shrink-0 ih:opacity-75" />
|
||||
</a>
|
||||
|
||||
<p v-if="m.body" class="ih:break-words ih:whitespace-pre-wrap" :class="[bigEmoji ? 'ih:text-4xl ih:leading-tight' : '', images.length ? 'ih:px-3 ih:py-2' : '']">
|
||||
<template v-for="(part, i) in linkify(m.body)" :key="i">
|
||||
<a v-if="part.href" :href="part.href" target="_blank" rel="noopener noreferrer" class="ih:underline ih:underline-offset-2">{{ part.text }}</a>
|
||||
<template v-else>{{ part.text }}</template>
|
||||
</template>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Aktionen beim Überfahren bzw. Fokus -->
|
||||
<div v-if="!m.deleted" class="ih:flex ih:shrink-0 ih:items-center ih:opacity-0 ih:transition-opacity ih:group-hover:opacity-100 ih:focus-within:opacity-100 ih:[@media(hover:none)]:opacity-100">
|
||||
<div class="ih:group/react ih:relative">
|
||||
<button type="button" class="ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted" aria-label="Reagieren"><SmilePlus class="ih:size-4" /></button>
|
||||
<div class="ih:absolute ih:bottom-full ih:z-20 ih:hidden ih:gap-0.5 ih:rounded-full ih:border ih:bg-popover ih:p-1 ih:shadow-md ih:group-focus-within/react:flex ih:group-hover/react:flex" :class="m.mine ? 'ih:right-0' : 'ih:left-0'">
|
||||
<button v-for="emoji in reactions" :key="emoji" type="button" class="ih:grid ih:size-8 ih:place-items-center ih:rounded-full ih:text-lg ih:hover:bg-accent" :aria-label="`Mit ${emoji} reagieren`" @click="emit('react', emoji)">{{ emoji }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted" aria-label="Antworten" @click="emit('reply')"><CornerUpLeft class="ih:size-4" /></button>
|
||||
<template v-if="m.mine">
|
||||
<button v-if="m.body && m.kind === 'text'" type="button" class="ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted" aria-label="Bearbeiten" @click="emit('edit')"><Pencil class="ih:size-4" /></button>
|
||||
<button type="button" class="ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-destructive" aria-label="Löschen" @click="emit('delete')"><Trash2 class="ih:size-4" /></button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="m.reactions.length" class="ih:relative ih:z-10 ih:-mt-1.5 ih:flex ih:flex-wrap ih:gap-1 ih:px-2">
|
||||
<button
|
||||
v-for="r in m.reactions"
|
||||
:key="r.emoji"
|
||||
type="button"
|
||||
class="ih:flex ih:items-center ih:gap-1 ih:rounded-full ih:border ih:px-1.5 ih:text-xs ih:shadow-xs ih:tabular-nums"
|
||||
:class="r.mine ? 'ih:border-brand ih:bg-brand-soft' : 'ih:bg-card'"
|
||||
:aria-pressed="r.mine"
|
||||
:aria-label="`${r.emoji} ${r.count}`"
|
||||
@click="emit('react', r.emoji)"
|
||||
><span class="ih:text-sm">{{ r.emoji }}</span>{{ r.count > 1 ? r.count : '' }}</button>
|
||||
</div>
|
||||
|
||||
<span class="ih:mt-0.5 ih:px-1 ih:text-[11px] ih:text-muted-foreground ih:tabular-nums">
|
||||
{{ messageTime(m.created_at) }}<template v-if="m.edited"> · bearbeitet</template><template v-if="m.mine && read"> · gelesen</template>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
84
resources/js/components/NewChatDialog.vue
Normal file
84
resources/js/components/NewChatDialog.vue
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { LoaderCircle } from '@lucide/vue';
|
||||
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Label, toast } from '@inhaus/ui';
|
||||
import PeopleSelect from './PeopleSelect.vue';
|
||||
import { api } from '../lib/api';
|
||||
|
||||
/** Neue Direktnachricht bzw. neue Gruppe */
|
||||
const props = defineProps({
|
||||
group: { type: Boolean, default: false },
|
||||
me: { type: Object, required: true },
|
||||
});
|
||||
const open = defineModel('open', { type: Boolean, default: false });
|
||||
const emit = defineEmits(['created']);
|
||||
|
||||
const name = ref('');
|
||||
const people = ref([]);
|
||||
const busy = ref(false);
|
||||
|
||||
watch(open, (value) => {
|
||||
if (value) {
|
||||
name.value = '';
|
||||
people.value = [];
|
||||
}
|
||||
});
|
||||
|
||||
async function start(person) {
|
||||
if (props.group) return;
|
||||
|
||||
busy.value = true;
|
||||
|
||||
try {
|
||||
const data = await api.direct(person.id);
|
||||
open.value = false;
|
||||
emit('created', data);
|
||||
} catch (error) {
|
||||
toast.error(error.message);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createGroup() {
|
||||
busy.value = true;
|
||||
|
||||
try {
|
||||
const data = await api.createGroup(name.value.trim(), people.value.map((p) => p.id));
|
||||
open.value = false;
|
||||
emit('created', data);
|
||||
} catch (error) {
|
||||
toast.error(error.message);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<DialogContent class="ih:sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ group ? 'Neue Gruppe' : 'Neue Nachricht' }}</DialogTitle>
|
||||
<DialogDescription>{{ group ? 'Name und Mitglieder wählen – Sie verwalten die Gruppe.' : 'An wen möchten Sie schreiben?' }}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div class="ih:grid ih:gap-4">
|
||||
<div v-if="group" class="ih:grid ih:gap-1.5">
|
||||
<Label for="chat-group-name">Name der Gruppe</Label>
|
||||
<Input id="chat-group-name" v-model="name" maxlength="100" placeholder="z. B. Station 3 – Frühdienst" />
|
||||
</div>
|
||||
<div class="ih:grid ih:gap-1.5">
|
||||
<Label v-if="group">Mitglieder</Label>
|
||||
<PeopleSelect v-model="people" :multiple="group" :exclude="[me.id]" autofocus @pick="start" />
|
||||
</div>
|
||||
<p v-if="busy && !group" class="ih:flex ih:items-center ih:gap-2 ih:text-sm ih:text-muted-foreground"><LoaderCircle class="ih:size-4 ih:animate-spin" /> Gespräch wird geöffnet …</p>
|
||||
</div>
|
||||
<DialogFooter v-if="group">
|
||||
<Button variant="ghost" @click="open = false">Abbrechen</Button>
|
||||
<Button :disabled="busy || !name.trim() || !people.length" @click="createGroup">
|
||||
<LoaderCircle v-if="busy" class="ih:animate-spin" /> Gruppe erstellen
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
98
resources/js/components/PeopleSelect.vue
Normal file
98
resources/js/components/PeopleSelect.vue
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { Search, X } from '@lucide/vue';
|
||||
import { PersonAvatar } from '@inhaus/ui';
|
||||
import { api } from '../lib/api';
|
||||
|
||||
/**
|
||||
* Personen suchen und auswählen – einzeln (Direktnachricht) oder mehrere (Gruppe).
|
||||
* v-model: Liste der Personen [{ id, name, … }]
|
||||
*/
|
||||
const props = defineProps({
|
||||
multiple: { type: Boolean, default: false },
|
||||
exclude: { type: Array, default: () => [] },
|
||||
placeholder: { type: String, default: 'Name oder E-Mail eingeben …' },
|
||||
autofocus: { type: Boolean, default: false },
|
||||
});
|
||||
const emit = defineEmits(['pick']);
|
||||
const selected = defineModel({ type: Array, default: () => [] });
|
||||
|
||||
const query = ref('');
|
||||
const results = ref([]);
|
||||
const active = ref(0);
|
||||
const loading = ref(false);
|
||||
let timer;
|
||||
|
||||
watch(query, (value) => {
|
||||
clearTimeout(timer);
|
||||
|
||||
if (value.trim().length < 2) {
|
||||
results.value = [];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
timer = setTimeout(async () => {
|
||||
loading.value = true;
|
||||
|
||||
try {
|
||||
const ids = [...props.exclude, ...selected.value.map((p) => p.id)];
|
||||
results.value = (await api.people(value.trim())).people.filter((p) => !ids.includes(p.id));
|
||||
active.value = 0;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
|
||||
function choose(person) {
|
||||
if (!person) return;
|
||||
|
||||
emit('pick', person);
|
||||
|
||||
if (props.multiple) selected.value = [...selected.value, person];
|
||||
query.value = '';
|
||||
results.value = [];
|
||||
}
|
||||
|
||||
const remove = (person) => (selected.value = selected.value.filter((p) => p.id !== person.id));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="ih:grid ih:gap-2">
|
||||
<div v-if="multiple && selected.length" class="ih:flex ih:flex-wrap ih:gap-1.5">
|
||||
<span v-for="person in selected" :key="person.id" class="ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-full ih:border ih:bg-card ih:py-0.5 ih:pr-1 ih:pl-0.5 ih:text-[13px]">
|
||||
<PersonAvatar :person="person" class="ih:size-6 ih:text-[10px]" />
|
||||
{{ person.name }}
|
||||
<button type="button" class="ih:rounded-full ih:p-0.5 ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground" :aria-label="`${person.name} entfernen`" @click="remove(person)"><X class="ih:size-3.5" /></button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="ih:relative">
|
||||
<Search class="ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground" />
|
||||
<input
|
||||
v-model="query"
|
||||
type="search"
|
||||
autocomplete="off"
|
||||
:autofocus="autofocus"
|
||||
:placeholder="placeholder"
|
||||
aria-label="Person suchen"
|
||||
class="ih:h-10 ih:w-full ih:rounded-md ih:border ih:border-input ih:bg-card ih:pr-3 ih:pl-8 ih:text-sm ih:shadow-xs ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none"
|
||||
@keydown.down.prevent="active = Math.min(results.length - 1, active + 1)"
|
||||
@keydown.up.prevent="active = Math.max(0, active - 1)"
|
||||
@keydown.enter.prevent="choose(results[active])"
|
||||
/>
|
||||
</div>
|
||||
<ul v-if="results.length" class="ih:max-h-64 ih:overflow-y-auto ih:rounded-md ih:border ih:bg-popover ih:p-1" role="listbox">
|
||||
<li v-for="(person, i) in results" :key="person.id" role="option" :aria-selected="i === active">
|
||||
<button type="button" class="ih:flex ih:w-full ih:items-center ih:gap-2.5 ih:rounded ih:px-2 ih:py-1.5 ih:text-left ih:text-sm" :class="i === active ? 'ih:bg-accent' : 'ih:hover:bg-accent/60'" @click="choose(person)" @mouseenter="active = i">
|
||||
<PersonAvatar :person="person" class="ih:size-7 ih:text-[11px]" />
|
||||
<span class="ih:min-w-0 ih:flex-1">
|
||||
<span class="ih:block ih:truncate ih:font-medium">{{ person.name }}</span>
|
||||
<span v-if="person.job_title || person.department" class="ih:block ih:truncate ih:text-xs ih:text-muted-foreground">{{ [person.job_title, person.department].filter(Boolean).join(' · ') }}</span>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else-if="query.trim().length >= 2 && !loading" class="ih:px-1 ih:text-[13px] ih:text-muted-foreground">Niemand gefunden.</p>
|
||||
</div>
|
||||
</template>
|
||||
25
resources/js/components/Popup.vue
Normal file
25
resources/js/components/Popup.vue
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
|
||||
/** Kleines Aufklapp-Fenster über der Eingabezeile; schließt bei Klick daneben und mit Esc */
|
||||
const emit = defineEmits(['close']);
|
||||
const root = ref(null);
|
||||
|
||||
const outside = (event) => root.value && !root.value.contains(event.target) && !event.target.closest?.('[data-popup-toggle]') && emit('close');
|
||||
const escape = (event) => event.key === 'Escape' && emit('close');
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('pointerdown', outside);
|
||||
document.addEventListener('keydown', escape);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('pointerdown', outside);
|
||||
document.removeEventListener('keydown', escape);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="root" class="ih:absolute ih:bottom-full ih:left-0 ih:z-30 ih:mb-2 ih:w-[min(22rem,calc(100vw-2rem))] ih:overflow-hidden ih:rounded-lg ih:border ih:bg-popover ih:text-popover-foreground ih:shadow-lg" role="dialog">
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
308
resources/js/components/Thread.vue
Normal file
308
resources/js/components/Thread.vue
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
<script setup>
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
import { ArrowDown, ArrowLeft, BellOff, Info, LoaderCircle, Upload } from '@lucide/vue';
|
||||
import { toast } from '@inhaus/ui';
|
||||
import ChatAvatar from './ChatAvatar.vue';
|
||||
import Composer from './Composer.vue';
|
||||
import MessageBubble from './MessageBubble.vue';
|
||||
import { api } from '../lib/api';
|
||||
import { dayLabel, sameDay } from '../lib/format';
|
||||
|
||||
const props = defineProps({
|
||||
conversation: { type: Object, required: true },
|
||||
me: { type: Object, required: true },
|
||||
reactions: { type: Array, required: true },
|
||||
maxUploadMb: { type: Number, default: 25 },
|
||||
typing: { type: Array, default: () => [] },
|
||||
});
|
||||
const emit = defineEmits(['back', 'info', 'changed', 'read']);
|
||||
|
||||
const messages = ref([]);
|
||||
const more = ref(false);
|
||||
const loading = ref(true);
|
||||
const loadingOlder = ref(false);
|
||||
const sending = ref(false);
|
||||
const replyTo = ref(null);
|
||||
const editing = ref(null);
|
||||
const scroller = ref(null);
|
||||
const composer = ref(null);
|
||||
const atBottom = ref(true);
|
||||
const newBelow = ref(0);
|
||||
const dragging = ref(false);
|
||||
// Erste ungelesene Nachricht beim Öffnen – dort steht der Trenner „Neu“
|
||||
const firstUnreadId = ref(null);
|
||||
|
||||
const isGroup = computed(() => props.conversation.type === 'group');
|
||||
const lastId = () => messages.value.at(-1)?.id ?? 0;
|
||||
const lastOwnId = computed(() => [...messages.value].reverse().find((m) => m.mine && !m.deleted && m.kind !== 'system')?.id);
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
messages.value = [];
|
||||
replyTo.value = editing.value = null;
|
||||
|
||||
try {
|
||||
const data = await api.messages(props.conversation.id);
|
||||
messages.value = data.messages;
|
||||
more.value = data.more;
|
||||
const readId = props.conversation.last_read_id ?? 0;
|
||||
firstUnreadId.value = props.conversation.unread ? data.messages.find((m) => m.id > readId && !m.mine && m.kind !== 'system')?.id ?? null : null;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
await nextTick();
|
||||
scrollTo(firstUnreadId.value ? document.getElementById(`nachricht-${firstUnreadId.value}`) : null);
|
||||
markRead();
|
||||
composer.value?.focus();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOlder() {
|
||||
if (!more.value || loadingOlder.value || !messages.value.length) return;
|
||||
|
||||
loadingOlder.value = true;
|
||||
const el = scroller.value;
|
||||
const before = el.scrollHeight;
|
||||
|
||||
try {
|
||||
const data = await api.messages(props.conversation.id, messages.value[0].id);
|
||||
messages.value = [...data.messages, ...messages.value];
|
||||
more.value = data.more;
|
||||
await nextTick();
|
||||
el.scrollTop = el.scrollHeight - before; // Position halten
|
||||
} finally {
|
||||
loadingOlder.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function scrollTo(element) {
|
||||
const el = scroller.value;
|
||||
|
||||
if (!el) return;
|
||||
|
||||
element ? element.scrollIntoView({ block: 'center' }) : (el.scrollTop = el.scrollHeight);
|
||||
newBelow.value = 0;
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
const el = scroller.value;
|
||||
atBottom.value = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
|
||||
|
||||
if (atBottom.value) {
|
||||
newBelow.value = 0;
|
||||
markRead();
|
||||
}
|
||||
|
||||
if (el.scrollTop < 120) loadOlder();
|
||||
}
|
||||
|
||||
let readTimer;
|
||||
function markRead() {
|
||||
clearTimeout(readTimer);
|
||||
readTimer = setTimeout(async () => {
|
||||
const last = [...messages.value].reverse().find((m) => !m.mine);
|
||||
|
||||
if (!last || document.visibilityState !== 'visible' || !atBottom.value || !props.conversation.unread) return;
|
||||
|
||||
const data = await api.read(props.conversation.id, lastId());
|
||||
emit('read', { id: props.conversation.id, unread: data.unread });
|
||||
}, 400);
|
||||
}
|
||||
|
||||
/** Neue bzw. geänderte Nachrichten aus der Abfrage einarbeiten */
|
||||
async function merge(incoming) {
|
||||
const mine = incoming.filter((m) => m.conversation_id === props.conversation.id);
|
||||
|
||||
if (!mine.length) return;
|
||||
|
||||
const byId = new Map(messages.value.map((m) => [m.id, m]));
|
||||
let added = 0;
|
||||
|
||||
for (const message of mine) {
|
||||
if (byId.has(message.id)) Object.assign(byId.get(message.id), message);
|
||||
else if (message.id > lastId()) {
|
||||
messages.value.push(message);
|
||||
added += message.mine ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added) return;
|
||||
|
||||
const stick = atBottom.value;
|
||||
await nextTick();
|
||||
|
||||
if (stick) {
|
||||
scrollTo();
|
||||
markRead();
|
||||
} else {
|
||||
newBelow.value += added;
|
||||
}
|
||||
}
|
||||
|
||||
async function send(payload) {
|
||||
sending.value = true;
|
||||
|
||||
try {
|
||||
const { message } = await api.send(props.conversation.id, { ...payload, replyTo: replyTo.value?.id });
|
||||
replyTo.value = null;
|
||||
|
||||
if (!messages.value.some((m) => m.id === message.id)) messages.value.push(message);
|
||||
await nextTick();
|
||||
scrollTo();
|
||||
emit('changed');
|
||||
} catch (error) {
|
||||
toast.error(error.message);
|
||||
} finally {
|
||||
sending.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveEdit(body) {
|
||||
const message = editing.value;
|
||||
|
||||
try {
|
||||
await api.edit(message.id, body);
|
||||
Object.assign(message, { body, edited: true });
|
||||
editing.value = null;
|
||||
} catch (error) {
|
||||
toast.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(message) {
|
||||
if (!window.confirm('Nachricht für alle löschen?')) return;
|
||||
|
||||
await api.remove(message.id);
|
||||
Object.assign(message, { deleted: true, body: null, gif_url: null, attachments: [], reactions: [] });
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
async function react(message, emoji) {
|
||||
// Sofort anzeigen, der Server bestätigt mit der nächsten Abfrage
|
||||
const existing = message.reactions.find((r) => r.emoji === emoji);
|
||||
|
||||
if (existing?.mine) {
|
||||
existing.count--;
|
||||
existing.mine = false;
|
||||
message.reactions = message.reactions.filter((r) => r.count > 0);
|
||||
} else if (existing) {
|
||||
existing.count++;
|
||||
existing.mine = true;
|
||||
} else {
|
||||
message.reactions.push({ emoji, count: 1, mine: true });
|
||||
}
|
||||
|
||||
await api.react(message.id, emoji).catch((error) => toast.error(error.message));
|
||||
}
|
||||
|
||||
function jump(id) {
|
||||
const element = document.getElementById(`nachricht-${id}`);
|
||||
|
||||
if (element) {
|
||||
element.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||||
element.classList.add('ih:animate-pulse');
|
||||
setTimeout(() => element.classList.remove('ih:animate-pulse'), 1500);
|
||||
}
|
||||
}
|
||||
|
||||
function onDrop(event) {
|
||||
dragging.value = false;
|
||||
const files = [...(event.dataTransfer?.files ?? [])];
|
||||
files.length && composer.value?.addFiles(files);
|
||||
}
|
||||
|
||||
const showAuthor = (m, i) => {
|
||||
const prev = messages.value[i - 1];
|
||||
|
||||
return !prev || prev.kind === 'system' || prev.user?.id !== m.user?.id || !sameDay(prev.created_at, m.created_at) || new Date(m.created_at) - new Date(prev.created_at) > 5 * 60000;
|
||||
};
|
||||
const showAvatar = (m, i) => {
|
||||
const next = messages.value[i + 1];
|
||||
|
||||
return !next || next.kind === 'system' || next.user?.id !== m.user?.id || !sameDay(next.created_at, m.created_at);
|
||||
};
|
||||
|
||||
const subtitle = computed(() => {
|
||||
if (props.typing.length) return `${props.typing.join(', ')} ${props.typing.length === 1 ? 'schreibt' : 'schreiben'} …`;
|
||||
if (isGroup.value) return props.conversation.members.map((m) => m.first_name || m.name).join(', ');
|
||||
|
||||
return props.conversation.person?.job_title ?? '';
|
||||
});
|
||||
|
||||
watch(() => props.conversation.id, load);
|
||||
onMounted(load);
|
||||
|
||||
defineExpose({ merge, lastId });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
class="ih:relative ih:flex ih:h-full ih:min-h-0 ih:flex-col"
|
||||
:aria-label="`Gespräch mit ${conversation.name}`"
|
||||
@dragover.prevent="dragging = true"
|
||||
@dragleave.self="dragging = false"
|
||||
@drop.prevent="onDrop"
|
||||
>
|
||||
<header class="ih:flex ih:items-center ih:gap-3 ih:border-b ih:px-3 ih:py-2.5">
|
||||
<button type="button" class="ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:hover:bg-accent ih:lg:hidden" aria-label="Zurück zur Übersicht" @click="emit('back')"><ArrowLeft class="ih:size-5" /></button>
|
||||
<ChatAvatar :conversation="conversation" />
|
||||
<div class="ih:min-w-0 ih:flex-1">
|
||||
<h2 class="ih:flex ih:items-center ih:gap-1.5 ih:truncate ih:font-semibold">
|
||||
<a v-if="conversation.person" :href="`/personen/${conversation.person.id}`" class="ih:truncate ih:hover:underline">{{ conversation.name }}</a>
|
||||
<span v-else class="ih:truncate">{{ conversation.name }}</span>
|
||||
<BellOff v-if="conversation.muted" class="ih:size-3.5 ih:shrink-0 ih:text-muted-foreground" aria-label="Stummgeschaltet" />
|
||||
</h2>
|
||||
<p class="ih:truncate ih:text-xs" :class="typing.length ? 'ih:text-brand-text' : 'ih:text-muted-foreground'" aria-live="polite">{{ subtitle }}</p>
|
||||
</div>
|
||||
<button type="button" class="ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:hover:bg-accent" :aria-label="isGroup ? 'Gruppe: Mitglieder und Einstellungen' : 'Einstellungen zum Gespräch'" @click="emit('info')"><Info class="ih:size-5" /></button>
|
||||
</header>
|
||||
|
||||
<div ref="scroller" class="ih:min-h-0 ih:flex-1 ih:overflow-y-auto ih:bg-muted/30 ih:px-3 ih:py-4 ih:sm:px-5" role="log" aria-live="polite" aria-relevant="additions" @scroll.passive="onScroll">
|
||||
<div v-if="loading" class="ih:grid ih:h-full ih:place-items-center"><LoaderCircle class="ih:size-6 ih:animate-spin ih:text-muted-foreground" /></div>
|
||||
<template v-else>
|
||||
<div v-if="loadingOlder" class="ih:flex ih:justify-center ih:py-2"><LoaderCircle class="ih:size-4 ih:animate-spin ih:text-muted-foreground" /></div>
|
||||
<p v-if="!messages.length" class="ih:py-10 ih:text-center ih:text-sm ih:text-muted-foreground">Schreiben Sie die erste Nachricht.</p>
|
||||
<template v-for="(m, i) in messages" :key="m.id">
|
||||
<div v-if="i === 0 || !sameDay(messages[i - 1].created_at, m.created_at)" class="ih:my-4 ih:flex ih:justify-center">
|
||||
<span class="ih:rounded-full ih:bg-card ih:px-3 ih:py-1 ih:text-xs ih:font-medium ih:text-muted-foreground ih:shadow-xs">{{ dayLabel(m.created_at) }}</span>
|
||||
</div>
|
||||
<div v-if="m.id === firstUnreadId" class="ih:my-3 ih:flex ih:items-center ih:gap-3 ih:text-xs ih:font-semibold ih:text-brand-text">
|
||||
<span class="ih:h-px ih:flex-1 ih:bg-brand/40" />Neu<span class="ih:h-px ih:flex-1 ih:bg-brand/40" />
|
||||
</div>
|
||||
<MessageBubble
|
||||
:message="m"
|
||||
:group="isGroup"
|
||||
:show-author="showAuthor(m, i)"
|
||||
:show-avatar="showAvatar(m, i)"
|
||||
:reactions="reactions"
|
||||
:read="m.id === lastOwnId && !!conversation.others_read_id && conversation.others_read_id >= m.id"
|
||||
@react="react(m, $event)"
|
||||
@reply="replyTo = m; editing = null"
|
||||
@edit="editing = m; replyTo = null"
|
||||
@delete="remove(m)"
|
||||
@jump="jump"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<button v-if="newBelow" type="button" class="ih:absolute ih:bottom-28 ih:left-1/2 ih:z-10 ih:flex ih:-translate-x-1/2 ih:items-center ih:gap-1.5 ih:rounded-full ih:bg-brand ih:px-3 ih:py-1.5 ih:text-xs ih:font-medium ih:text-brand-foreground ih:shadow-lg" @click="scrollTo(); markRead()">
|
||||
<ArrowDown class="ih:size-3.5" /> {{ newBelow }} {{ newBelow === 1 ? 'neue Nachricht' : 'neue Nachrichten' }}
|
||||
</button>
|
||||
|
||||
<Composer
|
||||
ref="composer"
|
||||
:reply-to="replyTo"
|
||||
:editing="editing"
|
||||
:sending="sending"
|
||||
:max-upload-mb="maxUploadMb"
|
||||
@send="send"
|
||||
@save-edit="saveEdit"
|
||||
@cancel="replyTo = null; editing = null"
|
||||
@typing="api.typing(conversation.id).catch(() => {})"
|
||||
/>
|
||||
|
||||
<div v-if="dragging" class="ih:pointer-events-none ih:absolute ih:inset-2 ih:z-20 ih:grid ih:place-items-center ih:rounded-xl ih:border-2 ih:border-dashed ih:border-brand ih:bg-brand-soft/80 ih:text-brand-text">
|
||||
<span class="ih:flex ih:items-center ih:gap-2 ih:font-medium"><Upload class="ih:size-5" /> Dateien hier ablegen</span>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
37
resources/js/header/Unread.vue
Normal file
37
resources/js/header/Unread.vue
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { MessageCircle } from '@lucide/vue';
|
||||
import { http } from '@inhaus/ui';
|
||||
|
||||
/**
|
||||
* Sprechblase neben der Glocke: Zahl der ungelesenen Nachrichten. Auf der Chat-Seite meldet
|
||||
* der Chat selbst, sonst wird alle 30 Sekunden nachgefragt.
|
||||
*/
|
||||
const props = defineProps({ unread: { type: Number, default: 0 } });
|
||||
const count = ref(props.unread);
|
||||
let timer;
|
||||
|
||||
const update = (event) => (count.value = event.detail);
|
||||
|
||||
async function poll() {
|
||||
if (document.visibilityState === 'visible' && !location.pathname.startsWith('/chat')) {
|
||||
count.value = (await http.get('/chat/api/ungelesen').catch(() => ({ unread: count.value }))).unread;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('inhaus-chat:unread', update);
|
||||
timer = setInterval(poll, 30000);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('inhaus-chat:unread', update);
|
||||
clearInterval(timer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a href="/chat" class="ih:relative ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:transition-colors ih:hover:bg-accent ih:hover:text-foreground" :aria-label="count ? `Nachrichten, ${count} ungelesen` : 'Nachrichten'" :title="count ? `${count} ungelesene Nachrichten` : 'Nachrichten'">
|
||||
<MessageCircle class="ih:size-5" />
|
||||
<span v-if="count" class="ih:absolute ih:top-0.5 ih:right-0.5 ih:grid ih:h-4 ih:min-w-4 ih:place-items-center ih:rounded-full ih:bg-brand ih:px-1 ih:text-[10px] ih:font-semibold ih:text-brand-foreground ih:tabular-nums" aria-hidden="true">{{ count > 99 ? '99+' : count }}</span>
|
||||
</a>
|
||||
</template>
|
||||
40
resources/js/lib/api.js
Normal file
40
resources/js/lib/api.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { http } from '@inhaus/ui';
|
||||
|
||||
/** JSON-Schnittstelle der Chat-Oberfläche (routes/web.php, Präfix /chat/api) */
|
||||
const base = '/chat/api';
|
||||
|
||||
export const api = {
|
||||
conversations: () => http.get(`${base}/gespraeche`),
|
||||
direct: (userId) => http.post(`${base}/direkt`, { user_id: userId }),
|
||||
createGroup: (name, members) => http.post(`${base}/gruppen`, { name, members }),
|
||||
updateConversation: (id, data) => http.put(`${base}/gespraeche/${id}`, data),
|
||||
leave: (id) => http.delete(`${base}/gespraeche/${id}`),
|
||||
addMembers: (id, members) => http.post(`${base}/gespraeche/${id}/mitglieder`, { members }),
|
||||
removeMember: (id, userId) => http.delete(`${base}/gespraeche/${id}/mitglieder/${userId}`),
|
||||
setAdmin: (id, userId, admin) => http.put(`${base}/gespraeche/${id}/mitglieder/${userId}`, { admin }),
|
||||
|
||||
messages: (id, before) => http.get(`${base}/gespraeche/${id}/nachrichten${before ? `?vor=${before}` : ''}`),
|
||||
send(id, { body, gifUrl, replyTo, files }) {
|
||||
const data = new FormData();
|
||||
if (body) data.append('body', body);
|
||||
if (gifUrl) data.append('gif_url', gifUrl);
|
||||
if (replyTo) data.append('reply_to', replyTo);
|
||||
(files ?? []).forEach((file) => data.append('files[]', file));
|
||||
|
||||
return http.post(`${base}/gespraeche/${id}/nachrichten`, data);
|
||||
},
|
||||
edit: (messageId, body) => http.put(`${base}/nachrichten/${messageId}`, { body }),
|
||||
remove: (messageId) => http.delete(`${base}/nachrichten/${messageId}`),
|
||||
react: (messageId, emoji) => http.post(`${base}/nachrichten/${messageId}/reaktion`, { emoji }),
|
||||
read: (id, messageId) => http.post(`${base}/gespraeche/${id}/gelesen`, { message_id: messageId }),
|
||||
typing: (id) => http.post(`${base}/gespraeche/${id}/tippt`),
|
||||
updates: (params) => http.get(`${base}/neues?${new URLSearchParams(Object.entries(params).filter(([, v]) => v !== null && v !== undefined))}`),
|
||||
unread: () => http.get(`${base}/ungelesen`),
|
||||
gifs: (q) => http.get(`${base}/gifs?q=${encodeURIComponent(q ?? '')}`),
|
||||
people: (q) => http.get(`/personen/suche?q=${encodeURIComponent(q)}`),
|
||||
};
|
||||
|
||||
/** Ungelesene an das Symbol in der Kopfzeile melden */
|
||||
export function announceUnread(count) {
|
||||
window.dispatchEvent(new CustomEvent('inhaus-chat:unread', { detail: count }));
|
||||
}
|
||||
11
resources/js/lib/emojis.js
Normal file
11
resources/js/lib/emojis.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/** Emoji-Auswahl (Unicode) – kompakt, ohne externe Bibliothek */
|
||||
export const EMOJI_GROUPS = [
|
||||
{ label: 'Smileys', icon: '😀', emojis: '😀 😃 😄 😁 😆 😅 🤣 😂 🙂 🙃 😉 😊 😇 🥰 😍 🤩 😘 😗 😚 😋 😛 😜 🤪 😝 🤗 🤭 🤫 🤔 🤐 🤨 😐 😑 😶 😏 😒 🙄 😬 😌 😔 😪 😴 😷 🤒 🤕 🤢 🤧 🥵 🥶 🥴 😵 🤯 🤠 🥳 😎 🤓 🧐 😕 😟 🙁 😮 😯 😲 😳 🥺 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 🥱 😤 😡 😠 🤬'.split(' ') },
|
||||
{ label: 'Gesten', icon: '👍', emojis: '👍 👎 👌 🤌 ✌️ 🤞 🤟 🤘 🤙 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐️ 🖖 👋 👏 🙌 👐 🤲 🤝 🙏 ✍️ 💪 🦾 👀 🧠 🫶 ❤️ 🧡 💛 💚 💙 💜 🖤 🤍 🤎 💔 ❣️ 💕 💞 💓 💗 💖 💘 💯 ✨ ⭐ 🌟 💥 🔥 🎉 🎊'.split(' ') },
|
||||
{ label: 'Menschen', icon: '🧑', emojis: '👶 🧒 👦 👧 🧑 👱 👨 🧔 👩 🧓 👴 👵 🙋 🙆 🙅 🤷 🤦 🙇 💁 🧑⚕️ 🧑🍳 🧑🔧 🧑🏫 🧑💻 🧑💼 🧑🔬 🧑🎨 🧑🚒 👮 🕵️ 💂 👷 🤴 👸 🧙 🧚 🦸 🏃 🚶 🧘 🏋️ 🚴 🤸 👯 💃 🕺 👪 🧑🤝🧑'.split(' ') },
|
||||
{ label: 'Natur', icon: '🌿', emojis: '🐶 🐱 🐭 🐹 🐰 🦊 🐻 🐼 🐨 🐯 🦁 🐮 🐷 🐸 🐵 🐔 🐧 🐦 🦆 🦉 🐴 🦄 🐝 🐞 🦋 🐢 🐍 🐙 🐠 🐬 🐳 🌵 🎄 🌲 🌳 🌴 🌱 🌿 🍀 🍁 🍂 🌷 🌹 🌻 🌼 🌸 🌞 🌝 🌙 ⭐ ☀️ 🌤️ ⛅ 🌧️ ⛈️ ❄️ ☃️ 🌈 🌊'.split(' ') },
|
||||
{ label: 'Essen', icon: '🍕', emojis: '🍏 🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🫐 🍒 🍑 🥭 🍍 🥥 🥝 🍅 🥑 🥦 🥕 🌽 🥔 🥐 🥖 🥨 🧀 🥚 🍳 🥞 🥓 🍔 🍟 🍕 🌭 🥪 🌮 🥗 🍝 🍜 🍲 🍣 🍰 🎂 🧁 🍩 🍪 🍫 🍬 🍭 🍦 ☕ 🍵 🧃 🥤 🍺 🍻 🥂 🍷'.split(' ') },
|
||||
{ label: 'Aktivitäten', icon: '⚽', emojis: '⚽ 🏀 🏈 ⚾ 🎾 🏐 🏓 🏸 🥅 ⛳ 🎣 🎽 🎿 ⛸️ 🥇 🥈 🥉 🏆 🏅 🎗️ 🎫 🎟️ 🎭 🎨 🎬 🎤 🎧 🎼 🎹 🥁 🎷 🎺 🎸 🎻 🎲 🧩 🎯 🎳 🎮 🎰'.split(' ') },
|
||||
{ label: 'Dinge', icon: '💡', emojis: '⌚ 📱 💻 ⌨️ 🖥️ 🖨️ 🖱️ 💾 📷 📞 ☎️ 📺 ⏰ ⏳ 💡 🔦 🕯️ 💰 💳 🧾 ✉️ 📧 📨 📦 📝 📁 📂 📅 📆 📌 📎 ✂️ 🔒 🔑 🔨 🛠️ 🧰 🩺 💊 💉 🩹 🧯 🛒 🎁 🎈 🏠 🏥 🏫 🚗 🚌 🚲 ✈️ 🚀 🕐'.split(' ') },
|
||||
{ label: 'Symbole', icon: '✅', emojis: '✅ ☑️ ✔️ ❌ ❎ ➕ ➖ ❓ ❗ ‼️ ⁉️ 💤 ⚠️ 🚫 ⛔ 🔴 🟠 🟡 🟢 🔵 🟣 ⚫ ⚪ 🔶 🔷 ▶️ ⏸️ ⏹️ 🔄 🔁 🆗 🆕 🆒 🆘 ℹ️ 🔔 🔕 📣 💬 💭 🗯️ ♻️ ⬆️ ⬇️ ⬅️ ➡️'.split(' ') },
|
||||
];
|
||||
62
resources/js/lib/format.js
Normal file
62
resources/js/lib/format.js
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
const time = new Intl.DateTimeFormat('de-DE', { hour: '2-digit', minute: '2-digit' });
|
||||
const weekday = new Intl.DateTimeFormat('de-DE', { weekday: 'short' });
|
||||
const short = new Intl.DateTimeFormat('de-DE', { day: '2-digit', month: '2-digit', year: '2-digit' });
|
||||
const long = new Intl.DateTimeFormat('de-DE', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' });
|
||||
|
||||
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
||||
|
||||
/** Zeit in der Gesprächsliste: heute Uhrzeit, diese Woche Wochentag, sonst Datum */
|
||||
export function listTime(iso) {
|
||||
if (!iso) return '';
|
||||
|
||||
const date = new Date(iso);
|
||||
const days = (startOfDay(new Date()) - startOfDay(date)) / 86400000;
|
||||
|
||||
if (days === 0) return time.format(date);
|
||||
if (days === 1) return 'Gestern';
|
||||
if (days < 7) return weekday.format(date);
|
||||
|
||||
return short.format(date);
|
||||
}
|
||||
|
||||
export const messageTime = (iso) => time.format(new Date(iso));
|
||||
|
||||
/** Trenner zwischen Tagen im Verlauf */
|
||||
export function dayLabel(iso) {
|
||||
const date = new Date(iso);
|
||||
const days = (startOfDay(new Date()) - startOfDay(date)) / 86400000;
|
||||
|
||||
if (days === 0) return 'Heute';
|
||||
if (days === 1) return 'Gestern';
|
||||
|
||||
return long.format(date);
|
||||
}
|
||||
|
||||
export const sameDay = (a, b) => startOfDay(new Date(a)) === startOfDay(new Date(b));
|
||||
|
||||
export function fileSize(bytes) {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
|
||||
|
||||
return `${(bytes / 1024 / 1024).toFixed(1).replace('.', ',')} MB`;
|
||||
}
|
||||
|
||||
/** Text in Stücke zerlegen, Links erkennen – ohne v-html */
|
||||
export function linkify(text) {
|
||||
const parts = [];
|
||||
const pattern = /(https?:\/\/[^\s<>"']+[^\s<>"'.,;:!?)\]])/g;
|
||||
let last = 0;
|
||||
|
||||
for (const match of text.matchAll(pattern)) {
|
||||
if (match.index > last) parts.push({ text: text.slice(last, match.index) });
|
||||
parts.push({ text: match[0], href: match[0] });
|
||||
last = match.index + match[0].length;
|
||||
}
|
||||
|
||||
if (last < text.length) parts.push({ text: text.slice(last) });
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
/** Nur Emojis (bis zu 3)? Dann groß darstellen */
|
||||
export const onlyEmoji = (text) => !!text && /^(\p{Extended_Pictographic}|\p{Emoji_Component}||️|\s){1,12}$/u.test(text) && [...text.replace(/\s/g, '')].length <= 8;
|
||||
78
resources/js/lib/sync.js
Normal file
78
resources/js/lib/sync.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import { api } from './api';
|
||||
|
||||
/**
|
||||
* Hält den Chat aktuell: fragt regelmäßig nach („Gibt es Neues?“) – häufig, solange die Seite
|
||||
* sichtbar ist, selten im Hintergrund. Ist Echtzeit eingerichtet, löst ein Signal des
|
||||
* Pusher-kompatiblen Dienstes die Abfrage sofort aus; das Nachfragen läuft dann nur noch als Rückfall.
|
||||
*/
|
||||
export function createSync({ realtime, userId, openId, lastId, onUpdate }) {
|
||||
let cursor = null;
|
||||
let timer = null;
|
||||
let running = false;
|
||||
let stopped = false;
|
||||
let socket = null;
|
||||
|
||||
const interval = () => {
|
||||
const visible = document.visibilityState === 'visible';
|
||||
|
||||
if (socket?.connection?.state === 'connected') return visible ? 20000 : 60000;
|
||||
|
||||
return visible ? (document.hasFocus() ? 3000 : 6000) : 30000;
|
||||
};
|
||||
|
||||
async function tick() {
|
||||
if (running || stopped) return;
|
||||
|
||||
running = true;
|
||||
clearTimeout(timer);
|
||||
|
||||
try {
|
||||
const data = await api.updates({ seit: cursor, offen: openId(), nach: lastId() });
|
||||
cursor = data.cursor;
|
||||
onUpdate(data);
|
||||
} catch {
|
||||
// Netzwerk kurz weg – nächster Versuch folgt
|
||||
} finally {
|
||||
running = false;
|
||||
|
||||
if (!stopped) timer = setTimeout(tick, interval());
|
||||
}
|
||||
}
|
||||
|
||||
const wake = () => document.visibilityState === 'visible' && tick();
|
||||
document.addEventListener('visibilitychange', wake);
|
||||
window.addEventListener('focus', wake);
|
||||
|
||||
if (realtime) {
|
||||
import('pusher-js').then(({ default: Pusher }) => {
|
||||
if (stopped) return;
|
||||
|
||||
socket = new Pusher(realtime.key, {
|
||||
cluster: realtime.cluster,
|
||||
...(realtime.host ? { wsHost: realtime.host, wsPort: realtime.port, wssPort: realtime.port, forceTLS: realtime.tls, enabledTransports: ['ws', 'wss'] } : {}),
|
||||
channelAuthorization: {
|
||||
endpoint: '/chat/api/echtzeit/anmelden',
|
||||
headers: { 'X-XSRF-TOKEN': decodeURIComponent(document.cookie.match(/(?:^|; )XSRF-TOKEN=([^;]*)/)?.[1] ?? ''), Accept: 'application/json' },
|
||||
},
|
||||
});
|
||||
socket.subscribe(`private-chat-user-${userId}`).bind('update', () => tick());
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
tick();
|
||||
|
||||
return {
|
||||
now: tick,
|
||||
reset() {
|
||||
cursor = null;
|
||||
tick();
|
||||
},
|
||||
stop() {
|
||||
stopped = true;
|
||||
clearTimeout(timer);
|
||||
document.removeEventListener('visibilitychange', wake);
|
||||
window.removeEventListener('focus', wake);
|
||||
socket?.disconnect();
|
||||
},
|
||||
};
|
||||
}
|
||||
127
resources/js/pages/Index.vue
Normal file
127
resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { MessagesSquare } from '@lucide/vue';
|
||||
import { AppLayout } from '@inhaus/ui';
|
||||
import ConversationInfo from '../components/ConversationInfo.vue';
|
||||
import ConversationList from '../components/ConversationList.vue';
|
||||
import NewChatDialog from '../components/NewChatDialog.vue';
|
||||
import Thread from '../components/Thread.vue';
|
||||
import { announceUnread, api } from '../lib/api';
|
||||
import { createSync } from '../lib/sync';
|
||||
|
||||
/**
|
||||
* Nachrichten: links die Gespräche, rechts der Verlauf. Auf dem Handy nacheinander.
|
||||
*/
|
||||
const props = defineProps({
|
||||
me: { type: Object, required: true },
|
||||
conversations: { type: Array, required: true },
|
||||
activeId: { type: Number, default: null },
|
||||
canCreateGroups: { type: Boolean, default: false },
|
||||
realtime: { type: Object, default: null },
|
||||
reactions: { type: Array, required: true },
|
||||
maxUploadMb: { type: Number, default: 25 },
|
||||
});
|
||||
|
||||
const list = ref(props.conversations);
|
||||
const activeId = ref(props.activeId);
|
||||
const typing = ref([]);
|
||||
const thread = ref(null);
|
||||
const dialog = ref(null); // 'chat' | 'group'
|
||||
const infoOpen = ref(false);
|
||||
|
||||
const active = computed(() => list.value.find((c) => c.id === activeId.value) ?? null);
|
||||
|
||||
function open(id, push = true) {
|
||||
activeId.value = id;
|
||||
typing.value = [];
|
||||
|
||||
if (push && location.pathname !== `/chat/${id ?? ''}`.replace(/\/$/, '')) {
|
||||
history.pushState({ chat: id }, '', id ? `/chat/${id}` : '/chat');
|
||||
}
|
||||
|
||||
sync?.now();
|
||||
}
|
||||
|
||||
const onPop = () => open(Number(location.pathname.split('/')[2]) || null, false);
|
||||
|
||||
function setList(conversations) {
|
||||
if (!conversations) return;
|
||||
|
||||
list.value = conversations;
|
||||
announceUnread(conversations.reduce((sum, c) => sum + (c.muted ? 0 : c.unread), 0));
|
||||
}
|
||||
|
||||
let sync = null;
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('popstate', onPop);
|
||||
sync = createSync({
|
||||
realtime: props.realtime,
|
||||
userId: props.me.id,
|
||||
openId: () => activeId.value,
|
||||
lastId: () => thread.value?.lastId() ?? 0,
|
||||
onUpdate(data) {
|
||||
setList(data.conversations);
|
||||
typing.value = data.typing ?? [];
|
||||
thread.value?.merge(data.messages ?? []);
|
||||
announceUnread(data.unread);
|
||||
},
|
||||
});
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('popstate', onPop);
|
||||
sync?.stop();
|
||||
});
|
||||
|
||||
function created(data) {
|
||||
setList(data.conversations);
|
||||
open(data.id);
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
setList((await api.conversations()).conversations);
|
||||
}
|
||||
|
||||
function onRead({ id, unread }) {
|
||||
const c = list.value.find((x) => x.id === id);
|
||||
|
||||
if (c) c.unread = 0;
|
||||
announceUnread(unread);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Nachrichten">
|
||||
<div class="ih:-mx-4 ih:-my-6 ih:flex ih:h-[calc(100dvh-4rem)] ih:overflow-hidden ih:border-y ih:bg-card ih:lg:mx-0 ih:lg:my-0 ih:lg:h-[calc(100dvh-8.5rem)] ih:lg:rounded-xl ih:lg:border ih:lg:shadow-xs">
|
||||
<aside class="ih:w-full ih:shrink-0 ih:border-r ih:lg:block ih:lg:w-80 ih:xl:w-96" :class="active ? 'ih:hidden' : 'ih:block'">
|
||||
<ConversationList :conversations="list" :active-id="activeId" :can-create-groups="canCreateGroups" @open="open" @new-chat="dialog = 'chat'" @new-group="dialog = 'group'" />
|
||||
</aside>
|
||||
|
||||
<main class="ih:min-w-0 ih:flex-1 ih:lg:block" :class="active ? 'ih:block' : 'ih:hidden'">
|
||||
<Thread
|
||||
v-if="active"
|
||||
ref="thread"
|
||||
:conversation="active"
|
||||
:me="me"
|
||||
:reactions="reactions"
|
||||
:typing="typing"
|
||||
:max-upload-mb="maxUploadMb"
|
||||
@back="open(null)"
|
||||
@info="infoOpen = true"
|
||||
@changed="refresh"
|
||||
@read="onRead"
|
||||
/>
|
||||
<div v-else class="ih:grid ih:h-full ih:place-items-center ih:p-8 ih:text-center">
|
||||
<div>
|
||||
<MessagesSquare class="ih:mx-auto ih:size-12 ih:text-muted-foreground/60" :stroke-width="1.5" />
|
||||
<p class="ih:mt-3 ih:font-medium">Wählen Sie ein Gespräch</p>
|
||||
<p class="ih:mt-1 ih:text-sm ih:text-muted-foreground">oder beginnen Sie eine neue Nachricht.</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<NewChatDialog :open="dialog !== null" :group="dialog === 'group'" :me="me" @update:open="(v) => !v && (dialog = null)" @created="created" />
|
||||
<ConversationInfo v-if="active" v-model:open="infoOpen" :conversation="active" :me="me" @updated="setList" @left="open(null)" />
|
||||
</AppLayout>
|
||||
</template>
|
||||
Loading…
Add table
Add a link
Reference in a new issue