Repository navigation
feat: host events with an issue-like page, a Watch-style going button and a milestone agenda #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hbenabdallah
wants to merge
5
commits into
dev-null-sh:production
Choose a base branch
from
hbenabdallah:feat/events
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,748
−25
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e14afc
feat: host events with an issue-like page, a Watch-style going button…
hbenabdallah 160a993
fix: show moderators the whole event, keep times in one zone and coun…
hbenabdallah 651d2de
fix: keep the compose button off the new event form and name the zone…
hbenabdallah 50fce09
fix: notify a large event's attendees in chunks and show the exact go…
hbenabdallah aa272c1
fix: name event hosts by their handle
hbenabdallah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Dto\NewEvent; | ||
| use App\Models\Event; | ||
| use App\Models\User; | ||
| use App\Services\EmojiShortcodes; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class CreateEvent | ||
| { | ||
| public function __construct(private CreateCommit $createCommit, private EmojiShortcodes $emojiShortcodes) | ||
| { | ||
| // | ||
| } | ||
|
|
||
| /** | ||
| * An event is announced by a commit, whose body is its description: the event goes through moderation with it, is | ||
| * discussed in its replies, and is deleted along with it. | ||
| */ | ||
| public function handle(User $user, string $body, NewEvent $newEvent): Event | ||
| { | ||
| return DB::transaction(function () use ($user, $body, $newEvent): Event { | ||
| $commit = $this->createCommit->handle($user, $body); | ||
|
|
||
| $event = $commit->event()->create([ | ||
| 'title' => $this->emojiShortcodes->replace($newEvent->title), | ||
| 'starts_at' => $newEvent->startsAt, | ||
| 'ends_at' => $newEvent->endsAt, | ||
| 'location' => $newEvent->location, | ||
| 'url' => $newEvent->url, | ||
| ]); | ||
|
|
||
| $event->agendaItems()->createMany(array_map(fn (array $item): array => [ | ||
| 'label' => $this->emojiShortcodes->replace($item['label']), | ||
| 'starts_at' => $item['starts_at'], | ||
| ], $newEvent->agenda)); | ||
|
|
||
| return $event->setRelation('commit', $commit); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Models\Event; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class CreateEventCancellation | ||
| { | ||
| public function __construct(private CreateEventCancellationNotifications $createEventCancellationNotifications) | ||
| { | ||
| // | ||
| } | ||
|
|
||
| public function handle(Event $event): void | ||
| { | ||
| DB::transaction(function () use ($event): void { | ||
| $event->update(['cancelled_at' => now()]); | ||
|
|
||
| $this->createEventCancellationNotifications->handle($event); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\EventResponse; | ||
| use App\Enums\NotificationType; | ||
| use App\Models\Event; | ||
| use App\Models\EventAttendee; | ||
| use App\Models\Notification; | ||
| use Illuminate\Database\Eloquent\Collection; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| final readonly class CreateEventCancellationNotifications | ||
| { | ||
| /** | ||
| * Only the people going hear about it: an interested answer is private, so nothing acts on it. The host is the actor, | ||
| * and the announcement commit is the subject, so the notification goes once the commit does. | ||
| */ | ||
| public function handle(Event $event): void | ||
| { | ||
| $hostId = $event->commit?->user_id; | ||
|
|
||
| // A statement takes at most 65,535 bound values, so a large event's notifications go in chunks. | ||
| $event->attendees() | ||
| ->where('response', EventResponse::Going) | ||
| ->chunkById(500, fn (Collection $attendees): int => Notification::query()->insertOrIgnore($attendees | ||
| ->map(fn (EventAttendee $attendee): array => [ | ||
| 'id' => Str::uuid7()->toString(), | ||
| 'recipient_id' => $attendee->user_id, | ||
| 'actor_id' => $hostId, | ||
| 'type' => NotificationType::EventCancelled->value, | ||
| 'commit_id' => $event->commit_id, | ||
| 'key' => 'event_cancelled:'.$event->id, | ||
| 'created_at' => now(), | ||
| 'updated_at' => now(), | ||
| ]) | ||
| ->all())); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Models\Event; | ||
| use App\Models\User; | ||
|
|
||
| final readonly class DeleteEventAttendance | ||
| { | ||
| public function handle(User $user, Event $event): void | ||
| { | ||
| $event->attendees()->where('user_id', $user->id)->delete(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\EventResponse; | ||
| use App\Models\Event; | ||
| use App\Models\EventAttendee; | ||
| use App\Models\User; | ||
|
|
||
| final readonly class UpdateEventAttendance | ||
| { | ||
| public function handle(User $user, Event $event, EventResponse $response): void | ||
| { | ||
| EventAttendee::query()->upsert( | ||
| [['event_id' => $event->id, 'user_id' => $user->id, 'response' => $response->value, 'created_at' => now(), 'updated_at' => now()]], | ||
| ['event_id', 'user_id'], | ||
| ['response', 'updated_at'], | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Dto; | ||
|
|
||
| use Carbon\CarbonImmutable; | ||
|
|
||
| final readonly class NewEvent | ||
| { | ||
| /** | ||
| * @param list<array{label: string, starts_at: CarbonImmutable}> $agenda | ||
| */ | ||
| public function __construct( | ||
| public string $title, | ||
| public CarbonImmutable $startsAt, | ||
| public CarbonImmutable $endsAt, | ||
| public ?string $location, | ||
| public ?string $url, | ||
| public array $agenda = [], | ||
| ) { | ||
| // | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Enums; | ||
|
|
||
| enum EventResponse: string | ||
| { | ||
| case Going = 'going'; | ||
| case Interested = 'interested'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Enums; | ||
|
|
||
| enum EventState: string | ||
| { | ||
| case Upcoming = 'upcoming'; | ||
| case Live = 'live'; | ||
| case Ended = 'ended'; | ||
| case Cancelled = 'cancelled'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.