Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@smoogipoo
Copy link
Contributor

As mentioned in #34533 (comment).

Bundled another change in here, which is to make Avatar (expected to be non-null in all external usages) truly non-null (as far as we expect from o!f).

@smoogipoo smoogipoo added the code quality Fixes code quality. Not visible to the end user. label Aug 15, 2025
@smoogipoo smoogipoo changed the title Refactor notification avatar to remove OnUpdate() Refactor notification avatar to remove OnUpdate Aug 15, 2025
Comment on lines 36 to 38
IconContent.Masking = true;
IconContent.CornerRadius = CORNER_RADIUS;
IconContent.ChangeChildDepth(IconDrawable, float.MinValue);
Copy link
Member

Choose a reason for hiding this comment

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

Should this still be applied outside the null check? Seems like the default avatar may look weird otherwise.

Copy link
Contributor Author

@smoogipoo smoogipoo Aug 15, 2025

Choose a reason for hiding this comment

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

I don't understand what you're referring to - it's still inside the null check.

If this is confusing, we can revert the moving of Avatar outside of here. I was just looking at a protected member that's actually accessed (usually Avatar.Colour = ...) and saw that potentially resulting in a nullref.

Copy link
Contributor Author

@smoogipoo smoogipoo Aug 15, 2025

Choose a reason for hiding this comment

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

Or are you referring to the code in Update()? In the case the user's null, there won't be any avatar. I'm not sure if it makes sense to do the width setting in that case so I decided to not change the semantics.

Copy link
Member

Choose a reason for hiding this comment

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

Referring to the IconContainer alterations. Not immediately obvious the avatar is just not being added to the hierarchy (a bit weird to me)

Copy link
Member

@peppy peppy Aug 15, 2025

Choose a reason for hiding this comment

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

This is how it looks with a null user in this PR:

Image

Can we go with this instead?

diff --git a/osu.Game/Overlays/Notifications/UserAvatarNotification.cs b/osu.Game/Overlays/Notifications/UserAvatarNotification.cs
index c283d36468..7dbecbf11e 100644
--- a/osu.Game/Overlays/Notifications/UserAvatarNotification.cs
+++ b/osu.Game/Overlays/Notifications/UserAvatarNotification.cs
@@ -26,26 +26,20 @@ protected UserAvatarNotification(APIUser? user, LocalisableString text = default
         [BackgroundDependencyLoader]
         private void load()
         {
-            Avatar = new DrawableAvatar(user)
-            {
-                FillMode = FillMode.Fill,
-            };
+            IconContent.Masking = true;
+            IconContent.CornerRadius = CORNER_RADIUS;
+            IconContent.ChangeChildDepth(IconDrawable, float.MinValue);
 
-            if (user != null)
+            LoadComponentAsync(Avatar = new DrawableAvatar(user)
             {
-                IconContent.Masking = true;
-                IconContent.CornerRadius = CORNER_RADIUS;
-                IconContent.ChangeChildDepth(IconDrawable, float.MinValue);
-                LoadComponentAsync(Avatar, IconContent.Add);
-            }
+                FillMode = FillMode.Fill,
+            }, IconContent.Add);
         }
 
         protected override void Update()
         {
             base.Update();
-
-            if (user != null)
-                IconContent.Width = IconContent.DrawHeight;
+            IconContent.Width = IconContent.DrawHeight;
         }
     }
 }
2025-08-15 20 43 04@2x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The null user is the case where multiple friends come online at the same time. Does it even make sense to display an avatar in that case?

Copy link
Contributor Author

@smoogipoo smoogipoo Aug 15, 2025

Choose a reason for hiding this comment

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

To be clear, I don't mind if you do that. It's just something you should be aware of.

Copy link
Member

Choose a reason for hiding this comment

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

Would be cool to show a little mosaic / cascade of each user's avatars in the future.

I think either what I have or having the drawable as nullable. I really get weirded about by a drawable created but not added ever.

@peppy peppy self-requested a review August 15, 2025 11:38
@peppy peppy merged commit 28fae93 into ppy:master Aug 17, 2025
6 of 9 checks passed
@peppy peppy deleted the refactor-avatar-notification branch August 17, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Fixes code quality. Not visible to the end user. size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants