false]); state(['currentPubkey' => null]); state(['currentPleb' => null]); state(['events' => []]); state(['election' => fn() => $election]); state(['plebs' => []]); state(['search' => '']); state(['signThisEvent' => '']); state(['isNotClosed' => true]); mount(function () { $this->plebs = \App\Models\EinundzwanzigPleb::query() ->with([ 'profile', ]) ->whereIn('association_status', [3, 4]) ->orderBy('association_status', 'desc') ->get() ->toArray(); $this->loadEvents(); if ($this->election->end_time->isPast()) { $this->isNotClosed = false; } }); on([ 'nostrLoggedIn' => function ($pubkey) { $this->currentPubkey = $pubkey; $this->currentPleb = \App\Models\EinundzwanzigPleb::query() ->where('pubkey', $pubkey)->first(); if($this->currentPleb->association_status->value < 3) { return redirect()->route('association.profile'); } $this->isAllowed = true; }, ]); on([ 'echo:votes,.newVote' => function () { $this->loadEvents(); } ]); updated([ 'search' => function ($value) { $this->plebs = \App\Models\EinundzwanzigPleb::query() ->with([ 'profile', ]) ->whereIn('association_status', [3, 4]) ->where(fn($query) => $query ->where('pubkey', 'like', "%$value%") ->orWhereHas('profile', function ($query) use ($value) { $query->where('name', 'ilike', "%$value%"); })) ->orderBy('association_status', 'desc') ->get() ->toArray(); }, ]); $loadEvents = function () { $subscription = new Subscription(); $subscriptionId = $subscription->setId(); $filter1 = new Filter(); $filter1->setKinds([2121]); // You can add multiple kind numbers $filters = [$filter1]; // You can add multiple filters. $requestMessage = new RequestMessage($subscriptionId, $filters); $relays = [ new Relay(config('services.relay')), ]; $relaySet = new RelaySet(); $relaySet->setRelays($relays); $request = new Request($relaySet, $requestMessage); $response = $request->send(); $this->events = 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(); }; $vote = function ($pubkey, $type) { if ($this->election->end_time->isPast()) { $this->isNotClosed = false; return; } $note = new NostrEvent(); $note->setContent($pubkey . ',' . $type); $note->setKind(2121); $this->signThisEvent = $note->toJson(); }; $checkElection = function () { if ($this->election->end_time->isPast()) { $this->isNotClosed = false; } }; $signEvent = function ($event) { $note = new NostrEvent(); $note->setId($event['id']); $note->setSignature($event['sig']); $note->setKind($event['kind']); $note->setContent($event['content']); $note->setPublicKey($event['pubkey']); $note->setTags($event['tags']); $note->setCreatedAt($event['created_at']); $eventMessage = new EventMessage($note); $relayUrl = config('services.relay'); $relay = new Relay($relayUrl); $relay->setMessage($eventMessage); $result = $relay->send(); Broadcast::on('votes') ->as('newVote') ->sendNow(); }; ?> @volt
@php $positions = [ 'presidency' => ['icon' => 'fa-crown', 'title' => 'Präsidium'], 'vice_president' => ['icon' => 'fa-user-group-crown', 'title' => 'Vizepräsidium'], 'finances' => ['icon' => 'fa-bitcoin-sign', 'title' => 'Finanzen'], 'secretary' => ['icon' => 'fa-stapler', 'title' => 'Revisionsstelle'], 'press_officer' => ['icon' => 'fa-newspaper', 'title' => 'Pressewart'], 'it_manager' => ['icon' => 'fa-server', 'title' => 'Technikwart'], ]; $loadedEvents = collect($events) ->map(function($event) { $profile = \App\Models\Profile::query() ->where('pubkey', $event['pubkey']) ->first() ?->toArray(); $votedFor = \App\Models\Profile::query() ->where('pubkey', str($event['content'])->before(',')->toString()) ->first() ?->toArray(); return [ 'id' => $event['id'], 'kind' => $event['kind'], 'content' => $event['content'], 'pubkey' => $event['pubkey'], 'tags' => $event['tags'], 'created_at' => $event['created_at'], 'profile' => $profile, 'votedFor' => $votedFor, 'type' => str($event['content'])->after(',')->toString(), ]; }) ->sortByDesc('created_at') ->unique(fn ($event) => $event['pubkey'] . $event['type']) ->values(); @endphp
Plebs
    @foreach($plebs as $pleb)
  • {{ $pleb['pubkey'] }}
    {{ $pleb['profile']['name'] ?? $pleb['pubkey'] }}
    @foreach($positions as $name => $p) @php $votedResult = $loadedEvents->filter(fn ($e) => $e['pubkey'] === $pleb['pubkey'])->firstWhere('type', $name); @endphp
    @if($votedResult) @endif
    @endforeach
  • @endforeach
@if($currentPubkey) @php $electionConfig = collect(json_decode($election->candidates, true, 512, JSON_THROW_ON_ERROR)) ->map(function ($c) use ($loadedEvents, $currentPubkey) { $candidates = \App\Models\Profile::query() ->whereIn('pubkey', $c['c']) ->get() ->map(function ($p) use ($loadedEvents, $c, $currentPubkey) { $votedClass = ' bg-green-500/20 text-green-700'; $notVotedClass = ' bg-gray-500/20 text-gray-100'; $hasVoted = $loadedEvents ->filter(fn($e) => $e['type'] === $c['type'] && $e['pubkey'] === $currentPubkey) ->firstWhere('votedFor.pubkey', $p->pubkey); return [ 'pubkey' => $p->pubkey, 'name' => $p->name, 'picture' => $p->picture, 'votedClass' => $hasVoted ? $votedClass : $notVotedClass, ]; }); return [ 'type' => $c['type'], 'c' => $c['c'], 'candidates' => $candidates, ]; }); @endphp
@if($isNotClosed) @else @endif

Wahl des Vereinsvorstands

@foreach($positions as $type => $position) @if($electionConfig->firstWhere('type', $type))

{{ $position['title'] }}

@php $votedResult = $loadedEvents->filter(fn ($event) => $event['pubkey'] === $currentPubkey)->firstWhere('type', $type); @endphp @if($votedResult) Du hast "{{ $votedResult['votedFor']['name'] ?? 'error' }}" gewählt @else Klicke auf den Kandidaten, den du wählen möchtest. @endif
@foreach($electionConfig->firstWhere('type', $type)['candidates'] as $c)
{{ $c['name'] }} {{ $c['name'] }}
@endforeach
@endif @endforeach
@endif
@endvolt