|
@@ -66,7 +66,8 @@ class AccountController implements IRouteController
|
|
|
"following" => rand(5, 6243),
|
|
|
"myself" => false,
|
|
|
"links" => [],
|
|
|
- "socialCredit" => rand(-20223, 20223)
|
|
|
+ "socialCredit" => rand(-20223, 20223),
|
|
|
+ "followed" => false
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -86,8 +87,10 @@ class AccountController implements IRouteController
|
|
|
$links = [];
|
|
|
}
|
|
|
|
|
|
+ $followed = new Follow(followee_id: $id, follower_id: get_token_id(request()))->Exists();
|
|
|
|
|
|
CORSHelper();
|
|
|
+
|
|
|
return api_json([
|
|
|
"id" => $id,
|
|
|
"username" => $account->username,
|
|
@@ -97,7 +100,8 @@ class AccountController implements IRouteController
|
|
|
"following" => $following,
|
|
|
"myself" => $id == get_token_id(request()),
|
|
|
"links" => $links,
|
|
|
- "socialCredit" => $account->social_credit
|
|
|
+ "socialCredit" => $account->social_credit,
|
|
|
+ "followed" => $followed
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -194,7 +198,7 @@ class AccountController implements IRouteController
|
|
|
$response = response();
|
|
|
$response->header("Content-Type: $mime");
|
|
|
$response->header("Content-Length: $picture_size");
|
|
|
- $response->header("Cache-Control: max-age=3600, public");
|
|
|
+ $response->header("Cache-Control: max-age=1800, public");
|
|
|
|
|
|
return $picture_contents;
|
|
|
}
|
|
@@ -328,6 +332,7 @@ class AccountController implements IRouteController
|
|
|
picture_hash: $picture_hash ?? $old_account->picture_hash,
|
|
|
verified: $old_account->verified,
|
|
|
bio: $bio ?? $old_account->bio,
|
|
|
+ social_credit: $old_account->social_credit,
|
|
|
);
|
|
|
|
|
|
CORSHelper();
|
|
@@ -338,6 +343,7 @@ class AccountController implements IRouteController
|
|
|
"pictureHash" => in_array($new_account->picture_hash, $valid_picture_hash_list) ? $new_account->picture_hash : null,
|
|
|
"bio" => $new_account->bio,
|
|
|
"verified" => $new_account->verified,
|
|
|
+ "social_credit" => $old_account->social_credit,
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -447,6 +453,28 @@ class AccountController implements IRouteController
|
|
|
return api_json($accounts);
|
|
|
}
|
|
|
|
|
|
+ public static function follow($id): string {
|
|
|
+ $signed_in = signed_in(request());
|
|
|
+ if(!$signed_in) throw new UnauthenticatedException(0, 401);
|
|
|
+ $follower_id = get_token_id(request());
|
|
|
+
|
|
|
+ $message = "Successful";
|
|
|
+ $successful = true;
|
|
|
+ $follow = new Follow(follower_id: $follower_id, followee_id: $id);
|
|
|
+ if($follow->Exists()) {
|
|
|
+ $successful = false;
|
|
|
+ $message = "You already follow this account...";
|
|
|
+ } else {
|
|
|
+ $follow->Save();
|
|
|
+ }
|
|
|
+
|
|
|
+ CORSHelper();
|
|
|
+ return api_json([
|
|
|
+ "successful" => $successful,
|
|
|
+ "message" => $message,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
public static function RegisterRoutes(): void
|
|
|
{
|
|
|
SimpleRouter::group([
|
|
@@ -459,6 +487,7 @@ class AccountController implements IRouteController
|
|
|
SimpleRouter::get("/{id}/picture", [AccountController::class, "getPicture"]);
|
|
|
//SimpleRouter::get("/{id}/followers", [AccountController::class, "getFollowers"]);
|
|
|
//SimpleRouter::get("/{id}/following", [AccountController::class, "getFollowing"]);
|
|
|
+ SimpleRouter::post("/{id}/follow", [AccountController::class, "follow"]);
|
|
|
SimpleRouter::post("/token", [AccountController::class, "getToken"]);
|
|
|
SimpleRouter::post("/update", [AccountController::class, "updateAccount"]);
|
|
|
SimpleRouter::post("/addLink", [AccountController::class, "addLink"]);
|