Laravel AT Protocol Client (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpClient\Client\Records;
4
5use DateTimeInterface;
6use SocialDept\AtpClient\Attributes\ScopedEndpoint;
7use SocialDept\AtpClient\Client\Requests\Request;
8use SocialDept\AtpClient\Data\Record;
9use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse;
10use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DeleteRecordResponse;
11use SocialDept\AtpClient\Enums\Nsid\BskyGraph;
12use SocialDept\AtpClient\Enums\Scope;
13
14class FollowRecordClient extends Request
15{
16 /**
17 * Follow a user
18 *
19 * @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.graph.follow?action=create)
20 */
21 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
22 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=create')]
23 public function create(
24 string $subject,
25 ?DateTimeInterface $createdAt = null
26 ): CreateRecordResponse {
27 $record = [
28 '$type' => BskyGraph::Follow->value,
29 'subject' => $subject, // DID
30 'createdAt' => ($createdAt ?? now())->format('c'),
31 ];
32
33 return $this->atp->atproto->repo->createRecord(
34 collection: BskyGraph::Follow,
35 record: $record
36 );
37 }
38
39 /**
40 * Unfollow a user (delete follow record)
41 *
42 * @requires transition:generic OR (rpc:com.atproto.repo.deleteRecord AND repo:app.bsky.graph.follow?action=delete)
43 */
44 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')]
45 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=delete')]
46 public function delete(string $rkey): DeleteRecordResponse
47 {
48 return $this->atp->atproto->repo->deleteRecord(
49 collection: BskyGraph::Follow,
50 rkey: $rkey
51 );
52 }
53
54 /**
55 * Get a follow record
56 *
57 * @requires transition:generic (rpc:com.atproto.repo.getRecord)
58 */
59 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
60 public function get(string $rkey, ?string $cid = null): Record
61 {
62 $response = $this->atp->atproto->repo->getRecord(
63 repo: $this->atp->client->session()->did(),
64 collection: BskyGraph::Follow,
65 rkey: $rkey,
66 cid: $cid
67 );
68
69 return Record::fromArrayRaw($response->toArray());
70 }
71}