Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
puklipo committed Dec 26, 2024
1 parent cf8e714 commit 27003bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/Labeler/Labeler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use InvalidArgumentException;
use Revolution\Bluesky\Core\CBOR;
use Revolution\Bluesky\Core\CBOR\AtBytes;
use Revolution\Bluesky\Core\CBOR\MapKeySort;
use Revolution\Bluesky\Crypto\K256;
use Revolution\Bluesky\Crypto\Signature;
use Revolution\Bluesky\FeedGenerator\ValidateAuth;
Expand Down Expand Up @@ -161,4 +162,15 @@ public static function signLabel(UnsignedLabel $unsigned): array

return [$label, $sign];
}

public static function formatLabel(array $label): array
{
return collect($label)
->put('ver', self::VERSION)
->except('id')
->reject(fn ($value) => is_null($value))
->reject(fn ($value, $key) => $key === 'neg' && $value === false)
->sortKeysUsing(new MapKeySort())
->toArray();
}
}
7 changes: 1 addition & 6 deletions src/Labeler/SavedLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ public function toArray(): array

public function toEmit(): array
{
return collect($this->toArray())
->except('id')
->reject(fn ($value) => is_null($value))
->reject(fn ($value, $key) => $key === 'neg' && $value === false)
->sortKeysUsing(new CBOR\MapKeySort())
->toArray();
return Labeler::formatLabel($this->toArray());
}

public function toBytes(): string
Expand Down
6 changes: 5 additions & 1 deletion src/Labeler/SubscribeLabelMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ public function toBytes(): string
{
$header = ['op' => 1, 't' => '#labels'];

$labels = collect($this->labels)
->map(fn ($label) => Labeler::formatLabel($label))
->toArray();

$body = [
'seq' => $this->seq,
'labels' => $this->labels,
'labels' => $labels,
];

return CBOR::encode($header).CBOR::encode($body);
Expand Down

0 comments on commit 27003bd

Please sign in to comment.