Skip to content

Commit

Permalink
Fix LBP3 playlist recent activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Slendy committed May 14, 2024
1 parent 2219373 commit 1820425
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ public async Task<IActionResult> LocalActivity(string? slotType, int slotId, str

if ((SlotHelper.IsTypeInvalid(slotType) || slotId == 0) == (username == null)) return this.BadRequest();

bool isLevelActivity = username == null;
bool groupByActor = !isLevelActivity && token.GameVersion == GameVersion.LittleBigPlanet3;

// User and Level activity will never contain news posts or MM pick events.
IQueryable<ActivityDto> activityQuery = this.database.Activities.ToActivityDto()
.Where(a => a.Activity.Type != EventType.NewsPost && a.Activity.Type != EventType.MMPickLevel);
Expand All @@ -318,8 +321,6 @@ public async Task<IActionResult> LocalActivity(string? slotType, int slotId, str
a.Activity.Type != EventType.AddLevelToPlaylist);
}

bool isLevelActivity = username == null;

// Slot activity
if (isLevelActivity)
{
Expand All @@ -345,9 +346,9 @@ public async Task<IActionResult> LocalActivity(string? slotType, int slotId, str
activityQuery = activityQuery.Where(dto =>
dto.Activity.Timestamp < times.Start && dto.Activity.Timestamp > times.End);

List<IGrouping<ActivityGroup, ActivityDto>> groups = await activityQuery.ToActivityGroups().ToListAsync();
List<IGrouping<ActivityGroup, ActivityDto>> groups = await activityQuery.ToActivityGroups(groupByActor).ToListAsync();

List<OuterActivityGroup> outerGroups = groups.ToOuterActivityGroups();
List<OuterActivityGroup> outerGroups = groups.ToOuterActivityGroups(groupByActor);

long oldestTimestamp = GetOldestTime(groups, times.Start).ToUnixTimeMilliseconds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public async Task<IActionResult> SubmitScore(string slotType, int id, int childI

await this.database.SaveChangesAsync();

ScoreEntity? existingScore = await this.database.Scores.Where(s => s.SlotId == slot.SlotId)
ScoreEntity? existingScore = await this.database.Scores
.Include(s => s.Slot)
.Where(s => s.SlotId == slot.SlotId)
.Where(s => s.ChildSlotId == 0 || s.ChildSlotId == childId)
.Where(s => s.UserId == token.UserId)
.Where(s => s.Type == score.Type)
Expand Down
12 changes: 6 additions & 6 deletions ProjectLighthouse/Extensions/ActivityQueryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public static List<OuterActivityGroup> ToOuterActivityGroups
{
Type = groupByActor
? gr.GroupType
: gr.GroupType != ActivityGroupType.News
? ActivityGroupType.User
: ActivityGroupType.News,
: gr.GroupType == ActivityGroupType.News
? ActivityGroupType.News
: ActivityGroupType.User,
UserId = gr.Activity.UserId,
TargetId = groupByActor
? gr.TargetId
: gr.GroupType != ActivityGroupType.News
? gr.Activity.UserId
: gr.TargetNewsId ?? 0,
: gr.GroupType == ActivityGroupType.News
? gr.TargetNewsId ?? 0
: gr.Activity.UserId,
})
.ToList(),
})
Expand Down
14 changes: 7 additions & 7 deletions ProjectLighthouse/Types/Activity/ActivityDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class ActivityDto
};

public ActivityGroupType GroupType =>
this.TargetSlotId != null
? ActivityGroupType.Level
: this.TargetUserId != null
? ActivityGroupType.User
: this.TargetPlaylistId != null
? ActivityGroupType.Playlist
: ActivityGroupType.News;
this.TargetPlaylistId != null
? ActivityGroupType.Playlist
: this.TargetNewsId != null
? ActivityGroupType.News
: this.TargetSlotId != null
? ActivityGroupType.Level
: ActivityGroupType.User;
}
35 changes: 24 additions & 11 deletions ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,17 @@ public void OnEntityInserted<T>(DatabaseContext database, T entity) where T : cl
},
PhotoEntity photo => photo.SlotId switch
{
// Photos without levels
null => new UserPhotoActivity
{
Type = EventType.UploadPhoto,
PhotoId = photo.PhotoId,
UserId = photo.CreatorId,
TargetUserId = photo.CreatorId,
},
_ => photo.Slot?.Type switch
{
SlotType.Developer => null,
// Non-story levels (moon, pod, etc)
_ => new LevelPhotoActivity
SlotType.User => new LevelPhotoActivity
{
Type = EventType.UploadPhoto,
PhotoId = photo.PhotoId,
UserId = photo.CreatorId,
SlotId = photo.SlotId ?? throw new NullReferenceException("SlotId in Photo is null"),
},
// All other photos (story, moon, pod, etc.)
_ => null,
},
},
ScoreEntity score => score.Slot.Type switch
Expand Down Expand Up @@ -227,6 +219,27 @@ public void OnEntityChanged<T>(DatabaseContext database, T origEntity, T current

int Plays(VisitedLevelEntity entity) => entity.PlaysLBP1 + entity.PlaysLBP2 + entity.PlaysLBP3;
}
case ScoreEntity score:
{
if (origEntity is not ScoreEntity oldScore) break;

// don't track versus levels
if (oldScore.Type == 7) break;

if (score.Slot.Type != SlotType.User) break;

if (oldScore.Points > score.Points) break;

activity = new ScoreActivityEntity
{
Type = EventType.Score,
ScoreId = score.ScoreId,
SlotId = score.SlotId,
UserId = score.UserId,
};

break;
}
case SlotEntity slotEntity:
{
if (origEntity is not SlotEntity oldSlotEntity) break;
Expand Down
22 changes: 10 additions & 12 deletions ProjectLighthouse/Types/Activity/ActivityGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,23 @@ public struct ActivityGroup
this.GroupType switch
{
ActivityGroupType.User => this.TargetUserId ?? this.UserId,
ActivityGroupType.Level => this.TargetSlotId?? 0,
ActivityGroupType.Level => this.TargetSlotId ?? 0,
ActivityGroupType.TeamPick => this.TargetTeamPickSlotId ?? 0,
ActivityGroupType.Playlist => this.TargetPlaylistId ?? 0,
ActivityGroupType.News => this.TargetNewsId ?? 0,
_ => this.UserId,
};

public ActivityGroupType GroupType =>
(this.TargetSlotId ?? 0) != 0
? ActivityGroupType.Level
: (this.TargetUserId ?? 0) != 0
? ActivityGroupType.User
: (this.TargetPlaylistId ?? 0) != 0
? ActivityGroupType.Playlist
: (this.TargetNewsId ?? 0) != 0
? ActivityGroupType.News
: (this.TargetTeamPickSlotId ?? 0) != 0
? ActivityGroupType.TeamPick
: ActivityGroupType.User;
(this.TargetPlaylistId ?? 0) != 0
? ActivityGroupType.User
: (this.TargetNewsId ?? 0) != 0
? ActivityGroupType.News
: (this.TargetTeamPickSlotId ?? 0) != 0
? ActivityGroupType.TeamPick
: (this.TargetSlotId ?? 0) != 0
? ActivityGroupType.Level
: ActivityGroupType.User;

public override string ToString() =>
$@"{this.GroupType} Group: Timestamp: {this.Timestamp}, UserId: {this.UserId}, TargetId: {this.TargetId}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static GameEvent CreateFromActivity(ActivityDto activity)
PhotoId = ((PhotoActivityEntity)activity.Activity).PhotoId,
Slot = new ReviewSlot
{
SlotId = targetId,
SlotId = activity.TargetSlotId ?? -1,
},
},
EventType.MMPickLevel => new GameTeamPickLevelEvent
Expand All @@ -211,15 +211,15 @@ private static GameEvent CreateFromActivity(ActivityDto activity)
},
EventType.CreatePlaylist => new GameCreatePlaylistEvent
{
TargetPlaylistId = targetId,
TargetPlaylistId = activity.TargetPlaylistId ?? -1,
},
EventType.HeartPlaylist => new GameHeartPlaylistEvent
{
TargetPlaylistId = targetId,
TargetPlaylistId = activity.TargetPlaylistId ?? -1,
},
EventType.AddLevelToPlaylist => new GameAddLevelToPlaylistEvent
{
TargetPlaylistId = targetId,
TargetPlaylistId = activity.TargetPlaylistId ?? -1,
Slot = new ReviewSlot
{
SlotId = ((PlaylistWithSlotActivityEntity)activity.Activity).SlotId,
Expand Down

0 comments on commit 1820425

Please sign in to comment.