mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add ReblogService, improve reblogged state for api entities
This commit is contained in:
parent
a7d715517d
commit
6cfd6be523
5 changed files with 50 additions and 7 deletions
|
@ -65,6 +65,7 @@ use App\Services\{
|
||||||
NotificationService,
|
NotificationService,
|
||||||
MediaPathService,
|
MediaPathService,
|
||||||
PublicTimelineService,
|
PublicTimelineService,
|
||||||
|
ReblogService,
|
||||||
RelationshipService,
|
RelationshipService,
|
||||||
SearchApiV2Service,
|
SearchApiV2Service,
|
||||||
StatusService,
|
StatusService,
|
||||||
|
@ -1646,6 +1647,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
if($pid) {
|
if($pid) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
|
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($pid, $status['id']);
|
||||||
}
|
}
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
|
@ -1676,6 +1678,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
if($pid) {
|
if($pid) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
|
$status['favourited'] = (bool) LikeService::liked($pid, $s['id']);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($pid, $status['id']);
|
||||||
}
|
}
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
|
@ -1798,6 +1801,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
if($user) {
|
if($user) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $status['id']);
|
||||||
}
|
}
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
|
@ -1839,7 +1843,7 @@ class ApiV1Controller extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$res['favourited'] = LikeService::liked($user->profile_id, $res['id']);
|
$res['favourited'] = LikeService::liked($user->profile_id, $res['id']);
|
||||||
$res['reblogged'] = false;
|
$res['reblogged'] = ReblogService::get($user->profile_id, $res['id']);
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2238,7 +2242,7 @@ class ApiV1Controller extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id);
|
||||||
|
ReblogService::add($user->profile_id, $status->id);
|
||||||
$res = StatusService::getMastodon($status->id);
|
$res = StatusService::getMastodon($status->id);
|
||||||
$res['reblogged'] = true;
|
$res['reblogged'] = true;
|
||||||
|
|
||||||
|
@ -2278,6 +2282,7 @@ class ApiV1Controller extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
UndoSharePipeline::dispatch($reblog);
|
UndoSharePipeline::dispatch($reblog);
|
||||||
|
ReblogService::del($user->profile_id, $status->id);
|
||||||
|
|
||||||
$res = StatusService::getMastodon($status->id);
|
$res = StatusService::getMastodon($status->id);
|
||||||
$res['reblogged'] = true;
|
$res['reblogged'] = true;
|
||||||
|
|
|
@ -32,6 +32,7 @@ use App\Services\{
|
||||||
LikeService,
|
LikeService,
|
||||||
PublicTimelineService,
|
PublicTimelineService,
|
||||||
ProfileService,
|
ProfileService,
|
||||||
|
ReblogService,
|
||||||
RelationshipService,
|
RelationshipService,
|
||||||
StatusService,
|
StatusService,
|
||||||
SnowflakeService,
|
SnowflakeService,
|
||||||
|
@ -329,6 +330,7 @@ class PublicApiController extends Controller
|
||||||
}
|
}
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
->filter(function($s) use($filtered) {
|
->filter(function($s) use($filtered) {
|
||||||
|
@ -372,6 +374,7 @@ class PublicApiController extends Controller
|
||||||
}
|
}
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
->filter(function($s) use($filtered) {
|
->filter(function($s) use($filtered) {
|
||||||
|
@ -402,7 +405,7 @@ class PublicApiController extends Controller
|
||||||
if($user) {
|
if($user) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
||||||
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $k);
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $k);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $k);
|
||||||
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
|
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
|
||||||
}
|
}
|
||||||
return $status;
|
return $status;
|
||||||
|
@ -524,6 +527,7 @@ class PublicApiController extends Controller
|
||||||
}
|
}
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
->filter(function($s) use($filtered) {
|
->filter(function($s) use($filtered) {
|
||||||
|
@ -569,6 +573,7 @@ class PublicApiController extends Controller
|
||||||
}
|
}
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
->filter(function($s) use($filtered) {
|
->filter(function($s) use($filtered) {
|
||||||
|
@ -623,6 +628,8 @@ class PublicApiController extends Controller
|
||||||
->map(function($s) use ($user) {
|
->map(function($s) use ($user) {
|
||||||
$status = StatusService::get($s->id);
|
$status = StatusService::get($s->id);
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
});
|
});
|
||||||
$res = $timeline->toArray();
|
$res = $timeline->toArray();
|
||||||
|
@ -646,6 +653,8 @@ class PublicApiController extends Controller
|
||||||
->map(function($s) use ($user) {
|
->map(function($s) use ($user) {
|
||||||
$status = StatusService::get($s->id);
|
$status = StatusService::get($s->id);
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
|
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
|
||||||
|
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
});
|
});
|
||||||
$res = $timeline->toArray();
|
$res = $timeline->toArray();
|
||||||
|
|
|
@ -25,6 +25,7 @@ use Illuminate\Support\Str;
|
||||||
use App\Services\HashidService;
|
use App\Services\HashidService;
|
||||||
use App\Services\StatusService;
|
use App\Services\StatusService;
|
||||||
use App\Util\Media\License;
|
use App\Util\Media\License;
|
||||||
|
use App\Services\ReblogService;
|
||||||
|
|
||||||
class StatusController extends Controller
|
class StatusController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -245,6 +246,7 @@ class StatusController extends Controller
|
||||||
->get();
|
->get();
|
||||||
foreach ($shares as $share) {
|
foreach ($shares as $share) {
|
||||||
UndoSharePipeline::dispatch($share);
|
UndoSharePipeline::dispatch($share);
|
||||||
|
ReblogService::del($profile->id, $status->id);
|
||||||
$count--;
|
$count--;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -255,6 +257,7 @@ class StatusController extends Controller
|
||||||
$share->save();
|
$share->save();
|
||||||
$count++;
|
$count++;
|
||||||
SharePipeline::dispatch($share);
|
SharePipeline::dispatch($share);
|
||||||
|
ReblogService::add($profile->id, $status->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id);
|
Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id);
|
||||||
|
|
29
app/Services/ReblogService.php
Normal file
29
app/Services/ReblogService.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Redis;
|
||||||
|
|
||||||
|
class ReblogService
|
||||||
|
{
|
||||||
|
const CACHE_KEY = 'pf:services:reblogs:';
|
||||||
|
|
||||||
|
public static function get($profileId, $statusId)
|
||||||
|
{
|
||||||
|
if (!Redis::zcard(self::CACHE_KEY . $profileId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Redis::zscore(self::CACHE_KEY . $profileId, $statusId) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($profileId, $statusId)
|
||||||
|
{
|
||||||
|
return Redis::zadd(self::CACHE_KEY . $profileId, $statusId, $statusId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function del($profileId, $statusId)
|
||||||
|
{
|
||||||
|
return Redis::zrem(self::CACHE_KEY . $profileId, $statusId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -165,10 +165,7 @@ class StatusService
|
||||||
public static function isShared($id, $pid = null)
|
public static function isShared($id, $pid = null)
|
||||||
{
|
{
|
||||||
return $pid ?
|
return $pid ?
|
||||||
DB::table('statuses')
|
ReblogService::get($pid, $id) :
|
||||||
->where('reblog_of_id', $id)
|
|
||||||
->where('profile_id', $pid)
|
|
||||||
->exists() :
|
|
||||||
false;
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue