Fix self followers & following hidden

This commit is contained in:
Cemre 2025-01-15 13:40:07 +00:00
parent 393e9a2a74
commit cb5b8f929c
3 changed files with 14 additions and 8 deletions

View file

@ -65,10 +65,10 @@ class Profile extends Model
return $this->hasMany(Status::class); return $this->hasMany(Status::class);
} }
public function followingCount($short = false) public function followingCount($short = false, $isSelf = false)
{ {
$count = Cache::remember('profile:following_count:'.$this->id, now()->addMonths(1), function() { $count = Cache::remember('profile:following_count:'.$this->id, now()->addMonths(1), function() {
if($this->domain == null && $this->user->settings->show_profile_following_count == false) { if(!$isSelf && $this->domain == null && $this->user->settings->show_profile_following_count == false) {
return 0; return 0;
} }
$count = DB::table('followers')->where('profile_id', $this->id)->count(); $count = DB::table('followers')->where('profile_id', $this->id)->count();
@ -82,10 +82,10 @@ class Profile extends Model
return $short ? PrettyNumber::convert($count) : $count; return $short ? PrettyNumber::convert($count) : $count;
} }
public function followerCount($short = false) public function followerCount($short = false, $isSelf = false)
{ {
$count = Cache::remember('profile:follower_count:'.$this->id, now()->addMonths(1), function() { $count = Cache::remember('profile:follower_count:'.$this->id, now()->addMonths(1), function() {
if($this->domain == null && $this->user->settings->show_profile_follower_count == false) { if(!$isSelf && $this->domain == null && $this->user->settings->show_profile_follower_count == false) {
return 0; return 0;
} }
$count = DB::table('followers')->where('following_id', $this->id)->count(); $count = DB::table('followers')->where('following_id', $this->id)->count();

View file

@ -15,6 +15,9 @@ class AccountWithStatusesTransformer extends Fractal\TransformerAbstract
public function transform(Profile $profile) public function transform(Profile $profile)
{ {
$auth = Auth::check();
$isSelf = $auth && $profile->id == Auth::user()->profile->id;
$local = $profile->domain == null; $local = $profile->domain == null;
$is_admin = !$local ? false : $profile->user->is_admin; $is_admin = !$local ? false : $profile->user->is_admin;
$acct = $local ? $profile->username : substr($profile->username, 1); $acct = $local ? $profile->username : substr($profile->username, 1);
@ -26,8 +29,8 @@ class AccountWithStatusesTransformer extends Fractal\TransformerAbstract
'display_name' => $profile->name, 'display_name' => $profile->name,
'locked' => (bool) $profile->is_private, 'locked' => (bool) $profile->is_private,
'followers_count' => $profile->followerCount(), 'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(), 'following_count' => $profile->followingCount($isSelf),
'statuses_count' => (int) $profile->statusCount(), 'statuses_count' => (int) $profile->statusCount($isSelf),
'note' => $profile->bio ?? '', 'note' => $profile->bio ?? '',
'url' => $profile->url(), 'url' => $profile->url(),
'avatar' => $profile->avatarUrl(), 'avatar' => $profile->avatarUrl(),

View file

@ -10,6 +10,9 @@ class AccountTransformer extends Fractal\TransformerAbstract
{ {
public function transform(Profile $profile) public function transform(Profile $profile)
{ {
$auth = Auth::check();
$isSelf = $auth && $profile->id == Auth::user()->profile->id;
$local = $profile->domain == null; $local = $profile->domain == null;
$username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0]; $username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
return [ return [
@ -26,8 +29,8 @@ class AccountTransformer extends Fractal\TransformerAbstract
'avatar_static' => $profile->avatarUrl(), 'avatar_static' => $profile->avatarUrl(),
'header' => url('/storage/headers/missing.png'), 'header' => url('/storage/headers/missing.png'),
'header_static' => url('/storage/headers/missing.png'), 'header_static' => url('/storage/headers/missing.png'),
'followers_count' => (int) $profile->followerCount(), 'followers_count' => (int) $profile->followerCount($isSelf),
'following_count' => (int) $profile->followingCount(), 'following_count' => (int) $profile->followingCount($isSelf),
'statuses_count' => (int) $profile->statusCount(), 'statuses_count' => (int) $profile->statusCount(),
'last_status_at' => optional($profile->last_status_at)->toJSON(), 'last_status_at' => optional($profile->last_status_at)->toJSON(),
'emojis' => [], 'emojis' => [],