mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-22 21:13:16 +00:00
Merge pull request #845 from pixelfed/frontend-ui-refactor
Frontend ui refactor
This commit is contained in:
commit
bc9e511aa2
3 changed files with 102 additions and 1 deletions
58
app/Services/FollowerService.php
Normal file
58
app/Services/FollowerService.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Redis;
|
||||
|
||||
use App\{
|
||||
Follower,
|
||||
Profile
|
||||
};
|
||||
|
||||
class FollowerService {
|
||||
|
||||
protected $profile;
|
||||
protected $follower_prefix;
|
||||
protected $following_prefix;
|
||||
|
||||
public static function build()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function profile(Profile $profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->follower_prefix = config('cache.prefix').':profile:followers:'.$profile->id;
|
||||
$this->following_prefix = config('cache.prefix').':profile:following:'.$profile->id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function followers($limit = 100, $offset = 0)
|
||||
{
|
||||
if(Redis::llen($this->follower_prefix) == 0) {
|
||||
$followers = $this->profile->followers;
|
||||
$followers->map(function($i) {
|
||||
Redis::lpush($this->follower_prefix, $i->id);
|
||||
});
|
||||
return $followers;
|
||||
} else {
|
||||
return Redis::lrange($this->follower_prefix, $offset, $limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function following($limit = 100, $offset = 0)
|
||||
{
|
||||
if(Redis::llen($this->following_prefix) == 0) {
|
||||
$following = $this->profile->following;
|
||||
$following->map(function($i) {
|
||||
Redis::lpush($this->following_prefix, $i->id);
|
||||
});
|
||||
return $following;
|
||||
} else {
|
||||
return Redis::lrange($this->following_prefix, $offset, $limit);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
43
app/Services/ProfileService.php
Normal file
43
app/Services/ProfileService.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Cache, Redis;
|
||||
|
||||
use App\{
|
||||
Follower,
|
||||
Profile
|
||||
};
|
||||
|
||||
class ProfileService {
|
||||
|
||||
protected $profile;
|
||||
protected $profile_prefix;
|
||||
|
||||
public static function build()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function profile(Profile $profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->profile_prefix = 'profile:model:'.$profile->id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function profileId($id)
|
||||
{
|
||||
return Cache::rememberForever('profile:model:'.$id, function() use($id) {
|
||||
return Profile::findOrFail($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return Cache::rememberForever($this->profile_prefix, function() {
|
||||
return $this->profile;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -31,7 +31,7 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
|||
public function includeStatus(Notification $notification)
|
||||
{
|
||||
$item = $notification->item;
|
||||
if(get_class($item) === 'App\Status') {
|
||||
if(is_object($item) && get_class($item) === 'App\Status') {
|
||||
return $this->item($item, new StatusTransformer());
|
||||
} else {
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue