Skip to content

Commit ad44812

Browse files
feat: add diamond and christmas pasteis
1 parent 90f528e commit ad44812

43 files changed

Lines changed: 1130 additions & 119 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎KNOWLEDGE_BASE.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ Sources: [pin authorization](app/Http/Requests/UpdateCommitPinRequest.php), [pin
385385

386386
Enable **Pastéis mode** in Settings → Profile to give pastry awards to other people's commits. You get **10 pastéis per day**, with the allowance resetting at **00:00 UTC**, and each click gives one. You cannot award your own commit. Unlike stars, repeated clicks can give more than one pastel to the same commit, using your daily allowance.
387387

388+
Each account also has **one Diamond pastel per week**, independent of the ten daily pastéis. It resets on Monday at 00:00 UTC; unused Diamonds do not accumulate. Open a commit's pastel counter by hovering, focusing or tapping it, then choose a gift. The Diamond choice appears only while it is available. After giving a Diamond, you can still give ordinary pastéis to that same commit, using your daily allowance.
389+
390+
On **December 25, from 00:00 through 23:59 UTC**, each ordinary gift has a **50% chance** of becoming a **Frosted pastel**. It uses one ordinary pastel, not an extra gift. Frosted pastéis cannot be selected directly and remain in collections after Christmas Day ends.
391+
392+
Commits and profiles keep one normal pastel icon and their total count. If they have received a Diamond, the normal icon has a subtle halo. The collection appears in a popover, showing the Original, Diamond and Frosted counts. Diamond sparkles and Frosted snowflakes animate while the collection is open, including the small icons; reduced-motion preferences disable those animations. Readers with Pastéis mode off see none of these controls, counts, collections or effects. Hover, focus or tap a variant in a collection to read its meaning: Original is everyday appreciation, Diamond is a legendary thank-you for a particularly appreciated commit or developer, and Frosted is a Christmas surprise.
393+
388394
Pastéis do not notify anyone and do not affect Trending. Turning Pastéis mode off hides its controls and counters, including the pastéis count on profiles; people can still give you pastéis. The pastel emoji and mode commemorate Fernando Andrade bringing Portuguese custard pastries to the livestream team, rather than representing a payment or purchasable currency.
389395

390396
With Pastéis mode on, the words **pastel**, **pasteis** and **pastéis** in commits automatically show as the pastel emoji. To talk about pastéis without rendering the emoji, write a backslash right before the word, like: `\pastel`.

‎app/Actions/CreateCommitPastel.php‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,57 @@
66

77
use App\Enums\CommitStatus;
88
use App\Enums\CommitUpdate;
9+
use App\Enums\PastelVariant;
910
use App\Enums\UserUpdate;
1011
use App\Events\CommitsUpdated;
1112
use App\Events\ProfilesUpdated;
1213
use App\Events\UsersUpdated;
1314
use App\Models\Commit;
1415
use App\Models\User;
16+
use App\Services\PastelSeason;
1517
use Illuminate\Support\Facades\DB;
1618

1719
final readonly class CreateCommitPastel
1820
{
19-
public function handle(User $user, Commit $commit): bool
21+
public function __construct(private PastelSeason $season)
2022
{
21-
return DB::transaction(function () use ($user, $commit): bool {
23+
//
24+
}
25+
26+
public function handle(User $user, Commit $commit, PastelVariant $variant = PastelVariant::Original): bool
27+
{
28+
return DB::transaction(function () use ($user, $commit, $variant): bool {
2229
$users = User::query()->whereKey([$user->id, $commit->user_id])
2330
->orderBy('id')->lockForUpdate()->get()->keyBy('id');
2431
$sender = $users->get($user->id);
2532
assert($sender instanceof User);
2633

27-
$remaining = $sender->pasteisRemaining();
34+
$remaining = $variant === PastelVariant::Diamond ? $sender->diamondPasteisRemaining() : $sender->pasteisRemaining();
2835

2936
if ($remaining === 0) {
3037
return false;
3138
}
3239

3340
$recipientCommit = Commit::query()->lockForUpdate()->findOrFail($commit->id);
3441

35-
$sender->update([
36-
'pasteis_given_on' => today()->toDateString(),
37-
'pasteis_given_today' => User::DAILY_PASTEIS - $remaining + 1,
38-
]);
42+
if ($variant === PastelVariant::Diamond) {
43+
$sender->update(['diamond_pastel_given_at' => now()]);
44+
} else {
45+
$sender->update([
46+
'pasteis_given_on' => today()->toDateString(),
47+
'pasteis_given_today' => User::DAILY_PASTEIS - $remaining + 1,
48+
]);
49+
$variant = $this->season->variant();
50+
}
3951

4052
$recipientCommit->increment('pasteis_count');
4153
User::query()->whereKey($commit->user_id)->increment('pasteis_received');
4254

55+
if ($variant !== PastelVariant::Original) {
56+
$recipientCommit->increment('pasteis_'.$variant->value.'_count');
57+
User::query()->whereKey($commit->user_id)->increment('pasteis_'.$variant->value.'_received');
58+
}
59+
4360
// The count is everyone's to see, and the giver's other devices learn what they have left to give.
4461
if ($recipientCommit->status === CommitStatus::Approved) {
4562
event(new CommitsUpdated([$recipientCommit], CommitUpdate::Engagement));

‎app/Actions/CreateExport.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
public function handle(User $user): array
8787
{
8888
return [
89-
'schema_version' => 9,
89+
'schema_version' => 10,
9090
'exported_at' => now()->toIso8601String(),
9191
'profile' => [
9292
'github_id' => $user->github_id,
@@ -107,6 +107,9 @@ public function handle(User $user): array
107107
'lane_color' => $user->lane_color,
108108
'pasteis_mode' => $user->pasteis_mode,
109109
'pasteis_received' => $user->pasteis_received,
110+
'pasteis_diamond_received' => $user->pasteis_diamond_received,
111+
'pasteis_frosted_received' => $user->pasteis_frosted_received,
112+
'diamond_pastel_given_at' => $user->diamond_pastel_given_at?->toIso8601String(),
110113
'pasteis_given_today' => $user->pasteis_given_today,
111114
'pasteis_given_on' => $user->pasteis_given_on?->toDateString(),
112115
'remotes_enabled' => $user->remotes_enabled,
@@ -233,7 +236,7 @@ private function commits(User $user): Generator
233236
{
234237
$commits = $user->commits()
235238
->withTrashed()
236-
->select(['id', 'parent_id', 'quoted_commit_id', 'guild_id', 'body', 'status', 'pasteis_count', 'created_at', 'updated_at', 'deleted_at'])
239+
->select(['id', 'parent_id', 'quoted_commit_id', 'guild_id', 'body', 'status', 'pasteis_count', 'pasteis_diamond_count', 'pasteis_frosted_count', 'created_at', 'updated_at', 'deleted_at'])
237240
->with(['images:id,commit_id', 'guild'])
238241
->lazyById(500);
239242

@@ -252,6 +255,8 @@ private function commits(User $user): Generator
252255
'cached_translations' => $cached[$translations->key($commit)],
253256
'status' => $commit->status->value,
254257
'pasteis_count' => $commit->pasteis_count,
258+
'pasteis_diamond_count' => $commit->pasteis_diamond_count,
259+
'pasteis_frosted_count' => $commit->pasteis_frosted_count,
255260
'images' => $commit->images->map(fn (CommitImage $image): string => $image->url())->all(),
256261
'created_at' => $commit->created_at->toIso8601String(),
257262
'updated_at' => $commit->updated_at->toIso8601String(),

‎app/Enums/PastelVariant.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Enums;
6+
7+
enum PastelVariant: string
8+
{
9+
case Original = 'original';
10+
case Diamond = 'diamond';
11+
case Frosted = 'frosted';
12+
}

‎app/Exceptions/ApiException.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public static function invalidGrant(): self
5858
/**
5959
* The user gave every pastel they get today. The web's own words, which say when they come back.
6060
*/
61-
public static function pasteisExhausted(): self
61+
public static function pasteisExhausted(bool $diamond = false): self
6262
{
63-
return new self(ApiErrorCode::PasteisExhausted, __('you ran out of pastéis. wait until tomorrow.'));
63+
return new self(ApiErrorCode::PasteisExhausted, $diamond ? __('You already gave your Diamond this week. Your next one arrives on Monday at 00:00 UTC.') : __('you ran out of pastéis. wait until tomorrow.'));
6464
}
6565

6666
/**

‎app/Http/Controllers/Api/CommitPastelController.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers\Api;
66

77
use App\Actions\CreateCommitPastel;
8+
use App\Enums\PastelVariant;
89
use App\Exceptions\ApiException;
910
use App\Http\Requests\CreateApiCommitPastelRequest;
1011
use App\Http\Resources\CommitResource;
@@ -23,14 +24,16 @@
2324
*/
2425
public function store(CreateApiCommitPastelRequest $request, #[CurrentUser] User $user, Commit $commit, CreateCommitPastel $action, CommitPageQuery $page): CommitResource|JsonResponse
2526
{
26-
if (! $action->handle($user, $commit)) {
27-
return ApiException::pasteisExhausted()->render();
27+
if (! $action->handle($user, $commit, $request->variant())) {
28+
return ApiException::pasteisExhausted($request->variant() === PastelVariant::Diamond)->render();
2829
}
2930

3031
$commit = $page->get($commit, $user);
3132

3233
return CommitResource::make($commit)->additional([
3334
'pasteis_remaining' => $user->refresh()->pasteisRemaining(),
35+
'diamond_pasteis_remaining' => $user->diamondPasteisRemaining(),
36+
'diamond_pasteis_resets_at' => now()->startOfWeek(1)->addWeek()->toIso8601ZuluString(),
3437
'pasteis_resets_at' => today()->addDay()->toIso8601ZuluString(),
3538
'author_pasteis_received' => $commit->user?->pasteis_received,
3639
]);

‎app/Http/Controllers/Api/UserController.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function show(ShowApiUserRequest $request, #[CurrentUser] ?User $currentU
3939
'follows_you' => $user->isFollowing($currentUser),
4040
'is_muting' => $currentUser->isMuting($user),
4141
'pasteis_received' => $user->pasteis_received,
42+
'pasteis_collection' => $currentUser->pasteis_mode ? [
43+
'diamond' => $user->pasteis_diamond_received,
44+
'frosted' => $user->pasteis_frosted_received,
45+
] : null,
4246
'activity' => $activity->get($user, $currentUser),
4347
'streaks' => $userStreaks,
4448
'achievements' => $achievements->get($user, $currentUser, $userStreaks),

‎app/Http/Controllers/CommitPastelController.php‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers;
66

77
use App\Actions\CreateCommitPastel;
8+
use App\Enums\PastelVariant;
89
use App\Http\Requests\CreateCommitPastelRequest;
910
use App\Models\Commit;
1011
use App\Models\User;
@@ -15,17 +16,23 @@
1516
{
1617
public function store(CreateCommitPastelRequest $request, #[CurrentUser] User $user, Commit $commit, CreateCommitPastel $action): JsonResponse
1718
{
18-
$awarded = $action->handle($user, $commit);
19+
$awarded = $action->handle($user, $commit, $request->variant());
1920

2021
return response()->json([
2122
'pasteis_count' => $commit->refresh()->pasteis_count,
23+
'pasteis_diamond_count' => $commit->pasteis_diamond_count,
24+
'pasteis_frosted_count' => $commit->pasteis_frosted_count,
2225
'remaining' => $user->refresh()->pasteisRemaining(),
26+
'diamond_remaining' => $user->diamondPasteisRemaining(),
27+
'diamond_resets_at' => now()->startOfWeek(1)->addWeek()->toIso8601ZuluString(),
2328
'day' => today()->toDateString(),
2429
'recipient' => [
2530
'id' => $commit->user_id,
2631
'pasteis_received' => $commit->user?->pasteis_received,
32+
'pasteis_diamond_received' => $commit->user?->pasteis_diamond_received,
33+
'pasteis_frosted_received' => $commit->user?->pasteis_frosted_received,
2734
],
28-
...$awarded ? [] : ['errors' => ['pastel' => ['you ran out of pastéis. wait until tomorrow.']]],
35+
...$awarded ? [] : ['errors' => ['pastel' => [$request->variant() === PastelVariant::Diamond ? 'You already gave your Diamond this week. Your next one arrives on Monday at 00:00 UTC.' : 'you ran out of pastéis. wait until tomorrow.']]],
2936
], $awarded ? 200 : 422);
3037
}
3138
}

‎app/Http/Controllers/UserController.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public function show(ShowUserRequest $request, #[CurrentUser] ?User $currentUser
7272
'user' => Inertia::live(fn (): ?array => ShownStreams::user($getCountedUser()), 'profile', $profile),
7373
'profileGuilds' => Inertia::live(fn (): ?array => $currentUser instanceof User && $features->available(Feature::Guilds, $currentUser) ? $guilds->joinedHandles($user) : null, 'profile', $profile),
7474
'bioProfiles' => fn (): array => $bioProfiles->get($user),
75+
'pasteisCollection' => Inertia::live(fn (): ?array => $currentUser?->pasteis_mode ? [
76+
'diamond' => $user->pasteis_diamond_received,
77+
'frosted' => $user->pasteis_frosted_received,
78+
] : null, 'profile', $profile),
7579
'pasteisReceived' => Inertia::live(fn (): ?int => $currentUser?->pasteis_mode ? $user->pasteis_received : null, 'profile', $profile),
7680
'isFollowing' => $relationship(fn (): bool => $currentUser?->isFollowing($user) ?? false),
7781
'followsYou' => $relationship(fn (): bool => $currentUser instanceof User && $user->isFollowing($currentUser)),

‎app/Http/Middleware/HandleInertiaRequests.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ public function share(Request $request): array
158158
] : null, UserUpdate::Account),
159159
'pasteis' => $live(fn (): ?array => $user?->pasteis_mode ? [
160160
'remaining' => $user->pasteisRemaining(),
161+
'diamond_remaining' => $user->diamondPasteisRemaining(),
162+
'diamond_resets_at' => now()->startOfWeek(1)->addWeek()->toIso8601ZuluString(),
161163
'day' => today()->toDateString(),
162164
] : null, UserUpdate::Account),
163165
],

0 commit comments

Comments
 (0)