false, 'currentPubkey' => null, 'votes' => null, 'boardVotes' => null, 'events' => null, 'boardEvents' => null, 'election' => fn() => $election, 'signThisEvent' => '', 'plebs' => fn() => \App\Models\EinundzwanzigPleb::query() ->with(['profile']) ->whereIn('association_status', [3, 4]) ->orderBy('association_status', 'desc') ->get() ->toArray(), 'electionConfig' => fn() => collect(json_decode($this->election->candidates, true, 512, JSON_THROW_ON_ERROR)) ->map(fn($c) => [ 'type' => $c['type'], 'c' => $c['c'], 'candidates' => \App\Models\Profile::query() ->whereIn('pubkey', $c['c']) ->get() ->map(fn($p) => [ 'pubkey' => $p->pubkey, 'name' => $p->name, 'picture' => $p->picture, ]), ]), ]); mount(fn() => [ $this->loadEvents(), $this->loadBoardEvents(), $this->loadVotes(), $this->loadBoardVotes(), ]); on([ 'nostrLoggedOut' => function () { $this->currentPubkey = null; $this->currentPleb = null; }, ]); on([ 'nostrLoggedIn' => fn($pubkey) => [ $this->currentPubkey = $pubkey, $allowedPubkeys = [ '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033', '430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279', ], !in_array($this->currentPubkey, $allowedPubkeys, true) ? $this->js('alert("Du bist hierzu nicht berechtigt.")') : $this->isAllowed = true, ], 'echo:votes,.newVote' => fn() => [ $this->loadEvents(), $this->loadBoardEvents(), $this->loadVotes(), $this->loadBoardVotes(), ], ]); $loadVotes = function () { $this->votes = collect($this->events) ->map(fn($event) => [ 'created_at' => $event['created_at'], 'pubkey' => $event['pubkey'], 'forpubkey' => $this->fetchProfile($event['content']), 'type' => str($event['content'])->after(',')->toString(), ]) ->sortByDesc('created_at') ->unique(fn($event) => $event['pubkey'] . $event['type']) ->values() ->groupBy('type') ->map(fn($votes) => [ 'type' => $votes[0]['type'], 'votes' => $votes->groupBy('forpubkey')->map(fn($group) => ['count' => $group->count()])->toArray(), ]) ->values() ->toArray(); }; $loadBoardVotes = function () { $this->boardVotes = collect($this->boardEvents) ->map(fn($event) => [ 'created_at' => $event['created_at'], 'pubkey' => $event['pubkey'], 'forpubkey' => $this->fetchProfile($event['content']), 'type' => str($event['content'])->after(',')->toString(), ]) ->sortByDesc('created_at') ->values() ->groupBy('type') ->map(fn($votes) => [ 'type' => $votes[0]['type'], 'votes' => $votes->groupBy('forpubkey')->map(fn($group) => ['count' => $group->count()])->toArray(), ]) ->values() ->toArray(); }; $loadEvents = function () { $this->events = $this->loadNostrEvents([32122]); }; $loadBoardEvents = function () { $this->boardEvents = $this->loadNostrEvents([2121]); }; $fetchProfile = function ($content) { $pubkey = str($content)->before(',')->toString(); $profile = \App\Models\Profile::query()->where('pubkey', $pubkey)->first(); if (!$profile) { Artisan::call(\App\Console\Commands\Nostr\FetchProfile::class, ['--pubkey' => $pubkey]); $profile = \App\Models\Profile::query()->where('pubkey', $pubkey)->first(); } return $profile->pubkey; }; $loadNostrEvents = function ($kinds) { $subscription = new Subscription(); $subscriptionId = $subscription->setId(); $filter = new Filter(); $filter->setKinds($kinds); $requestMessage = new RequestMessage($subscriptionId, [$filter]); $relaySet = new RelaySet(); $relaySet->setRelays([new Relay(config('services.relay'))]); $request = new Request($relaySet, $requestMessage); $response = $request->send(); return collect($response[config('services.relay')]) ->map(fn($event) => [ 'id' => $event->event->id, 'kind' => $event->event->kind, 'content' => $event->event->content, 'pubkey' => $event->event->pubkey, 'tags' => $event->event->tags, 'created_at' => $event->event->created_at, ])->toArray(); }; ?> @volt @php $positions = [ 'presidency' => ['icon' => 'fa-crown', 'title' => 'Präsidium'], 'board' => ['icon' => 'fa-users', 'title' => 'Vorstandsmitglieder'], ]; @endphp

Wahl des Vorstands {{ $election->year }}

@php $president = $positions['presidency']; $board = $positions['board']; @endphp

{{ $president['title'] }}

{{ $board['title'] }}

@endvolt