Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Consolidate post creation through build() and remove deprecated methods

+21 -136
+21 -136
src/Client/Records/PostRecordClient.php
··· 4 4 5 5 use DateTimeInterface; 6 6 use SocialDept\AtpClient\Attributes\ScopedEndpoint; 7 + use SocialDept\AtpClient\Builders\PostBuilder; 7 8 use SocialDept\AtpClient\Client\Requests\Request; 8 9 use SocialDept\AtpClient\Contracts\Recordable; 9 10 use SocialDept\AtpClient\Data\StrongRef; ··· 14 15 15 16 class PostRecordClient extends Request 16 17 { 18 + /** 19 + * Create a new post builder bound to this client 20 + */ 21 + public function build(): PostBuilder 22 + { 23 + return PostBuilder::make()->for($this); 24 + } 25 + 17 26 /** 18 27 * Create a post 19 28 * ··· 41 50 $record = $content; 42 51 } 43 52 44 - // Add optional fields 45 - if ($embed) { 46 - $record['embed'] = $embed; 47 - } 48 - if ($reply) { 49 - $record['reply'] = $reply; 53 + // Add optional fields (only for non-Recordable inputs) 54 + if (! ($content instanceof Recordable)) { 55 + if ($embed) { 56 + $record['embed'] = $embed; 57 + } 58 + if ($reply) { 59 + $record['reply'] = $reply; 60 + } 61 + if ($langs) { 62 + $record['langs'] = $langs; 63 + } 50 64 } 51 - if ($langs) { 52 - $record['langs'] = $langs; 53 - } 65 + 54 66 if (! isset($record['createdAt'])) { 55 67 $record['createdAt'] = ($createdAt ?? now())->format('c'); 56 68 } ··· 127 139 return PostView::fromArray($response->value); 128 140 } 129 141 130 - /** 131 - * Create a reply to another post 132 - * 133 - * @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create) 134 - */ 135 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')] 136 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')] 137 - public function reply( 138 - StrongRef $parent, 139 - StrongRef $root, 140 - string|array|Recordable $content, 141 - ?array $facets = null, 142 - ?array $embed = null, 143 - ?array $langs = null, 144 - ?DateTimeInterface $createdAt = null 145 - ): StrongRef { 146 - $reply = [ 147 - 'parent' => $parent->toArray(), 148 - 'root' => $root->toArray(), 149 - ]; 150 - 151 - return $this->create( 152 - content: $content, 153 - facets: $facets, 154 - embed: $embed, 155 - reply: $reply, 156 - langs: $langs, 157 - createdAt: $createdAt 158 - ); 159 - } 160 - 161 - /** 162 - * Create a quote post (post with embedded post) 163 - * 164 - * @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create) 165 - */ 166 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')] 167 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')] 168 - public function quote( 169 - StrongRef $quotedPost, 170 - string|array|Recordable $content, 171 - ?array $facets = null, 172 - ?array $langs = null, 173 - ?DateTimeInterface $createdAt = null 174 - ): StrongRef { 175 - $embed = [ 176 - '$type' => 'app.bsky.embed.record', 177 - 'record' => $quotedPost->toArray(), 178 - ]; 179 - 180 - return $this->create( 181 - content: $content, 182 - facets: $facets, 183 - embed: $embed, 184 - langs: $langs, 185 - createdAt: $createdAt 186 - ); 187 - } 188 - 189 - /** 190 - * Create a post with images 191 - * 192 - * @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create) 193 - */ 194 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')] 195 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')] 196 - public function withImages( 197 - string|array|Recordable $content, 198 - array $images, 199 - ?array $facets = null, 200 - ?array $langs = null, 201 - ?DateTimeInterface $createdAt = null 202 - ): StrongRef { 203 - $embed = [ 204 - '$type' => 'app.bsky.embed.images', 205 - 'images' => $images, 206 - ]; 207 - 208 - return $this->create( 209 - content: $content, 210 - facets: $facets, 211 - embed: $embed, 212 - langs: $langs, 213 - createdAt: $createdAt 214 - ); 215 - } 216 - 217 - /** 218 - * Create a post with external link embed 219 - * 220 - * @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create) 221 - */ 222 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')] 223 - #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')] 224 - public function withLink( 225 - string|array|Recordable $content, 226 - string $uri, 227 - string $title, 228 - string $description, 229 - ?string $thumbBlob = null, 230 - ?array $facets = null, 231 - ?array $langs = null, 232 - ?DateTimeInterface $createdAt = null 233 - ): StrongRef { 234 - $external = [ 235 - 'uri' => $uri, 236 - 'title' => $title, 237 - 'description' => $description, 238 - ]; 239 - 240 - if ($thumbBlob) { 241 - $external['thumb'] = $thumbBlob; 242 - } 243 - 244 - $embed = [ 245 - '$type' => 'app.bsky.embed.external', 246 - 'external' => $external, 247 - ]; 248 - 249 - return $this->create( 250 - content: $content, 251 - facets: $facets, 252 - embed: $embed, 253 - langs: $langs, 254 - createdAt: $createdAt 255 - ); 256 - } 257 142 }