Browse Source

Update StatusService

Daniel Supernault 3 years ago
parent
commit
cc6b78c436

+ 4 - 4
app/Http/Controllers/Api/ApiV1Controller.php

@@ -1867,17 +1867,17 @@ class ApiV1Controller extends Controller
 
 		if(config('database.default') == 'pgsql') {
 			$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) {
-					return $q->whereFromId($pid);
+					return $q->whereFromId($pid)->groupBy(['to_id', 'id']);
 				})
 				->when($scope === 'requests', function($q, $scope) use($pid) {
 					return $q->whereToId($pid)->whereIsHidden(true);
 				});
 		} else {
 			$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) {
 					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)
 			->map(function($dm) use($pid) {
 				$from = $pid == $dm->to_id ? $dm->from_id : $dm->to_id;

+ 5 - 0
app/Services/StatusLabelService.php

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

+ 1 - 1
app/Services/StatusService.php

@@ -131,7 +131,7 @@ class StatusService
 
 		$fractal = new Fractal\Manager();
 		$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();
 	}
 

+ 1 - 1
app/Transformer/Api/AccountTransformer.php

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