Fix LBP3 playlist recent activity

This commit is contained in:
Slendy 2024-05-13 21:21:38 -05:00
commit 1820425038
No known key found for this signature in database
GPG key ID: 7288D68361B91428
7 changed files with 59 additions and 45 deletions

View file

@ -306,6 +306,9 @@ public class ActivityController : ControllerBase
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);
@ -318,8 +321,6 @@ public class ActivityController : ControllerBase
a.Activity.Type != EventType.AddLevelToPlaylist);
}
bool isLevelActivity = username == null;
// Slot activity
if (isLevelActivity)
{
@ -345,9 +346,9 @@ public class ActivityController : ControllerBase
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();

View file

@ -131,7 +131,9 @@ public class ScoreController : ControllerBase
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)

View file

@ -66,15 +66,15 @@ public static class ActivityQueryExtensions
{
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(),
})

View file

@ -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;
}

View file

@ -57,25 +57,17 @@ public class ActivityEntityEventHandler : IEntityEventHandler
},
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
@ -227,6 +219,27 @@ public class ActivityEntityEventHandler : IEntityEventHandler
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;

View file

@ -19,7 +19,7 @@ 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,
@ -27,17 +27,15 @@ public struct ActivityGroup
};
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}";

View file

@ -187,7 +187,7 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization
PhotoId = ((PhotoActivityEntity)activity.Activity).PhotoId,
Slot = new ReviewSlot
{
SlotId = targetId,
SlotId = activity.TargetSlotId ?? -1,
},
},
EventType.MMPickLevel => new GameTeamPickLevelEvent
@ -211,15 +211,15 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization
},
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,