소스 검색

Update follower counts on follow_request approval

Daniel Supernault 3 년 전
부모
커밋
e97900a060
2개의 변경된 파일41개의 추가작업 그리고 18개의 파일을 삭제
  1. 21 11
      app/Http/Controllers/AccountController.php
  2. 20 7
      app/Http/Controllers/Api/ApiV1Controller.php

+ 21 - 11
app/Http/Controllers/AccountController.php

@@ -393,17 +393,27 @@ class AccountController extends Controller
 
 		switch ($action) {
 			case 'accept':
-			$follow = new Follower();
-			$follow->profile_id = $follower->id;
-			$follow->following_id = $pid;
-			$follow->save();
-
-            if($follower->domain != null && $follower->private_key === null) {
-                FollowAcceptPipeline::dispatch($followRequest);
-            } else {
-                FollowPipeline::dispatch($follow);
-                $followRequest->delete();
-            }
+				$follow = new Follower();
+				$follow->profile_id = $follower->id;
+				$follow->following_id = $pid;
+				$follow->save();
+
+				$profile = Profile::findOrFail($pid);
+				$profile->followers_count++;
+				$profile->save();
+				AccountService::del($profile->id);
+
+				$profile = Profile::findOrFail($follower->id);
+				$profile->following_count++;
+				$profile->save();
+				AccountService::del($profile->id);
+
+				if($follower->domain != null && $follower->private_key === null) {
+					FollowAcceptPipeline::dispatch($followRequest);
+				} else {
+					FollowPipeline::dispatch($follow);
+					$followRequest->delete();
+				}
 			break;
 
 			case 'reject':

+ 20 - 7
app/Http/Controllers/Api/ApiV1Controller.php

@@ -1160,18 +1160,21 @@ class ApiV1Controller extends Controller
 	{
 		abort_if(!$request->user(), 403);
 		$this->validate($request, [
-			'limit' => 'sometimes|integer|min:1|max:40'
+			'limit' => 'sometimes|integer|min:1|max:100'
 		]);
 		$user = $request->user();
 
-		$followRequests = FollowRequest::whereFollowingId($user->profile->id)
+		$res = FollowRequest::whereFollowingId($user->profile->id)
 			->limit($request->input('limit', 40))
-			->pluck('follower_id');
-
-		$profiles = Profile::find($followRequests);
+			->pluck('follower_id')
+			->map(function($id) {
+				return AccountService::getMastodon($id, true);
+			})
+			->filter(function($acct) {
+				return $acct && isset($acct['id']);
+			})
+			->values();
 
-		$resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
-		$res = $this->fractal->createData($resource)->toArray();
 		return $this->json($res);
 	}
 
@@ -1204,6 +1207,16 @@ class ApiV1Controller extends Controller
 		$follow->following_id = $pid;
 		$follow->save();
 
+		$profile = Profile::findOrFail($pid);
+		$profile->followers_count++;
+		$profile->save();
+		AccountService::del($profile->id);
+
+		$profile = Profile::findOrFail($follower->id);
+		$profile->following_count++;
+		$profile->save();
+		AccountService::del($profile->id);
+
 		if($follower->domain != null && $follower->private_key === null) {
 			FollowAcceptPipeline::dispatch($followRequest);
 		} else {