Update StatusService

This commit is contained in:
Daniel Supernault 2022-04-18 01:59:27 -06:00
parent 2b188acff3
commit cc6b78c436
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
4 changed files with 11 additions and 6 deletions

View file

@ -1867,17 +1867,17 @@ class ApiV1Controller extends Controller
if(config('database.default') == 'pgsql') { if(config('database.default') == 'pgsql') {
$dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) { $dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) {
return $q->whereIsHidden(false)->whereToId($pid)->orWhere('from_id', $pid); return $q->whereIsHidden(false)->where('to_id', $pid)->orWhere('from_id', $pid);
}) })
->when($scope === 'sent', function($q, $scope) use($pid) { ->when($scope === 'sent', function($q, $scope) use($pid) {
return $q->whereFromId($pid); return $q->whereFromId($pid)->groupBy(['to_id', 'id']);
}) })
->when($scope === 'requests', function($q, $scope) use($pid) { ->when($scope === 'requests', function($q, $scope) use($pid) {
return $q->whereToId($pid)->whereIsHidden(true); return $q->whereToId($pid)->whereIsHidden(true);
}); });
} else { } else {
$dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) { $dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) {
return $q->whereIsHidden(false)->whereToId($pid)->orWhere('from_id', $pid)->groupBy('to_id'); return $q->whereIsHidden(false)->where('to_id', $pid)->orWhere('from_id', $pid);
}) })
->when($scope === 'sent', function($q, $scope) use($pid) { ->when($scope === 'sent', function($q, $scope) use($pid) {
return $q->whereFromId($pid)->groupBy('to_id'); return $q->whereFromId($pid)->groupBy('to_id');
@ -1887,7 +1887,7 @@ class ApiV1Controller extends Controller
}); });
} }
$dms = $dms->latest() $dms = $dms->orderByDesc('created_at')
->simplePaginate($limit) ->simplePaginate($limit)
->map(function($dm) use($pid) { ->map(function($dm) use($pid) {
$from = $pid == $dm->to_id ? $dm->from_id : $dm->to_id; $from = $pid == $dm->to_id ? $dm->from_id : $dm->to_id;

View file

@ -19,6 +19,11 @@ class StatusLabelService
} }
return Cache::remember(self::CACHE_KEY . $status->id, now()->addDays(7), function() use($status) { return Cache::remember(self::CACHE_KEY . $status->id, now()->addDays(7), function() use($status) {
if(!$status->caption) {
return [
'covid' => false
];
}
return [ return [
'covid' => Str::of(strtolower($status->caption))->contains(['covid','corona', 'coronavirus', 'vaccine', 'vaxx', 'vaccination', 'plandemic']) 'covid' => Str::of(strtolower($status->caption))->contains(['covid','corona', 'coronavirus', 'vaccine', 'vaxx', 'vaccination', 'plandemic'])
]; ];

View file

@ -131,7 +131,7 @@ class StatusService
$fractal = new Fractal\Manager(); $fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer()); $fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($status, new StatusTransformer()); $resource = new Fractal\Resource\Item($status, new StatusStatelessTransformer());
return $fractal->createData($resource)->toArray(); return $fractal->createData($resource)->toArray();
} }

View file

@ -30,7 +30,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
'following_count' => (int) $profile->followingCount(), 'following_count' => (int) $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(), 'statuses_count' => (int) $profile->statusCount(),
'note' => $profile->bio ?? '', 'note' => $profile->bio ?? '',
'note_text' => strip_tags($profile->bio), 'note_text' => $profile->bio ? strip_tags($profile->bio) : null,
'url' => $profile->url(), 'url' => $profile->url(),
'avatar' => $profile->avatarUrl(), 'avatar' => $profile->avatarUrl(),
'website' => $profile->website, 'website' => $profile->website,