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(); 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. // User and Level activity will never contain news posts or MM pick events.
IQueryable<ActivityDto> activityQuery = this.database.Activities.ToActivityDto() IQueryable<ActivityDto> activityQuery = this.database.Activities.ToActivityDto()
.Where(a => a.Activity.Type != EventType.NewsPost && a.Activity.Type != EventType.MMPickLevel); .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); a.Activity.Type != EventType.AddLevelToPlaylist);
} }
bool isLevelActivity = username == null;
// Slot activity // Slot activity
if (isLevelActivity) if (isLevelActivity)
{ {
@ -345,9 +346,9 @@ public class ActivityController : ControllerBase
activityQuery = activityQuery.Where(dto => activityQuery = activityQuery.Where(dto =>
dto.Activity.Timestamp < times.Start && dto.Activity.Timestamp > times.End); 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(); long oldestTimestamp = GetOldestTime(groups, times.Start).ToUnixTimeMilliseconds();

View file

@ -131,7 +131,9 @@ public class ScoreController : ControllerBase
await this.database.SaveChangesAsync(); 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.ChildSlotId == 0 || s.ChildSlotId == childId)
.Where(s => s.UserId == token.UserId) .Where(s => s.UserId == token.UserId)
.Where(s => s.Type == score.Type) .Where(s => s.Type == score.Type)

View file

@ -66,15 +66,15 @@ public static class ActivityQueryExtensions
{ {
Type = groupByActor Type = groupByActor
? gr.GroupType ? gr.GroupType
: gr.GroupType != ActivityGroupType.News : gr.GroupType == ActivityGroupType.News
? ActivityGroupType.User ? ActivityGroupType.News
: ActivityGroupType.News, : ActivityGroupType.User,
UserId = gr.Activity.UserId, UserId = gr.Activity.UserId,
TargetId = groupByActor TargetId = groupByActor
? gr.TargetId ? gr.TargetId
: gr.GroupType != ActivityGroupType.News : gr.GroupType == ActivityGroupType.News
? gr.Activity.UserId ? gr.TargetNewsId ?? 0
: gr.TargetNewsId ?? 0, : gr.Activity.UserId,
}) })
.ToList(), .ToList(),
}) })

View file

@ -25,11 +25,11 @@ public class ActivityDto
}; };
public ActivityGroupType GroupType => public ActivityGroupType GroupType =>
this.TargetSlotId != null this.TargetPlaylistId != null
? ActivityGroupType.Level
: this.TargetUserId != null
? ActivityGroupType.User
: this.TargetPlaylistId != null
? ActivityGroupType.Playlist ? ActivityGroupType.Playlist
: ActivityGroupType.News; : 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 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 _ => photo.Slot?.Type switch
{ {
SlotType.Developer => null, SlotType.User => new LevelPhotoActivity
// Non-story levels (moon, pod, etc)
_ => new LevelPhotoActivity
{ {
Type = EventType.UploadPhoto, Type = EventType.UploadPhoto,
PhotoId = photo.PhotoId, PhotoId = photo.PhotoId,
UserId = photo.CreatorId, UserId = photo.CreatorId,
SlotId = photo.SlotId ?? throw new NullReferenceException("SlotId in Photo is null"), 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 ScoreEntity score => score.Slot.Type switch
@ -227,6 +219,27 @@ public class ActivityEntityEventHandler : IEntityEventHandler
int Plays(VisitedLevelEntity entity) => entity.PlaysLBP1 + entity.PlaysLBP2 + entity.PlaysLBP3; 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: case SlotEntity slotEntity:
{ {
if (origEntity is not SlotEntity oldSlotEntity) break; if (origEntity is not SlotEntity oldSlotEntity) break;

View file

@ -27,16 +27,14 @@ public struct ActivityGroup
}; };
public ActivityGroupType GroupType => public ActivityGroupType GroupType =>
(this.TargetSlotId ?? 0) != 0 (this.TargetPlaylistId ?? 0) != 0
? ActivityGroupType.Level
: (this.TargetUserId ?? 0) != 0
? ActivityGroupType.User ? ActivityGroupType.User
: (this.TargetPlaylistId ?? 0) != 0
? ActivityGroupType.Playlist
: (this.TargetNewsId ?? 0) != 0 : (this.TargetNewsId ?? 0) != 0
? ActivityGroupType.News ? ActivityGroupType.News
: (this.TargetTeamPickSlotId ?? 0) != 0 : (this.TargetTeamPickSlotId ?? 0) != 0
? ActivityGroupType.TeamPick ? ActivityGroupType.TeamPick
: (this.TargetSlotId ?? 0) != 0
? ActivityGroupType.Level
: ActivityGroupType.User; : ActivityGroupType.User;
public override string ToString() => public override string ToString() =>

View file

@ -187,7 +187,7 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization
PhotoId = ((PhotoActivityEntity)activity.Activity).PhotoId, PhotoId = ((PhotoActivityEntity)activity.Activity).PhotoId,
Slot = new ReviewSlot Slot = new ReviewSlot
{ {
SlotId = targetId, SlotId = activity.TargetSlotId ?? -1,
}, },
}, },
EventType.MMPickLevel => new GameTeamPickLevelEvent EventType.MMPickLevel => new GameTeamPickLevelEvent
@ -211,15 +211,15 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization
}, },
EventType.CreatePlaylist => new GameCreatePlaylistEvent EventType.CreatePlaylist => new GameCreatePlaylistEvent
{ {
TargetPlaylistId = targetId, TargetPlaylistId = activity.TargetPlaylistId ?? -1,
}, },
EventType.HeartPlaylist => new GameHeartPlaylistEvent EventType.HeartPlaylist => new GameHeartPlaylistEvent
{ {
TargetPlaylistId = targetId, TargetPlaylistId = activity.TargetPlaylistId ?? -1,
}, },
EventType.AddLevelToPlaylist => new GameAddLevelToPlaylistEvent EventType.AddLevelToPlaylist => new GameAddLevelToPlaylistEvent
{ {
TargetPlaylistId = targetId, TargetPlaylistId = activity.TargetPlaylistId ?? -1,
Slot = new ReviewSlot Slot = new ReviewSlot
{ {
SlotId = ((PlaylistWithSlotActivityEntity)activity.Activity).SlotId, SlotId = ((PlaylistWithSlotActivityEntity)activity.Activity).SlotId,