mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update Profile model, added recommendedFollowers() and keyId() methods
This commit is contained in:
parent
d9ec94ba65
commit
305fd10519
1 changed files with 32 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use Storage;
|
||||
use Auth, Storage;
|
||||
use App\Util\Lexer\PrettyNumber;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
@ -138,4 +138,35 @@ class Profile extends Model
|
|||
{
|
||||
return $this->statuses()->whereHas('media')->count();
|
||||
}
|
||||
|
||||
public function recommendFollowers()
|
||||
{
|
||||
$follows = $this->following()->pluck('followers.id');
|
||||
$following = $this->following()
|
||||
->orderByRaw('rand()')
|
||||
->take(3)
|
||||
->pluck('following_id');
|
||||
$following->push(Auth::id());
|
||||
$following = Follower::whereNotIn('profile_id', $follows)
|
||||
->whereNotIn('following_id', $following)
|
||||
->whereNotIn('following_id', $follows)
|
||||
->whereIn('profile_id', $following)
|
||||
->orderByRaw('rand()')
|
||||
->limit(3)
|
||||
->pluck('following_id');
|
||||
$recommended = [];
|
||||
foreach($following as $follow) {
|
||||
$recommended[] = Profile::findOrFail($follow);
|
||||
}
|
||||
|
||||
return $recommended;
|
||||
}
|
||||
|
||||
public function keyId()
|
||||
{
|
||||
if($this->remote_url) {
|
||||
return;
|
||||
}
|
||||
return $this->permalink('#main-key');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue