diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs index f84e25aea..ff904cff9 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs @@ -30,16 +30,21 @@ public ActivityController(DatabaseContext database) this.database = database; } + private class ActivityFilterOptions + { + public bool ExcludeNews { get; init; } + public bool ExcludeMyLevels { get; init; } + public bool ExcludeFriends { get; init; } + public bool ExcludeFavouriteUsers { get; init; } + public bool ExcludeMyself { get; init; } + public bool ExcludeMyPlaylists { get; init; } = true; + } + private async Task> GetFilters ( IQueryable dtoQuery, GameTokenEntity token, - bool excludeNews, - bool excludeMyLevels, - bool excludeFriends, - bool excludeFavouriteUsers, - bool excludeMyself, - bool excludeMyPlaylists = true + ActivityFilterOptions options ) { dtoQuery = token.GameVersion == GameVersion.LittleBigPlanetVita @@ -75,37 +80,37 @@ private async Task> GetFilters } } - Expression> newsPredicate = !excludeNews + Expression> newsPredicate = !options.ExcludeNews ? new IncludeNewsFilter().GetPredicate() : new ExcludeNewsFilter().GetPredicate(); predicate = predicate.Or(newsPredicate); - if (!excludeMyLevels) + if (!options.ExcludeMyLevels) { predicate = predicate.Or(dto => dto.TargetSlotCreatorId == token.UserId); } List includedUserIds = []; - if (!excludeFriends) + if (!options.ExcludeFriends) { includedUserIds.AddRange(friendIds); } - if (!excludeFavouriteUsers) + if (!options.ExcludeFavouriteUsers) { includedUserIds.AddRange(favouriteUsers); } - if (!excludeMyself) + if (!options.ExcludeMyself) { includedUserIds.Add(token.UserId); } predicate = predicate.Or(dto => includedUserIds.Contains(dto.Activity.UserId)); - if (!excludeMyPlaylists && !excludeMyself && token.GameVersion == GameVersion.LittleBigPlanet3) + if (!options.ExcludeMyPlaylists && !options.ExcludeMyself && token.GameVersion == GameVersion.LittleBigPlanet3) { List creatorPlaylists = await this.database.Playlists.Where(p => p.CreatorId == token.UserId) .Select(p => p.PlaylistId) @@ -200,14 +205,15 @@ public async Task GlobalActivityLBP3 if (token.GameVersion != GameVersion.LittleBigPlanet3) return this.NotFound(); IQueryable activityEvents = await this.GetFilters( - this.database.Activities.ToActivityDto(true, true), - token, - excludeNews, - true, - true, - true, - excludeMyself, - excludeMyPlaylists); + this.database.Activities.ToActivityDto(true, true), token, new ActivityFilterOptions() + { + ExcludeNews = excludeNews, + ExcludeMyLevels = true, + ExcludeFriends = true, + ExcludeFavouriteUsers = true, + ExcludeMyself = excludeMyself, + ExcludeMyPlaylists = excludeMyPlaylists, + }); (DateTime Start, DateTime End) times = await this.GetTimeBounds(activityEvents, timestamp, null); @@ -246,11 +252,14 @@ bool excludeMyself IQueryable activityEvents = await this.GetFilters(this.database.Activities.ToActivityDto(true), token, - excludeNews, - excludeMyLevels, - excludeFriends, - excludeFavouriteUsers, - excludeMyself); + new ActivityFilterOptions + { + ExcludeNews = excludeNews, + ExcludeMyLevels = excludeMyLevels, + ExcludeFriends = excludeFriends, + ExcludeFavouriteUsers = excludeFavouriteUsers, + ExcludeMyself = excludeMyself, + }); (DateTime Start, DateTime End) times = await this.GetTimeBounds(activityEvents, timestamp, endTimestamp); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs index a9580e387..198d3fe74 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs @@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; using LBPUnion.ProjectLighthouse.Filter; +using LBPUnion.ProjectLighthouse.Filter.Filters; using LBPUnion.ProjectLighthouse.Filter.Filters.Slot; using LBPUnion.ProjectLighthouse.Filter.Sorts; using LBPUnion.ProjectLighthouse.Filter.Sorts.Metadata; diff --git a/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs b/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs index cbe70db8e..135ffd4bd 100644 --- a/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs +++ b/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs @@ -32,7 +32,7 @@ public static List GetIds(this IReadOnlyCollection grou /// Turns a list of into a group based on its timestamp /// /// An to group - /// Whether or not the groups should be created based on the initiator of the event or the target of the event + /// Whether the groups should be created based on the initiator of the event or the target of the event /// The transformed query containing groups of public static IQueryable> ToActivityGroups (this IQueryable activityQuery, bool groupByActor = false) => @@ -84,8 +84,8 @@ public static List ToOuterActivityGroups /// Converts an <> into an <> for grouping. /// /// The activity query to be converted. - /// Whether or not the field should be included. - /// Whether or not the field should be included. + /// Whether the field should be included. + /// Whether the field should be included. /// The converted <> public static IQueryable ToActivityDto (this IQueryable activityQuery, bool includeSlotCreator = false, bool includeTeamPick = false) @@ -107,8 +107,8 @@ public static IQueryable ToActivityDto /// Converts an IEnumerable<> into an IEnumerable<> for grouping. /// /// The activity query to be converted. - /// Whether or not the field should be included. - /// Whether or not the field should be included. + /// Whether the field should be included. + /// Whether the field should be included. /// The converted IEnumerable<> public static IEnumerable ToActivityDto (this IEnumerable activityEnumerable, bool includeSlotCreator = false, bool includeTeamPick = false)