@php $navGuard = session('active_guard', 'web'); $navUser = auth($navGuard)->user(); $activeProfileUnreadCount = 0; if ($navUser) { $activeProfileUnreadCount = \Illuminate\Support\Facades\DB::table('wirechat_participants as p') ->join('wirechat_conversations as c', 'p.conversation_id', '=', 'c.id') ->where('p.participantable_id', $navUser->id) ->where('p.participantable_type', $navUser->getMorphClass()) ->whereNull('p.deleted_at') ->where(function ($q) { $q->whereNull('p.conversation_read_at') ->orWhereColumn('c.updated_at', '>', 'p.conversation_read_at'); }) ->whereExists(function ($q) use ($navUser) { $q->select(\Illuminate\Support\Facades\DB::raw(1)) ->from('wirechat_messages as m') ->whereColumn('m.conversation_id', 'p.conversation_id') ->whereNull('m.deleted_at') ->where(function ($q2) use ($navUser) { $q2->where('m.sendable_id', '!=', $navUser->id) ->orWhere('m.sendable_type', '!=', $navUser->getMorphClass()); }) ->where(function ($q3) { $q3->whereNull('p.conversation_read_at') ->orWhereColumn('m.created_at', '>', 'p.conversation_read_at'); }); }) ->count(); } // Check if any non-active profile (org/bank/admin) has unread messages // Used to initialize the hamburger dot before Livewire mounts SwitchProfileUnreadIndicator $switchProfileHasUnread = false; $webUser = auth('web')->user(); if ($webUser) { $activeProfileType = session('activeProfileType'); $activeProfileId = session('activeProfileId'); $userWithRelations = \App\Models\User::with(['organizations', 'banksManaged', 'admins'])->find($webUser->id); if ($userWithRelations) { $profilePairs = []; foreach ($userWithRelations->organizations->filter(fn($o) => !$o->deleted_at || $o->deleted_at > now()) as $org) { if (!($activeProfileType === 'App\\Models\\Organization' && $activeProfileId == $org->id)) { $profilePairs[] = ['type' => 'App\Models\Organization', 'id' => $org->id]; } } foreach ($userWithRelations->banksManaged->filter(fn($b) => !$b->deleted_at || $b->deleted_at > now()) as $bank) { if (!($activeProfileType === 'App\\Models\\Bank' && $activeProfileId == $bank->id)) { $profilePairs[] = ['type' => 'App\Models\Bank', 'id' => $bank->id]; } } foreach ($userWithRelations->admins->filter(fn($a) => !$a->deleted_at || $a->deleted_at > now()) as $admin) { if (!($activeProfileType === 'App\\Models\\Admin' && $activeProfileId == $admin->id)) { $profilePairs[] = ['type' => 'App\Models\Admin', 'id' => $admin->id]; } } if (!empty($profilePairs)) { $typeIds = collect($profilePairs)->groupBy('type')->map(fn($g) => $g->pluck('id')->toArray())->toArray(); foreach ($typeIds as $modelClass => $ids) { $found = \Illuminate\Support\Facades\DB::table('wirechat_participants as p') ->join('wirechat_conversations as c', 'p.conversation_id', '=', 'c.id') ->where('p.participantable_type', $modelClass) ->whereIn('p.participantable_id', $ids) ->whereNull('p.deleted_at') ->whereExists(function ($q) { $q->select(\Illuminate\Support\Facades\DB::raw(1)) ->from('wirechat_messages as m') ->whereColumn('m.conversation_id', 'p.conversation_id') ->whereNull('m.deleted_at') ->where(fn($q2) => $q2->whereNull('p.conversation_read_at')->orWhereColumn('m.created_at', '>', 'p.conversation_read_at')) ->where(fn($q3) => $q3->where('m.sendable_id', '!=', \Illuminate\Support\Facades\DB::raw('p.participantable_id'))->orWhere('m.sendable_type', '!=', \Illuminate\Support\Facades\DB::raw('p.participantable_type'))); }) ->exists(); if ($found) { $switchProfileHasUnread = true; break; } } } } } @endphp @php // Admin management links. Each keeps its own visibility check; for Admin profiles they are // grouped into the Editorial and Administration dropdowns, other profiles keep plain links. $navWebUser = Auth::guard('web')->user(); $navIsAdmin = strtolower(getActiveProfileType() ?? '') === 'admin'; $navCan = fn (string $permission) => (bool) $navWebUser?->can($permission); $navShowProfiles = ($navIsAdmin && $navCan('access profiles')) || (getActiveProfileType() === 'Bank' && optional(getActiveProfile())->level === 0) || $navCan('bank manage accounts'); $navLink = fn (string $label, string $route, bool $visible) => ['label' => __($label), 'route' => $route, 'visible' => $visible]; $navGroups = $navIsAdmin ? [ __('Editorial') => [ $navLink('Posts', 'posts.manage', $navCan('access posts')), $navLink('Polls', 'polls.manage', $navCan('access polls')), $navLink('Calls', 'calls.manage', true), $navLink('Mailings', 'mailings.index', $navCan('access mailings')), $navLink('Categories', 'categories.manage', $navCan('access categories')), $navLink('Tags', 'tags.manage', $navCan('access tags')), ], __('Administration') => [ $navLink('Profiles', 'profiles.manage', $navShowProfiles), $navLink('Roles', 'roles.manage', $navCan('access roles')), ], ] : []; // Drop hidden links, and groups left empty $navGroups = array_filter(array_map(fn ($links) => array_values(array_filter($links, fn ($link) => $link['visible'])), $navGroups)); @endphp