Skip to content
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

Add the ability to add/remove friends in UserProfileHeader #30467

Merged
merged 18 commits into from
Nov 5, 2024

Conversation

cdwcgt
Copy link
Contributor

@cdwcgt cdwcgt commented Nov 1, 2024

what this pr do:

  • add new model named APIRelation, it's also used in "blocking relationships"
  • modified some logic that is using the friend function due to model changes
  • add a new method named UpdateLocalFriends to IAPIProvider for update friends list manually, because it is currently impossible to get the friend list in real time through push method.
  • add loading layer to ProfileHeaderButton for display the online request status.

need to be mentioned:

  • follower count is store in FollowersButton when profile user loaded, and data changes are handled locally, because it is not possible to update user in profileOverlay after performing an operation
  • loading layer is bit different from web

@cdwcgt cdwcgt changed the title Add the ability to add friends to your profile Add the ability to add friends in UserProfileHeader Nov 1, 2024
Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superficial review, just the most obvious problems

Comment on lines +19 to +20
[JsonProperty("target")]
public APIUser? TargetUser { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But he does exist, I think it's this is in
https://github.com/nanaya/osu-web/blob/fe21e207e8f8106ae024d8eab9108b8481ea1b5a/app/Http/Controllers/FriendsController.php#L57

api will return APIUser when request friends but not for block relation

osu.Game/Online/API/Requests/FriendDeleteRequest.cs Outdated Show resolved Hide resolved
osu.Game/Online/API/Requests/FriendAddRequest.cs Outdated Show resolved Hide resolved
{
followerCount += status.Value == FriendStatus.None ? 1 : -1;

api.UpdateLocalFriends();
Copy link
Collaborator

@bdach bdach Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need to refetch friends every time? The request just succeeded, you can tell what happened, why do a refetch?

I guess it would make sense in the case of adding users, because you might not have the APIUser instance present or whatever, but isn't/can't that be in the add friend request or response? Or even couldn't the APIUser be taken from the ambient overlay?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing the refetch but things crash, something or other about groups not being populated in the response of this.

@ppy/team-client can I get a second pair of eyes on this to make sure you're ok with it?

osu.Game/Tests/Visual/OsuTestScene.cs Outdated Show resolved Hide resolved
Comment on lines +137 to +140
/// <summary>
/// Update the friends status of the current user.
/// </summary>
void UpdateLocalFriends();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to preceding comment - if the need to refetch users can be removed, this method probably doesn't need to exist. (I guess there is #13604, but it's (a) out of scope here, and (b) not even a given that a poll like the OP of that proposes is the right thing to do.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll keep him for now until the results come in?

@pull-request-size pull-request-size bot added size/XL and removed size/L labels Nov 1, 2024
@cdwcgt
Copy link
Contributor Author

cdwcgt commented Nov 1, 2024

I have fixed some of the issues that I think are now fixable, and now we cannot update friends list in real time
But to be honest, I don't have a good solution. Maybe it can be done like beatmap updates or achievement push?

@bdach
Copy link
Collaborator

bdach commented Nov 1, 2024

now we cannot update friends list in real time

I'm not sure what you're trying to say? You haven't undone any of the UpdateLocalFriends() changes, so that should still work?

@cdwcgt
Copy link
Contributor Author

cdwcgt commented Nov 1, 2024

UpdateLocalFriends() will only be called when adding or deleting friends or logging in.
and I haven't added any polling logic, so if you add friends on the web page, they won't be displayed in real time in the game.

@bdach
Copy link
Collaborator

bdach commented Nov 1, 2024

As I said, that's out of scope of this PR. Let's focus on the adding/removing of friends here.

@bdach bdach changed the title Add the ability to add friends in UserProfileHeader Add the ability to add/remove friends in UserProfileHeader Nov 4, 2024
@bdach bdach added the next release Pull requests which are almost there. We'll aim to get them in the next release, but no guarantees! label Nov 4, 2024
bdach
bdach previously approved these changes Nov 4, 2024
Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine

@@ -6,7 +6,7 @@

namespace osu.Game.Online.API.Requests
{
public class GetFriendsRequest : APIRequest<List<APIUser>>
public class GetFriendsRequest : APIRequest<List<APIRelation>>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this works because API-side the format of the response is changed and is dependent on x-api-version. This means that at least this single change to this single file must go out before the next release, or the friends displays will be broken. (Discovered in testing with #30499.)

@peppy peppy self-requested a review November 5, 2024 05:32
@peppy
Copy link
Member

peppy commented Nov 5, 2024

I've adjusted the slightly because the transition of the button states was irking me.

Before:

osu! 2024-11-05 at 05 54 06

After:

osu! 2024-11-05 at 05 53 06

Now, rather than the full state change being delayed, only the mutual status is. I think this makes more sense.

@bdach please double check you're okay with this.

peppy
peppy previously approved these changes Nov 5, 2024
@cdwcgt
Copy link
Contributor Author

cdwcgt commented Nov 5, 2024

for adding friend we can get a APIRelation response for mutual status but maybe need two different code path?

not sure whether to do this or not.

@peppy peppy self-requested a review November 5, 2024 06:52
@peppy
Copy link
Member

peppy commented Nov 5, 2024

Hmm, I've tried that but Mutual doesn't seem to be set where I expect it to:

JetBrains Rider-EAP 2024-11-05 at 07 20 11

peppy@1fcdf67

@cdwcgt
Copy link
Contributor Author

cdwcgt commented Nov 5, 2024

I tried capturing the network request and it looks like the api is returning the correct values, but addedRequest.Response looks like nothing?

ok I got it, response is

{
	"user_relation": {
		"target_id": 960,
		"relation_type": "friend",
		"mutual": true
	}
}

The actual data is in the inner layer

my bad

@cdwcgt
Copy link
Contributor Author

cdwcgt commented Nov 5, 2024

image
add AddFriendResponse to handle it

Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine. the issue with the wrong request shape is probably why i couldn't get this to work without refetching friends, but i don't have the mental energy to try it again

@bdach bdach merged commit 2bd12e1 into ppy:master Nov 5, 2024
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:overlay-user-profile next release Pull requests which are almost there. We'll aim to get them in the next release, but no guarantees! size/XL type:online
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There's no way to add a friend in-game
3 participants