mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-05 19:38:39 +00:00
Only serialize user slots and set photo ID in event object
This commit is contained in:
parent
991b3f7af9
commit
4d2645b7c3
3 changed files with 7 additions and 3 deletions
|
@ -184,6 +184,7 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization
|
|||
},
|
||||
EventType.UploadPhoto => new GamePhotoUploadEvent
|
||||
{
|
||||
PhotoId = ((PhotoActivityEntity)activity.Activity).PhotoId,
|
||||
Slot = new ReviewSlot
|
||||
{
|
||||
SlotId = targetId,
|
||||
|
|
|
@ -35,7 +35,6 @@ public class GamePhotoUploadEvent : GameEvent
|
|||
if (photo == null) return;
|
||||
|
||||
this.PhotoParticipants = photo.PhotoSubjects.Select(ps => ps.User.Username).ToList();
|
||||
this.PhotoId = photo.PhotoId;
|
||||
|
||||
if (photo.SlotId == null) return;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
|||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Website;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization.News;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization.Playlist;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization.Slot;
|
||||
|
@ -76,13 +77,13 @@ public class GameStream : ILbpSerializable, INeedsPreparationForSerialization
|
|||
|
||||
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.Playlists = await LoadEntities<PlaylistEntity, GamePlaylist>(this.PlaylistIds, GamePlaylist.CreateFromEntity);
|
||||
this.News = await LoadEntities<WebsiteAnnouncementEntity, GameNewsObject>(this.NewsIds, a => GameNewsObject.CreateFromEntity(a, this.TargetGame));
|
||||
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
|
||||
{
|
||||
List<TResult> results = new();
|
||||
|
@ -90,6 +91,9 @@ public class GameStream : ILbpSerializable, INeedsPreparationForSerialization
|
|||
foreach (int id in ids)
|
||||
{
|
||||
TFrom entity = await database.Set<TFrom>().FindAsync(id);
|
||||
|
||||
if (predicate != null && !predicate(entity)) continue;
|
||||
|
||||
if (entity == null) continue;
|
||||
|
||||
results.Add(transformation(entity));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue