1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 20:22:55 +08:00

Merge pull request #29363 from peppy/fix-daily-challenge-notification-spam

Fix daily challenge notification spam
This commit is contained in:
Bartłomiej Dach 2024-08-12 12:18:38 +02:00 committed by GitHub
commit 92bd123ebc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 6 deletions

View File

@ -48,6 +48,7 @@ namespace osu.Game.Tests.Visual.Menus
{
new PlaylistItem(beatmap)
},
StartDate = { Value = DateTimeOffset.Now.AddMinutes(-30) },
EndDate = { Value = DateTimeOffset.Now.AddSeconds(60) }
});
return true;

View File

@ -58,6 +58,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
new PlaylistItem(beatmap)
},
StartDate = { Value = DateTimeOffset.Now.AddMinutes(-5) },
EndDate = { Value = DateTimeOffset.Now.AddSeconds(30) }
});
return true;
@ -95,8 +96,13 @@ namespace osu.Game.Tests.Visual.UserInterface
},
};
});
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
AddAssert("notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.EqualTo(1));
AddStep("clear notifications", () =>
{
foreach (var notification in notificationOverlay.AllNotifications)
notification.Close(runFlingAnimation: false);
});
AddStep("beatmap of the day not active", () => metadataClient.DailyChallengeUpdated(null));
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
@ -105,7 +111,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
RoomID = 1234,
}));
AddAssert("notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.EqualTo(1));
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
}
}
}

View File

@ -104,8 +104,7 @@ namespace osu.Game.Screens.Menu
{
base.LoadComplete();
info.BindValueChanged(_ => dailyChallengeChanged(postNotification: true));
dailyChallengeChanged(postNotification: false);
info.BindValueChanged(dailyChallengeChanged, true);
}
protected override void Update()
@ -131,7 +130,9 @@ namespace osu.Game.Screens.Menu
}
}
private void dailyChallengeChanged(bool postNotification)
private long? lastNotifiedDailyChallengeRoomId;
private void dailyChallengeChanged(ValueChangedEvent<DailyChallengeInfo?> _)
{
UpdateState();
@ -152,8 +153,14 @@ namespace osu.Game.Screens.Menu
Room = room;
cover.OnlineInfo = TooltipContent = room.Playlist.FirstOrDefault()?.Beatmap.BeatmapSet as APIBeatmapSet;
if (postNotification)
// We only want to notify the user if a new challenge recently went live.
if (room.StartDate.Value != null
&& Math.Abs((DateTimeOffset.Now - room.StartDate.Value!.Value).TotalSeconds) < 1800
&& room.RoomID.Value != lastNotifiedDailyChallengeRoomId)
{
lastNotifiedDailyChallengeRoomId = room.RoomID.Value;
notificationOverlay?.Post(new NewDailyChallengeNotification(room));
}
updateCountdown();
Scheduler.AddDelayed(updateCountdown, 1000, true);