Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions app/Devnull/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,13 @@ public function replies(string $id, ?string $cursor = null): Page
* Commits, as a reply to $parentId or quoting $quotedCommitId, as the web's
* composer, reply box and Quote do. devnull takes one or the other, not both.
* A new commit or a quote may start a poll (see PollDraft::payload()).
* A new commit can go straight to a guild's board ($guildHandle).
*
* @param array{options: list<string>, duration: int}|null $poll
*/
public function createCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null): Commit
public function createCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null, ?string $guildHandle = null): Commit
{
$commit = $this->data($this->send('POST', 'commits', payload: self::commitPayload($body, $parentId, $quotedCommitId, poll: $poll)));
$commit = $this->data($this->send('POST', 'commits', payload: self::commitPayload($body, $parentId, $quotedCommitId, $poll, $guildHandle)));
$this->cache->commitAdded($commit);

return Commit::fromArray($commit);
Expand All @@ -321,9 +322,9 @@ public function createCommit(string $body, ?string $parentId = null, ?string $qu
*
* @param array{options: list<string>, duration: int}|null $poll
*/
public function signedCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null): SignedRequest
public function signedCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null, ?string $guildHandle = null): SignedRequest
{
return $this->signedWrite('POST', 'commits', self::commitPayload($body, $parentId, $quotedCommitId, poll: $poll));
return $this->signedWrite('POST', 'commits', self::commitPayload($body, $parentId, $quotedCommitId, $poll, $guildHandle));
}

/**
Expand All @@ -333,9 +334,9 @@ public function signedCommit(string $body, ?string $parentId = null, ?string $qu
*
* @param list<DraftImage> $images
*/
public function signedCommitWithImages(string $body, array $images, ?string $parentId = null, ?string $quotedCommitId = null): SignedRequest
public function signedCommitWithImages(string $body, array $images, ?string $parentId = null, ?string $quotedCommitId = null, ?string $guildHandle = null): SignedRequest
{
return $this->signedWithImages('commits', self::commitPayload($body, $parentId, $quotedCommitId), $images);
return $this->signedWithImages('commits', self::commitPayload($body, $parentId, $quotedCommitId, guildHandle: $guildHandle), $images);
}

/**
Expand All @@ -362,14 +363,14 @@ public function signedMessage(string $threadPath, string $body, string $clientId
* Signs a commit to be submitted at $at, as the web's Schedule commit
* does, for the background to send. Only you see it until then. With
* photos it goes as multipart, as a commit with photos does, and a poll
* goes in its JSON.
* goes in its JSON. One for a guild's board says which ($guildHandle).
*
* @param list<DraftImage> $images
* @param array<string, mixed>|null $poll
*/
public function signedScheduledCommit(string $body, CarbonInterface $at, array $images = [], ?array $poll = null): SignedRequest
public function signedScheduledCommit(string $body, CarbonInterface $at, array $images = [], ?array $poll = null, ?string $guildHandle = null): SignedRequest
{
$payload = array_filter(['body' => $body, 'scheduled_at' => self::scheduleTime($at), 'poll' => $poll], fn (mixed $value): bool => $value !== null);
$payload = array_filter(['body' => $body, 'scheduled_at' => self::scheduleTime($at), 'poll' => $poll, 'guild_handle' => $guildHandle], fn (mixed $value): bool => $value !== null);

return $images === []
? $this->signedWrite('POST', self::ScheduledCommitsPath, $payload)
Expand Down Expand Up @@ -1004,13 +1005,14 @@ private function send(string $method, string $path, array $query = [], ?array $p
* @param array{options: list<string>, duration: int}|null $poll
* @return array<string, mixed>
*/
private static function commitPayload(string $body, ?string $parentId, ?string $quotedCommitId, ?array $poll = null): array
private static function commitPayload(string $body, ?string $parentId, ?string $quotedCommitId, ?array $poll = null, ?string $guildHandle = null): array
{
return array_filter([
'body' => $body,
'parent_id' => $parentId,
'quoted_commit_id' => $quotedCommitId,
'poll' => $poll,
'guild_handle' => $guildHandle,
], fn (mixed $value): bool => $value !== null);
}

Expand Down
7 changes: 4 additions & 3 deletions app/Devnull/Outbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ public function pending(string $kind, ?string $target = null, bool $withFailed =
}

/**
* Commits on their way that reply to $parentId, or with null, new commits and quotes.
* Commits on their way that reply to $parentId, or with null, new commits and quotes: those for your log, or with
* $guildHandle, those for that guild's board.
*
* @return Collection<int, PendingWrite>
*/
public function commitsUnder(?string $parentId): Collection
public function commitsUnder(?string $parentId, ?string $guildHandle = null): Collection
{
return $this->pending(PendingWrite::Commit)->filter(fn (PendingWrite $write): bool => $write->parentId() === $parentId)->values();
return $this->pending(PendingWrite::Commit)->filter(fn (PendingWrite $write): bool => $write->parentId() === $parentId && $write->guildHandle() === $guildHandle)->values();
}

/**
Expand Down
12 changes: 10 additions & 2 deletions app/Devnull/ResponseCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Devnull;

use App\Devnull\Data\Guild;
use Carbon\CarbonImmutable;
use Closure;
use Illuminate\Contracts\Cache\Repository;
Expand Down Expand Up @@ -399,7 +400,10 @@ public function pastelGiven(array $json): void

/**
* You committed. A commit goes on top of your logs and your profile; a reply
* goes under its parent and counts there, and on top of your replies.
* goes under its parent and counts there, and on top of your replies. A
* post to a guild's board goes on top of that board alone, as it isn't in
* the logs or your profile's list, though devnull counts it among your
* commits.
*
* @param array<string, mixed> $commit
*/
Expand All @@ -413,9 +417,13 @@ public function commitAdded(array $commit): void

$parentId = is_string($commit['parent_id'] ?? null) ? $commit['parent_id'] : null;

$guild = Guild::fromArray(is_array($commit['guild'] ?? null) ? $commit['guild'] : ['handle' => $commit['guild_handle'] ?? null]);

if ($parentId === null) {
// Trending is ranked, so a new commit has no place at the top of it.
foreach (['log/following', 'log/latest', "users/{$me}/commits"] as $path) {
$paths = $guild === null ? ['log/following', 'log/latest', "users/{$me}/commits"] : ['guilds/'.rawurlencode($guild->handle)];

foreach ($paths as $path) {
$this->patch($path, [], fn (array $json): array => self::prepend($json, $commit));
}

Expand Down
12 changes: 11 additions & 1 deletion app/Models/PendingWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Devnull\Data\Commit;
use App\Devnull\Data\CommitBody;
use App\Devnull\Data\DraftImage;
use App\Devnull\Data\Guild;
use App\Devnull\Data\MessageVoice;
use App\Devnull\Data\ScoreCard;
use App\Devnull\Data\User;
Expand All @@ -20,7 +21,7 @@
* message goes to. $payload is what's sent, and for a commit what the
* composer needs to have it back: its body, what it replies to or quotes,
* its poll, its photos with their descriptions, and the draft it was
* stashed under.
* stashed under, and the guild whose board it goes to, if any.
*
* It's queued until it goes, sending while it's on its way, and failed once
* devnull turned it down, when a commit stays for you to edit and a message
Expand Down Expand Up @@ -144,6 +145,14 @@ public function poll(): ?array
return is_array($poll) && is_array($poll['options'] ?? null) && is_int($poll['duration'] ?? null) ? $poll : null;
}

/**
* The guild whose board a new commit goes to, or null for one that goes to your log.
*/
public function guildHandle(): ?string
{
return is_string($this->payload['guild_handle'] ?? null) ? $this->payload['guild_handle'] : null;
}

/**
* The message a Remotes message replies to.
*/
Expand Down Expand Up @@ -216,6 +225,7 @@ public function stagedCommit(User $author): Commit
images: array_map(fn (DraftImage $image, int $index) => $image->asCommitImage($index), $this->images(), array_keys($this->images())),
content: CommitBody::blocks(ScoreCard::withoutRun($this->body()), null, []),
quotedCommitId: $this->quotedCommitId(),
guild: Guild::fromArray(['handle' => $this->guildHandle()]),
scoreCard: ScoreCard::fromCommit($this->body(), $author),
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/NativeComponents/Concerns/DraftsIssues.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ protected function typeIssueCommand(): void
}

/**
* Only a new commit can become an issue, as on the web.
* Only a new commit for your log can become an issue, as on the web, whose guild composer has no commands.
*/
protected function canDraftIssue(): bool
{
return $this->sheetOpen && $this->sheetView === 'compose' && ! $this->scheduling;
return $this->sheetOpen && $this->sheetView === 'compose' && $this->sheetGuild === null && ! $this->scheduling;
}

/**
Expand Down
65 changes: 60 additions & 5 deletions app/NativeComponents/Concerns/OpensCommitSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
* A new commit's draft can become a `/feature` or `/bug` issue, as on the web
* (see DraftsIssues).
*
* A guild's page opens it for a new commit on the guild's board, as the web's
* guild page has its own composer (see composeInGuildSheet()): its own draft,
* `guild:{handle}`, and no issue commands, as on the web. The commit goes to
* the board, not to your log, and if devnull turns it down it goes back only
* to that guild's page (see composerGuild()).
*
* A commit's page can open its reply in the same composer, for the photos and
* the preview the reply bar has no room for (see replyInSheet()). The draft
* is the reply bar's, and goes back to it when the sheet closes.
Expand Down Expand Up @@ -92,6 +98,11 @@ trait OpensCommitSheet
*/
public string $sheetView = 'report';

/**
* The guild whose board the new commit in the sheet goes to, or null for one that goes to your log.
*/
public ?string $sheetGuild = null;

/**
* The reason picked on the report form, or '' until one is.
*/
Expand Down Expand Up @@ -249,6 +260,18 @@ public function composeInSheet(): void
$this->restoreSheetDraft();
}

/**
* A new commit in the sheet for the board of the guild $handle, under its own draft.
*/
protected function composeInGuildSheet(string $handle): void
{
$this->forgetCommitSheet();
$this->sheetView = 'compose';
$this->sheetGuild = $handle;
$this->sheetOpen = true;
$this->restoreSheetDraft();
}

/**
* The web's clock button, in a new commit's composer: it opens "Submit at" under the field, with no time picked,
* or closes it, and the commit goes now again. Its photos or its poll go with it either way, as on the web.
Expand Down Expand Up @@ -335,6 +358,7 @@ public function commitFromSheet(): void
'images' => PendingWrite::imagePayload($this->sheetImages),
'stash' => $stashName,
'composer' => $this->sheetView,
...($this->sheetGuild === null ? [] : ['guild_handle' => $this->sheetGuild]),
]);

if ($write === null) {
Expand Down Expand Up @@ -432,7 +456,7 @@ protected function commitSheetGone(string $view): void
*/
protected function reopenFailedCommit(PendingWrite $write): bool
{
if ($this->sheetOpen || ($write->composer() === 'compose' && ! $this->opensComposer())) {
if ($this->sheetOpen || ($write->composer() === 'compose' && (! $this->opensComposer() || $write->guildHandle() !== $this->composerGuild()))) {
return false;
}

Expand All @@ -448,14 +472,28 @@ protected function reopenFailedCommit(PendingWrite $write): bool
/**
* Edit, on the toast of a commit devnull turned down: its sheet, here if
* the commit it quotes or replies to is showing, or the commit's own page.
* A new commit's sheet opens anywhere it can.
* A new commit's sheet opens anywhere it can but a guild's page, which
* sends it to the Log. One for a guild's board opens only on that guild's
* page, which opens it.
*/
protected function editFailedCommit(PendingWrite $write): void
{
if ($this->openFailedCommit($write)) {
return;
}

if ($write->guildHandle() !== null) {
$this->openInTab('/guilds/'.rawurlencode($write->guildHandle()), ['edit' => $write->id]);

return;
}

if ($write->composer() === 'compose') {
$this->composeInSheet();

return;
}

$for = $write->parentId() ?? $write->quotedCommitId();

if ($for !== null) {
Expand Down Expand Up @@ -502,15 +540,30 @@ protected function opensComposer(): bool
return false;
}

/**
* The guild whose board this screen's composer posts to, or null when it posts to your log. A new commit devnull
* turned down goes back only to a composer for the same place.
*/
protected function composerGuild(): ?string
{
return null;
}

/**
* Opens the sheet a commit devnull turned down was written in, with everything it had (see restoreSheetDraft()).
*/
private function openFailedCommit(PendingWrite $write): bool
{
$for = $write->parentId() ?? $write->quotedCommitId();

$guild = $write->guildHandle();

match ($write->composer()) {
'compose' => $this->composeInSheet(),
'compose' => match (true) {
$guild === null => $this->composerGuild() === null ? $this->composeInSheet() : null,
$guild === $this->composerGuild() => $this->composeInGuildSheet($guild),
default => null,
},
'quote' => $for === null ? null : $this->quoteCommit($for),
'reply' => $for === null ? null : $this->replyInSheet($for),
default => null,
Expand Down Expand Up @@ -549,10 +602,11 @@ private function scheduleFromSheet(string $body, string $stashName): void

$images = $this->sheetImages;
$poll = $this->sheetPollPayload();
$guild = $this->sheetGuild;
$this->sendingSchedule = true;
$this->sheetError = null;

$this->sendInBackground(fn (Client $devnull): SignedRequest => $devnull->signedScheduledCommit($body, $at, $images, $poll), function () use ($me, $stashName, $images): void {
$this->sendInBackground(fn (Client $devnull): SignedRequest => $devnull->signedScheduledCommit($body, $at, $images, $poll, $guild), function () use ($me, $stashName, $images): void {
$this->sendingSchedule = false;
app(ResponseCache::class)->forget(Client::ScheduledCommitsPath);
app(Stash::class)->put($me->id, $stashName, new StashedDraft);
Expand All @@ -571,6 +625,7 @@ private function forgetCommitSheet(): void
$this->sheetOpen = false;
$this->sheetCommit = null;
$this->sheetView = 'report';
$this->sheetGuild = null;
$this->reportReason = '';
$this->reportDetails = '';
$this->sheetBody = '';
Expand All @@ -592,7 +647,7 @@ private function forgetCommitSheet(): void
private function sheetStashName(): ?string
{
return match (true) {
$this->sheetView === 'compose' => 'commit',
$this->sheetView === 'compose' => $this->sheetGuild === null ? 'commit' : 'guild:'.$this->sheetGuild,
$this->sheetView === 'quote' && $this->sheetCommit !== null => 'quote-'.$this->sheetCommit->id,
$this->sheetView === 'reply' && $this->sheetCommit !== null => 'reply-'.$this->sheetCommit->id,
default => null,
Expand Down
13 changes: 8 additions & 5 deletions app/NativeComponents/Concerns/SyncsOutbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,20 @@ protected function sendLeftovers(): void

/**
* The commits on their way that this screen would show, as they stand in for themselves (see
* PendingWrite::stagedCommit()): replies to $parentId, or with null, new commits and quotes. Newest first.
* PendingWrite::stagedCommit()): replies to $parentId, or with null, new commits and quotes, for your log or, with
* $guildHandle, for that guild's board. Newest first.
*
* @return list<Commit>
*/
protected function stagedCommits(?string $parentId): array
protected function stagedCommits(?string $parentId, ?string $guildHandle = null): array
{
$me = $this->me();

if ($me === null) {
return [];
}

return app(Outbox::class)->commitsUnder($parentId)
return app(Outbox::class)->commitsUnder($parentId, $guildHandle)
->reverse()
->map(fn (PendingWrite $write): Commit => $write->stagedCommit($me))
->values()
Expand Down Expand Up @@ -245,6 +246,8 @@ private function writeWent(PendingWrite $write, array $json): void
app(VoiceNotes::class)->discard($write->voice());

if ($write->isCommit()) {
// A post to a guild's board is known by its guild, even when devnull's answer leaves it out.
$data = $write->guildHandle() === null ? $data : ['guild_handle' => $write->guildHandle(), ...$data];
app(ResponseCache::class)->commitAdded($data);
$this->showCommitWent($write, Commit::fromArray($data));

Expand Down Expand Up @@ -333,8 +336,8 @@ private function signWrite(PendingWrite $write): SignedRequest
PendingWrite::Unstar => $devnull->signedWrite('DELETE', $commit),
PendingWrite::Message => $devnull->signedMessage((string) $write->target, $write->body(), $write->client_id, $write->replyToId(), $write->images(), $write->voice()),
default => $write->images() === []
? $devnull->signedCommit($write->body(), $write->parentId(), $write->quotedCommitId(), $write->poll())
: $devnull->signedCommitWithImages($write->body(), $write->images(), $write->parentId(), $write->quotedCommitId()),
? $devnull->signedCommit($write->body(), $write->parentId(), $write->quotedCommitId(), $write->poll(), $write->guildHandle())
: $devnull->signedCommitWithImages($write->body(), $write->images(), $write->parentId(), $write->quotedCommitId(), $write->guildHandle()),
};
}

Expand Down
Loading
Loading