瀏覽代碼

Update StoryController, fix postgres bug. Fixes #2904

Daniel Supernault 4 年之前
父節點
當前提交
00c32360ae
共有 1 個文件被更改,包括 22 次插入7 次删除
  1. 22 7
      app/Http/Controllers/StoryController.php

+ 22 - 7
app/Http/Controllers/StoryController.php

@@ -36,13 +36,28 @@ class StoryController extends StoryComposeController
 		abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
 		$pid = $request->user()->profile_id;
 
-		$s = Story::select('stories.*', 'followers.following_id')
-			->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
-			->where('followers.profile_id', $pid)
-			->where('stories.active', true)
-			->groupBy('followers.following_id')
-			->orderByDesc('id')
-			->get();
+		if(config('database.default') == 'pgsql') {
+			$s = Story::select('stories.*', 'followers.following_id')
+				->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
+				->where('followers.profile_id', $pid)
+				->where('stories.active', true)
+				->get()
+				->map(function($s) {
+					$r  = new \StdClass;
+					$r->id = $s->id;
+					$r->profile_id = $s->profile_id;
+					return $r;
+				})
+				->unique('profile_id');
+		} else {
+			$s = Story::select('stories.*', 'followers.following_id')
+				->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
+				->where('followers.profile_id', $pid)
+				->where('stories.active', true)
+				->groupBy('followers.following_id')
+				->orderByDesc('id')
+				->get();
+		}
 
 		$res = $s->map(function($s) use($pid) {
 			$profile = AccountService::get($s->profile_id);