-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return UserRelation instead of UserCompact for friends API #7768
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
use Auth; | ||
use Request; | ||
|
||
/** | ||
* @group Friends | ||
*/ | ||
class FriendsController extends Controller | ||
{ | ||
public function __construct() | ||
|
@@ -30,8 +33,96 @@ public function __construct() | |
return parent::__construct(); | ||
} | ||
|
||
/** | ||
* Get Friends | ||
* | ||
* Returns the authenticated user's friends list. | ||
* | ||
* --- | ||
* | ||
* ### Response Format | ||
* | ||
* A collection of [UserRelation](#userrelation) objects with `target` included. `target`s include `country`, `cover`, `groups`, and `support_level`. | ||
* | ||
* @response [ | ||
* { | ||
* "target_id": 2, | ||
* "relation_type": "friend", | ||
* "mutual": false, | ||
* "target": { | ||
* "avatar_url": "https://a.ppy.sh/2?1537409912.jpeg", | ||
* "country_code": "AU", | ||
* "default_group": "default", | ||
* "id": 2, | ||
* "is_active": true, | ||
* "is_bot": false, | ||
* "is_deleted": false, | ||
* "is_online": false, | ||
* "is_supporter": true, | ||
* "last_visit": "2021-06-21T06:55:47+00:00", | ||
* "pm_friends_only": false, | ||
* "profile_colour": "#3366FF", | ||
* "username": "peppy", | ||
* "country": { | ||
* "code": "AU", | ||
* "name": "Australia" | ||
* }, | ||
* "cover": { | ||
* "custom_url": "https://assets.ppy.sh/user-profile-covers/2/baba245ef60834b769694178f8f6d4f6166c5188c740de084656ad2b80f1eea7.jpeg", | ||
* "url": "https://assets.ppy.sh/user-profile-covers/2/baba245ef60834b769694178f8f6d4f6166c5188c740de084656ad2b80f1eea7.jpeg", | ||
* "id": null | ||
* }, | ||
* "groups": [ | ||
* { | ||
* "colour": "#0066FF", | ||
* "has_listing": false, | ||
* "has_playmodes": false, | ||
* "id": 33, | ||
* "identifier": "ppy", | ||
* "is_probationary": false, | ||
* "name": "ppy", | ||
* "short_name": "PPY", | ||
* "playmodes": null | ||
* }, | ||
* { | ||
* "colour": "#EB47D0", | ||
* "has_listing": true, | ||
* "has_playmodes": false, | ||
* "id": 11, | ||
* "identifier": "dev", | ||
* "is_probationary": false, | ||
* "name": "Developers", | ||
* "short_name": "DEV", | ||
* "playmodes": null | ||
* } | ||
* ], | ||
* "support_level": 3 | ||
* } | ||
* }, | ||
* // ... | ||
* ] | ||
*/ | ||
public function index() | ||
{ | ||
if (is_api_request()) { | ||
return json_collection( | ||
auth()->user() | ||
->relations() | ||
->friends() | ||
->withMutual() | ||
->with(['target' => fn ($query) => $query->eagerloadForListing()]) | ||
->get(), | ||
'UserRelation', | ||
[ | ||
'target', | ||
'target.country', | ||
'target.cover', | ||
'target.groups', | ||
'target.support_level', | ||
Comment on lines
+117
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static $userIncludes = [ ... ];
if (is_api_request()) {
return json_collection(..., ..., [
"target:mode({$currentMode})",
...array_map(..., $userIncludes),
]);
} |
||
], | ||
); | ||
} | ||
|
||
$currentUser = auth()->user(); | ||
$currentMode = default_mode(); | ||
|
||
|
@@ -52,10 +143,6 @@ public function index() | |
'support_level', | ||
]); | ||
|
||
if (is_api_request()) { | ||
return $usersJson; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About statistics; |
||
return ext_view('friends.index', compact('usersJson')); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## UserRelation | ||
```json | ||
{ | ||
"target_id": 3, | ||
"relation_type": "friend", | ||
"mutual": true | ||
} | ||
``` | ||
|
||
Field | Type | Notes | ||
--------------|---------------------|------------ | ||
mutual | boolean | Always `false` for blocks. | ||
relation_type | `block` \| `friend` | | | ||
target_id | number | | | ||
|
||
### Optional Attributes | ||
|
||
The following are attributes which may be additionally included in responses. Relevant endpoints should list them if applicable. | ||
|
||
Field | Type | ||
-------|----- | ||
target | [UserCompact](#usercompact) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make its own relation and load that instead.