Skip to content

Commit fff300d

Browse files
committed
Merge production into IndexedDB retry fix
2 parents 5b0a5eb + facb804 commit fff300d

36 files changed

Lines changed: 1869 additions & 143 deletions

‎.ai/guidelines/resources.js.blade.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
## Navigation and requests
1818

19-
- Every Inertia `<Link>` to a GET page prefetches on hover (`prefetch`). A GET page never writes; the only exceptions are `log/{log}` (remembers the log), `notifications` (marks read, remembers the filter), `remotes/@{partner}` and `remotes/orgs/{org}` (mark read), and every link to them keeps `prefetch={false}`. `starred` also keeps it, because starring changes the list. A new GET page that must write joins this list.
19+
- Every Inertia `<Link>` to a GET page prefetches on hover (`prefetch`). A GET page never writes; the only exceptions are `log/{log}` (remembers the log), `notifications` (marks read, remembers the filter), `remotes/@{partner}` and `remotes/orgs/{org}` (mark read), and every link to them keeps `prefetch={false}`. The navigation's Log is the exception: it opens the remembered log and a prefetch never changes the remembered log, so it prefetches everywhere except on a log page, where it scrolls to the top instead. `starred` also keeps it, because starring changes the list. A new GET page that must write joins this list.
2020
- Never prefetch a non-GET link, an external URL, a guest's sign-in link, a mention of a handle nobody here has (guests get a missing page, and a feed would ask for it on every hover), or a URL that is not an Inertia page (images, feeds, downloads, JSON).
2121
- A click target that is not a link (the commit card surface) prefetches on `mousedown`, never on hover: scrolling a feed hovers every card.
2222
- After an action that changes what a prefetched page shows, flush that page (`router.flush(url)`, `router.flushAll()`, or `invalidateCacheTags`), so the next click does not show the old state.

‎KNOWLEDGE_BASE.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ Sources: [onboarding page](resources/js/pages/onboarding/show.tsx), [sign-in tes
105105

106106
Pages update as things happen, without reloading: new replies and quotes in an open thread, a commit approved, deleted or brought back with Undo, new commits in Following and Latest, star, pastéis and reply counts on the commits on screen, poll results once someone votes or the poll closes, link cards and translations once they are ready, unread counts, the notifications list, Remotes messages, reactions, pins, reads and typing, incoming calls, the scheduled commits page, the GitHub import during setup, live markers, profile counts and pinned commits, organization pages, the moderation and reports queues, your settings, abilities and features across your devices, and the devices, safety and organization member settings. Followers and following lists, and the moderation and reports queues once they show something, offer a refresh instead of changing under you, so the pages you loaded stay; the Live now list keeps who it showed, marking a stream that ended, until the next page. Blocking, muting or following someone updates the feeds and threads you have open. The connection is used only to learn that something changed: the page then reads it again with your own access, so nothing private travels over it, and a remote you lose access to closes. When the connection drops, or a page comes back from history, pages check what they missed and catch up, and they go back to checking on their own every so often until it returns. Trending is never reordered while you read it: only commits that are gone leave it. Open notifications are only marked read while the tab is in front of you. The mobile and Mac apps don't use live updates yet.
107107

108+
Following and Latest group incoming commits during busy periods. After a quiet spell, arrivals are checked after about a second; successive batches with several new commits increase the wait through 5, 10, 20 and at most 30 seconds. A quiet period restores the fast updates. Hidden tabs save their pending updates and catch up when shown. Deletions, blocks and connection recovery do not wait behind an arrival batch. The log keeps your reading position and shows its existing new-commit notice when arrivals are above you.
109+
108110
Sources: [live updates](resources/js/lib/realtime.ts), [what changed](app/Enums/UserUpdate.php), [commit updates](app/Events/CommitsUpdated.php).
109111

110112
### Profiles and GitHub sync
@@ -202,6 +204,8 @@ Logs are the app's timelines. **Following** contains your commits and those of d
202204

203205
Logs list top-level commits, including quotes, rather than every reply, 20 at a time as you scroll, and show your own pending commits to you, and your organizations' to their members. Following and Latest find new commits as they are published, including the first one in an empty log and older ones approved since, and mark where you left off. Following and Latest load new commits automatically. New arrivals stay above the content you are reading, even when you start at the top or their images and link previews finish loading later. A **New commits** control appears after they load above you and stays until you return to the top or see the newest arrival below the sticky tabs. Switching away from the tab does not mark arrivals as seen. It previews up to three distinct authors from the new commits waiting above you, with a +N circle for additional authors. Deleted or no-longer-visible commits leave the announcement and the loaded feed as they go; the control disappears if none remain. Select it to scroll to the new commits; it disappears when you reach them. On touch screens, swipe sideways to move between logs. An empty Following log suggests three recent commits from people to follow. Muted and blocked people are filtered for signed-in viewers. The last log you opened is remembered.
204206

207+
While reading a log, selecting **Log** in the navigation scrolls back to the top without reloading the feed. Selecting the current **Following** or **Latest** tab does the same; selecting **Trending** again refreshes its ranking. Switching to a different log still loads that log. The return to the top slows as it arrives, can be interrupted by scrolling, and respects reduced-motion preferences.
208+
205209
Browser Back and Forward restore expanded replies and loaded thread continuations. Offscreen commits are measured before scroll restoration so returning to a log or discussion keeps the content in place.
206210

207211
If a background check hits a temporary connection or gateway failure, the page keeps its last received content and tries again on the normal polling schedule.

‎app/Actions/CreateDevice.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
{
1515
/**
1616
* Redeems an authorization code: the key it was handed out for becomes an approved device of the user who approved
17-
* it, and the code is used up. A key that was approved before, even for someone else, is approved again for them.
17+
* it, and the code is used up. A key that was approved before, even for someone else, is approved again for them,
18+
* without the push token it had, until the app sends one.
1819
*
1920
* A code is redeemed once, like a signature nonce is used once, so of two requests with the same code only one gets
2021
* a device. The other gets null.
@@ -34,6 +35,9 @@ public function handle(AuthorizationCode $authorizationCode): ?Device
3435
'app_name' => $authorizationCode->appName,
3536
'approved_at' => now(),
3637
'last_used_at' => null,
38+
'push_token_hash' => null,
39+
'push_token' => null,
40+
'push_platform' => null,
3741
]);
3842

3943
event(new UsersUpdated([$authorizationCode->userId], UserUpdate::Account));

‎app/Actions/CreateExport.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* notifications: Generator<int, array<string, int|string|null>>,
6060
* ssh_keys: array<mixed>,
6161
* push_subscriptions: array<int, array{id: string}>,
62-
* devices: array<int, array{name: string, app_id: string|null, app_name: string|null, fingerprint: string, approved_at: string, last_used_at: string|null}>,
62+
* devices: array<int, array{name: string, app_id: string|null, app_name: string|null, fingerprint: string, approved_at: string, last_used_at: string|null, push_platform: string|null}>,
6363
* timeouts: array<int, array{reason: string, ends_at: string, created_at: string}>,
6464
* sessions: Collection<int, stdClass>
6565
* }
@@ -100,6 +100,11 @@ public function handle(User $user): array
100100
'remotes_enabled' => $user->remotes_enabled,
101101
'remotes_from' => $user->remotes_from->value,
102102
'pull_receipts' => $user->pull_receipts,
103+
'push_follows' => $user->push_follows,
104+
'push_replies' => $user->push_replies,
105+
'push_mentions' => $user->push_mentions,
106+
'push_direct_remotes' => $user->push_direct_remotes,
107+
'push_org_remotes' => $user->push_org_remotes,
103108
'pinned_commit_id' => $user->pinned_commit_id,
104109
'live_platform' => $user->live_platform?->value,
105110
'live_url' => $user->live_url,
@@ -172,6 +177,7 @@ public function handle(User $user): array
172177
'fingerprint' => $device->fingerprint,
173178
'approved_at' => $device->approved_at->toIso8601String(),
174179
'last_used_at' => $device->last_used_at?->toIso8601String(),
180+
'push_platform' => $device->push_platform?->value,
175181
])->all(),
176182
'timeouts' => $user->timeouts()->oldest()->get()->map(fn (UserTimeout $timeout): array => [
177183
'reason' => $timeout->reason->value,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Actions;
6+
7+
use App\Models\Device;
8+
9+
final readonly class DeleteDevicePushToken
10+
{
11+
/**
12+
* Nothing is pushed to the device until it sends a token again. This writes straight to the row rather than
13+
* through the copy authentication loaded, which can be out of date if a token arrived since.
14+
*/
15+
public function handle(Device $device): void
16+
{
17+
Device::query()->whereKey($device->id)->update(['push_token_hash' => null, 'push_token' => null, 'push_platform' => null]);
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Actions;
6+
7+
use App\Enums\PushPlatform;
8+
use App\Models\Device;
9+
use Illuminate\Database\UniqueConstraintViolationException;
10+
use Illuminate\Support\Facades\DB;
11+
use Throwable;
12+
13+
final readonly class UpdateDevicePushToken
14+
{
15+
/**
16+
* Pushes for the device go to this token from now on. A token belongs to the phone that sent it last, so it leaves
17+
* any other device that had it, such as the one the phone signed in as before, under this account or another.
18+
* Two phones sending the same token at once can both clear it before either takes it, so the one that loses the
19+
* unique index starts the move again. The device is read again under a lock, since the copy authentication loaded
20+
* can be out of date, and Eloquent skips writing a value it thinks is unchanged.
21+
*/
22+
public function handle(Device $device, string $token, PushPlatform $platform): void
23+
{
24+
$hash = hash('sha256', $token);
25+
26+
retry(3, fn () => DB::transaction(function () use ($device, $token, $platform, $hash): void {
27+
Device::query()->where('push_token_hash', $hash)->whereKeyNot($device->id)
28+
->update(['push_token_hash' => null, 'push_token' => null, 'push_platform' => null]);
29+
30+
Device::query()->whereKey($device->id)->lockForUpdate()->firstOrFail()
31+
->update(['push_token_hash' => $hash, 'push_token' => $token, 'push_platform' => $platform]);
32+
}), when: fn (Throwable $exception): bool => $exception instanceof UniqueConstraintViolationException);
33+
}
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Actions;
6+
7+
use App\Enums\PushPreference;
8+
use App\Enums\UserUpdate;
9+
use App\Events\UsersUpdated;
10+
use App\Models\User;
11+
12+
final readonly class UpdateUserPushPreferences
13+
{
14+
/**
15+
* @param array<value-of<PushPreference>, bool> $preferences
16+
*/
17+
public function handle(User $user, array $preferences): void
18+
{
19+
$user->update(collect($preferences)->mapWithKeys(fn (bool $on, string $preference): array => [
20+
PushPreference::from($preference)->column() => $on,
21+
])->all());
22+
23+
event(new UsersUpdated([$user->id], UserUpdate::Account));
24+
}
25+
}

‎app/Enums/PushPlatform.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Enums;
6+
7+
/**
8+
* What kind of phone a push token is for, which decides how a push to it is shaped.
9+
*/
10+
enum PushPlatform: string
11+
{
12+
case Ios = 'ios';
13+
case Android = 'android';
14+
}

‎app/Enums/PushPreference.php‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Enums;
6+
7+
use App\Models\User;
8+
9+
/**
10+
* What a user can choose to have pushed to their phones, each a switch of its own.
11+
*/
12+
enum PushPreference: string
13+
{
14+
case Follows = 'follows';
15+
case Replies = 'replies';
16+
case Mentions = 'mentions';
17+
case DirectRemotes = 'direct_remotes';
18+
case OrgRemotes = 'org_remotes';
19+
20+
/**
21+
* The switch for a notification, or null when it is one that isn't pushed.
22+
*/
23+
public static function forNotification(NotificationType $type): ?self
24+
{
25+
return match ($type) {
26+
NotificationType::Followed => self::Follows,
27+
NotificationType::Replied => self::Replies,
28+
NotificationType::Mentioned => self::Mentions,
29+
default => null,
30+
};
31+
}
32+
33+
/**
34+
* The switch for messages and pings in a conversation of this kind.
35+
*/
36+
public static function forConversation(ConversationKind $kind): self
37+
{
38+
return match ($kind) {
39+
ConversationKind::Direct => self::DirectRemotes,
40+
ConversationKind::Org => self::OrgRemotes,
41+
};
42+
}
43+
44+
/**
45+
* Every switch and whether the user has it on.
46+
*
47+
* @return array<value-of<self>, bool>
48+
*/
49+
public static function allFor(User $user): array
50+
{
51+
return collect(self::cases())->mapWithKeys(fn (self $preference): array => [$preference->value => $preference->isOnFor($user)])->all();
52+
}
53+
54+
public function column(): string
55+
{
56+
return "push_{$this->value}";
57+
}
58+
59+
public function isOnFor(User $user): bool
60+
{
61+
return $user->getAttribute($this->column()) === true;
62+
}
63+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Controllers\Api;
6+
7+
use App\Actions\DeleteDevicePushToken;
8+
use App\Actions\UpdateDevicePushToken;
9+
use App\Http\Requests\DeleteApiDevicePushTokenRequest;
10+
use App\Http\Requests\UpdateApiDevicePushTokenRequest;
11+
use Illuminate\Http\Response;
12+
13+
final readonly class DevicePushTokenController
14+
{
15+
/**
16+
* Saves the token pushes reach the phone that signed the request with, replacing the one it sent before.
17+
*/
18+
public function update(UpdateApiDevicePushTokenRequest $request, UpdateDevicePushToken $action): Response
19+
{
20+
$action->handle($request->device(), $request->string('token')->toString(), $request->platform());
21+
22+
return response()->noContent();
23+
}
24+
25+
/**
26+
* Stops pushing to the phone that signed the request, as when the app signs out or notifications are turned off.
27+
*/
28+
public function destroy(DeleteApiDevicePushTokenRequest $request, DeleteDevicePushToken $action): Response
29+
{
30+
$action->handle($request->device());
31+
32+
return response()->noContent();
33+
}
34+
}

0 commit comments

Comments
 (0)