@extends('layouts.app') @section('title', 'Messages - GSI Mobilier') @section('page-title', 'Messages') @section('page-description', 'Discussions privées et groupes') @section('content')
Conversations
Actualiser
@forelse($conversations as $c) @php $title = $c->type === 'group' ? ($c->title ?? ($c->building?->name ?? 'Groupe')) : 'Discussion privée'; $convPhotoUrl = !empty($c->photo_path) ? '/storage/'.ltrim($c->photo_path, '/') : null; @endphp
@if($convPhotoUrl) Photo @else
@endif
{{ $title }} @if($c->type === 'group') (Groupe) @endif
{{ $c->messages_count }} messages
#{{ $c->id }}
@empty
Aucune conversation
@endforelse
@if(auth()->user()->isManager())
Nouveau message
@csrf
@endif
@php $headerPhotoUrl = ($activeConversation && !empty($activeConversation->photo_path)) ? '/storage/'.ltrim($activeConversation->photo_path, '/') : null; $headerTitle = $activeConversation ? (($activeConversation->type === 'group') ? ($activeConversation->title ?? $activeConversation->building?->name ?? 'Groupe') : 'Discussion privée') : 'Sélectionne une conversation'; @endphp @if($headerPhotoUrl) Photo @else
@endif {{ $headerTitle }}
@if($activeConversation && $activeConversation->type === 'group' && auth()->user()->isManager()) @php $groupPhotoUrl = !empty($activeConversation->photo_path) ? '/storage/'.ltrim($activeConversation->photo_path, '/') : null; $groupTitle = $activeConversation->title ?? $activeConversation->building?->name ?? 'Groupe'; @endphp @endif
{{ $activeConversation ? $messages->count().' messages' : '' }}
@if(!$activeConversation)
Choisis une conversation à gauche.
@else @foreach($messages as $m) @php $mine = $m->user_id === auth()->id(); $uid = (int) ($m->user_id ?? 0); $hue = ($uid * 47) % 360; $avatarStyle = 'background:hsl('.$hue.',70%,45%);color:#fff;'; $name = $m->user?->name ?? 'Utilisateur'; $initials = collect(preg_split('/\s+/', trim($name)))->filter()->map(fn($p) => mb_substr($p, 0, 1))->take(2)->join(''); $isImage = $m->attachment_mime ? str_starts_with($m->attachment_mime, 'image/') : false; $attachmentUrl = $m->attachment_path ? '/storage/'.ltrim($m->attachment_path, '/') : null; $userAvatarUrl = !empty($m->user?->avatar_path) ? '/storage/'.ltrim($m->user->avatar_path, '/') : null; @endphp
@if(!$mine) @if($userAvatarUrl) Avatar @else
{{ strtoupper($initials) }}
@endif @endif
@if($mine) @endif
{{ $name }}
{{ $m->body }}
@if($attachmentUrl)
@if($isImage) {{ $m->attachment_name }} @elseif($m->attachment_mime && str_starts_with($m->attachment_mime, 'audio/'))
0:00
@else {{ $m->attachment_name ?? 'Document' }} @endif
@endif
{{ $m->created_at?->format('d/m/Y H:i') }}
@if($mine) @if($userAvatarUrl) Avatar @else
{{ strtoupper($initials) }}
@endif @endif
@endforeach @endif
@if($activeConversation)
@csrf
@endif
@endsection @push('scripts') @endpush