Don't create activities for story levels

Also no longer shows you activities from incompatible levels (someone plays an LBP3 level but you won't be shown it from LBP2)

Also gets rid of versus scores
This commit is contained in:
Slendy 2023-08-31 18:20:53 -05:00
commit 24fa301182
No known key found for this signature in database
GPG key ID: 7288D68361B91428
4 changed files with 96 additions and 47 deletions

View file

@ -43,6 +43,10 @@ public class ActivityController : ControllerBase
bool excludeMyPlaylists = true
)
{
dtoQuery = token.GameVersion == GameVersion.LittleBigPlanetVita
? dtoQuery.Where(dto => dto.TargetSlotGameVersion == null || dto.TargetSlotGameVersion == token.GameVersion)
: dtoQuery.Where(dto => dto.TargetSlotGameVersion == null || dto.TargetSlotGameVersion <= token.GameVersion);
Expression<Func<ActivityDto, bool>> predicate = PredicateExtensions.False<ActivityDto>();
List<int> favouriteUsers = await this.database.HeartedProfiles.Where(hp => hp.UserId == token.UserId)

View file

@ -71,6 +71,7 @@ public static class ActivityQueryExtensions
// to build a pattern matching switch statement with expression trees. so the only other option
// is to basically rewrite this nested ternary mess with expression trees which isn't much better
// The resulting SQL generated by EntityFramework uses a CASE statement which is probably fine
// TOTAL HOURS WASTED: 3
public static IQueryable<ActivityDto> ToActivityDto
(this IQueryable<ActivityEntity> activityQuery, bool includeSlotCreator = false, bool includeTeamPick = false)
{
@ -79,7 +80,7 @@ public static class ActivityQueryExtensions
Activity = a,
TargetSlotId = a is LevelActivityEntity
? ((LevelActivityEntity)a).SlotId
: a is PhotoActivityEntity && ((PhotoActivityEntity)a).Photo.PhotoId != 0
: a is PhotoActivityEntity && ((PhotoActivityEntity)a).Photo.SlotId != 0
? ((PhotoActivityEntity)a).Photo.SlotId
: a is CommentActivityEntity && ((CommentActivityEntity)a).Comment.Type == CommentType.Level
? ((CommentActivityEntity)a).Comment.TargetSlotId
@ -87,22 +88,18 @@ public static class ActivityQueryExtensions
? ((ScoreActivityEntity)a).Score.SlotId
: a is ReviewActivityEntity
? ((ReviewActivityEntity)a).Review.SlotId
: 0,
TargetUserId = a is UserActivityEntity
? ((UserActivityEntity)a).TargetUserId
: a is CommentActivityEntity && ((CommentActivityEntity)a).Comment.Type == CommentType.Profile
? ((CommentActivityEntity)a).Comment.TargetUserId
: a is PhotoActivityEntity && ((PhotoActivityEntity)a).Photo.SlotId != 0
? ((PhotoActivityEntity)a).Photo.CreatorId
: 0,
TargetPlaylistId = a is PlaylistActivityEntity || a is PlaylistWithSlotActivityEntity
? ((PlaylistActivityEntity)a).PlaylistId
: 0,
TargetNewsId = a is NewsActivityEntity ? ((NewsActivityEntity)a).NewsId : 0,
TargetTeamPickId = includeTeamPick
? a.Type == EventType.MMPickLevel && a is LevelActivityEntity ? ((LevelActivityEntity)a).SlotId : 0
: 0,
: null,
TargetSlotGameVersion = a is LevelActivityEntity
? ((LevelActivityEntity)a).Slot.GameVersion
: a is PhotoActivityEntity && ((PhotoActivityEntity)a).Photo.SlotId != 0
? ((PhotoActivityEntity)a).Photo.Slot.GameVersion
: a is CommentActivityEntity && ((CommentActivityEntity)a).Comment.Type == CommentType.Level
? ((CommentActivityEntity)a).Comment.TargetSlot.GameVersion
: a is ScoreActivityEntity
? ((ScoreActivityEntity)a).Score.Slot.GameVersion
: a is ReviewActivityEntity
? ((ReviewActivityEntity)a).Review.Slot.GameVersion
: null,
TargetSlotCreatorId = includeSlotCreator
? a is LevelActivityEntity
? ((LevelActivityEntity)a).Slot.CreatorId
@ -114,8 +111,22 @@ public static class ActivityQueryExtensions
? ((ScoreActivityEntity)a).Score.Slot.CreatorId
: a is ReviewActivityEntity
? ((ReviewActivityEntity)a).Review.Slot!.CreatorId
: 0
: 0,
});
: null
: null,
TargetUserId = a is UserActivityEntity
? ((UserActivityEntity)a).TargetUserId
: a is CommentActivityEntity && ((CommentActivityEntity)a).Comment.Type == CommentType.Profile
? ((CommentActivityEntity)a).Comment.TargetUserId
: a is PhotoActivityEntity && ((PhotoActivityEntity)a).Photo.SlotId != 0
? ((PhotoActivityEntity)a).Photo.CreatorId
: null,
TargetPlaylistId = a is PlaylistActivityEntity || a is PlaylistWithSlotActivityEntity
? ((PlaylistActivityEntity)a).PlaylistId
: null,
TargetNewsId = a is NewsActivityEntity ? ((NewsActivityEntity)a).NewsId : null,
TargetTeamPickId = includeTeamPick
? a.Type == EventType.MMPickLevel && a is LevelActivityEntity ? ((LevelActivityEntity)a).SlotId : null
: null, });
}
}

View file

@ -1,4 +1,5 @@
using LBPUnion.ProjectLighthouse.Types.Entities.Activity;
using LBPUnion.ProjectLighthouse.Types.Users;
namespace LBPUnion.ProjectLighthouse.Types.Activity;
@ -7,6 +8,7 @@ public class ActivityDto
public required ActivityEntity Activity { get; set; }
public int? TargetSlotId { get; set; }
public int? TargetSlotCreatorId { get; set; }
public GameVersion? TargetSlotGameVersion { get; set; }
public int? TargetUserId { get; set; }
public int? TargetPlaylistId { get; set; }
public int? TargetNewsId { get; set; }

View file

@ -16,7 +16,6 @@ using System.Reflection;
namespace LBPUnion.ProjectLighthouse.Types.Activity;
//TODO implement missing event triggers
public class ActivityEntityEventHandler : IEntityEventHandler
{
public void OnEntityInserted<T>(DatabaseContext database, T entity) where T : class
@ -24,35 +23,56 @@ public class ActivityEntityEventHandler : IEntityEventHandler
Console.WriteLine($@"OnEntityInserted: {entity.GetType().Name}");
ActivityEntity? activity = entity switch
{
SlotEntity slot => new LevelActivityEntity
SlotEntity slot => slot.Type switch
{
Type = EventType.PublishLevel,
SlotId = slot.SlotId,
UserId = slot.CreatorId,
SlotType.User => new LevelActivityEntity
{
Type = EventType.PublishLevel,
SlotId = slot.SlotId,
UserId = slot.CreatorId,
},
_ => null,
},
CommentEntity comment => new CommentActivityEntity
CommentEntity comment => comment.TargetSlot?.Type switch
{
Type = comment.Type == CommentType.Level ? EventType.CommentOnLevel : EventType.CommentOnUser,
CommentId = comment.CommentId,
UserId = comment.PosterUserId,
SlotType.User => new CommentActivityEntity
{
Type = comment.Type == CommentType.Level ? EventType.CommentOnLevel : EventType.CommentOnUser,
CommentId = comment.CommentId,
UserId = comment.PosterUserId,
},
_ => null,
},
PhotoEntity photo => new PhotoActivityEntity
PhotoEntity photo => photo.Slot?.Type switch
{
Type = EventType.UploadPhoto,
PhotoId = photo.PhotoId,
UserId = photo.CreatorId,
SlotType.User => new PhotoActivityEntity
{
Type = EventType.UploadPhoto,
PhotoId = photo.PhotoId,
UserId = photo.CreatorId,
},
_ => null,
},
ScoreEntity score => new ScoreActivityEntity
ScoreEntity score => score.Slot.Type switch
{
Type = EventType.Score,
ScoreId = score.ScoreId,
UserId = score.UserId,
// Don't add story scores or versus scores
SlotType.User when score.Type != 7 => new ScoreActivityEntity
{
Type = EventType.Score,
ScoreId = score.ScoreId,
UserId = score.UserId,
},
_ => null,
},
HeartedLevelEntity heartedLevel => new LevelActivityEntity
HeartedLevelEntity heartedLevel => heartedLevel.Slot.Type switch
{
Type = EventType.HeartLevel,
SlotId = heartedLevel.SlotId,
UserId = heartedLevel.UserId,
SlotType.User => new LevelActivityEntity
{
Type = EventType.HeartLevel,
SlotId = heartedLevel.SlotId,
UserId = heartedLevel.UserId,
},
_ => null,
},
HeartedProfileEntity heartedProfile => new UserActivityEntity
{
@ -123,8 +143,7 @@ public class ActivityEntityEventHandler : IEntityEventHandler
object? origVal = propInfo.GetValue(origEntity);
object? newVal = propInfo.GetValue(currentEntity);
if ((origVal == null && newVal == null) || (origVal != null && newVal != null && origVal.Equals(newVal)))
continue;
if ((origVal == null && newVal == null) || (origVal != null && newVal != null && origVal.Equals(newVal))) continue;
Console.WriteLine($@"Value for {propInfo.Name} changed");
Console.WriteLine($@"Orig val: {origVal?.ToString() ?? "null"}");
@ -197,6 +216,14 @@ public class ActivityEntityEventHandler : IEntityEventHandler
{
if (origEntity is not CommentEntity oldComment) break;
if (comment.TargetSlotId != null)
{
SlotType slotType = database.Slots.Where(s => s.SlotId == comment.TargetSlotId)
.Select(s => s.Type)
.FirstOrDefault();
if (slotType != SlotType.User) break;
}
if (oldComment.Deleted || !comment.Deleted) break;
if (comment.Type != CommentType.Level) break;
@ -238,6 +265,7 @@ public class ActivityEntityEventHandler : IEntityEventHandler
};
InsertActivity(database, entity);
}
break;
}
}
@ -250,11 +278,15 @@ public class ActivityEntityEventHandler : IEntityEventHandler
Console.WriteLine($@"OnEntityDeleted: {entity.GetType().Name}");
ActivityEntity? activity = entity switch
{
HeartedLevelEntity heartedLevel => new LevelActivityEntity
HeartedLevelEntity heartedLevel => heartedLevel.Slot.Type switch
{
Type = EventType.UnheartLevel,
SlotId = heartedLevel.SlotId,
UserId = heartedLevel.UserId,
SlotType.User => new LevelActivityEntity
{
Type = EventType.UnheartLevel,
SlotId = heartedLevel.SlotId,
UserId = heartedLevel.UserId,
},
_ => null,
},
HeartedProfileEntity heartedProfile => new UserActivityEntity
{