Only serialize user slots and set photo ID in event object

This commit is contained in:
Slendy 2023-09-05 23:52:19 -05:00
commit 4d2645b7c3
No known key found for this signature in database
GPG key ID: 7288D68361B91428
3 changed files with 7 additions and 3 deletions

View file

@ -184,6 +184,7 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization
}, },
EventType.UploadPhoto => new GamePhotoUploadEvent EventType.UploadPhoto => new GamePhotoUploadEvent
{ {
PhotoId = ((PhotoActivityEntity)activity.Activity).PhotoId,
Slot = new ReviewSlot Slot = new ReviewSlot
{ {
SlotId = targetId, SlotId = targetId,

View file

@ -35,7 +35,6 @@ public class GamePhotoUploadEvent : GameEvent
if (photo == null) return; if (photo == null) return;
this.PhotoParticipants = photo.PhotoSubjects.Select(ps => ps.User.Username).ToList(); this.PhotoParticipants = photo.PhotoSubjects.Select(ps => ps.User.Username).ToList();
this.PhotoId = photo.PhotoId;
if (photo.SlotId == null) return; if (photo.SlotId == null) return;

View file

@ -11,6 +11,7 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token; using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Entities.Website; using LBPUnion.ProjectLighthouse.Types.Entities.Website;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Serialization.News; using LBPUnion.ProjectLighthouse.Types.Serialization.News;
using LBPUnion.ProjectLighthouse.Types.Serialization.Playlist; using LBPUnion.ProjectLighthouse.Types.Serialization.Playlist;
using LBPUnion.ProjectLighthouse.Types.Serialization.Slot; using LBPUnion.ProjectLighthouse.Types.Serialization.Slot;
@ -76,13 +77,13 @@ public class GameStream : ILbpSerializable, INeedsPreparationForSerialization
public async Task PrepareSerialization(DatabaseContext database) public async Task PrepareSerialization(DatabaseContext database)
{ {
this.Slots = await LoadEntities<SlotEntity, SlotBase>(this.SlotIds, slot => SlotBase.CreateFromEntity(slot, this.TargetGame, this.TargetUserId)); this.Slots = await LoadEntities<SlotEntity, SlotBase>(this.SlotIds, slot => SlotBase.CreateFromEntity(slot, this.TargetGame, this.TargetUserId), s => s.Type == SlotType.User);
this.Users = await LoadEntities<UserEntity, GameUser>(this.UserIds, user => GameUser.CreateFromEntity(user, this.TargetGame)); this.Users = await LoadEntities<UserEntity, GameUser>(this.UserIds, user => GameUser.CreateFromEntity(user, this.TargetGame));
this.Playlists = await LoadEntities<PlaylistEntity, GamePlaylist>(this.PlaylistIds, GamePlaylist.CreateFromEntity); this.Playlists = await LoadEntities<PlaylistEntity, GamePlaylist>(this.PlaylistIds, GamePlaylist.CreateFromEntity);
this.News = await LoadEntities<WebsiteAnnouncementEntity, GameNewsObject>(this.NewsIds, a => GameNewsObject.CreateFromEntity(a, this.TargetGame)); this.News = await LoadEntities<WebsiteAnnouncementEntity, GameNewsObject>(this.NewsIds, a => GameNewsObject.CreateFromEntity(a, this.TargetGame));
return; return;
async Task<List<TResult>> LoadEntities<TFrom, TResult>(List<int> ids, Func<TFrom, TResult> transformation) async Task<List<TResult>> LoadEntities<TFrom, TResult>(List<int> ids, Func<TFrom, TResult> transformation, Func<TFrom, bool> predicate = null)
where TFrom : class where TFrom : class
{ {
List<TResult> results = new(); List<TResult> results = new();
@ -90,6 +91,9 @@ public class GameStream : ILbpSerializable, INeedsPreparationForSerialization
foreach (int id in ids) foreach (int id in ids)
{ {
TFrom entity = await database.Set<TFrom>().FindAsync(id); TFrom entity = await database.Set<TFrom>().FindAsync(id);
if (predicate != null && !predicate(entity)) continue;
if (entity == null) continue; if (entity == null) continue;
results.Add(transformation(entity)); results.Add(transformation(entity));