Przeglądaj źródła

Update AccountService, add getMastodon method for mastoapi compatibility

Daniel Supernault 3 lat temu
rodzic
commit
85e4be8172

+ 29 - 0
app/Services/AccountService.php

@@ -33,6 +33,35 @@ class AccountService
 		});	
 	}
 
+	public static function getMastodon($id, $softFail = false)
+	{
+		$account = self::get($id, $softFail);
+		if(!$account) {
+			return null;
+		}
+
+		unset(
+			$account['header_bg'],
+			$account['is_admin'],
+			$account['last_fetched_at'],
+			$account['local'],
+			$account['location'],
+			$account['note_text'],
+			$account['pronouns'],
+			$account['website']
+		);
+
+		$account['avatar_static'] = $account['avatar'];
+		$account['bot'] = false;
+		$account['emojis'] = [];
+		$account['fields'] = [];
+		$account['header'] = url('/storage/headers/missing.png');
+		$account['header_static'] = url('/storage/headers/missing.png');
+		$account['last_status_at'] = null;
+
+		return $account;
+	}
+
 	public static function del($id)
 	{
 		return Cache::forget(self::CACHE_KEY . $id);

+ 2 - 2
app/Transformer/Api/AccountTransformer.php

@@ -25,8 +25,8 @@ class AccountTransformer extends Fractal\TransformerAbstract
 			'acct' => $acct,
 			'display_name' => $profile->name,
 			'locked' => (bool) $profile->is_private,
-			'followers_count' => $profile->followerCount(),
-			'following_count' => $profile->followingCount(),
+			'followers_count' => (int) $profile->followerCount(),
+			'following_count' => (int) $profile->followingCount(),
 			'statuses_count' => (int) $profile->statusCount(),
 			'note' => $profile->bio ?? '',
 			'note_text' => strip_tags($profile->bio),

+ 2 - 2
app/Transformer/Api/Mastodon/v1/AccountTransformer.php

@@ -24,8 +24,8 @@ class AccountTransformer extends Fractal\TransformerAbstract
 			'url' => $profile->url(),
 			'avatar' => $profile->avatarUrl(),
 			'avatar_static' => $profile->avatarUrl(),
-			'header' => '',
-			'header_static' => '',
+			'header' =>  url('/storage/headers/missing.png'),
+			'header_static' =>  url('/storage/headers/missing.png'),
 			'followers_count' => (int) $profile->followerCount(),
 			'following_count' => (int) $profile->followingCount(),
 			'statuses_count' => (int) $profile->statusCount(),