Fix admin note updates duplicating visually across all open note windows (#15471)

This commit is contained in:
DrSmugleaf
2023-04-16 23:18:54 -07:00
committed by GitHub
parent fa8906da36
commit 13d299dea3
5 changed files with 25 additions and 6 deletions

View File

@@ -117,13 +117,19 @@ public sealed class AdminNotesEui : BaseEui
private void NoteModified(SharedAdminNote note) private void NoteModified(SharedAdminNote note)
{ {
if (note.Player != NotedPlayer)
return;
Notes[note.Id] = note; Notes[note.Id] = note;
StateDirty(); StateDirty();
} }
private void NoteDeleted(int id) private void NoteDeleted(SharedAdminNote note)
{ {
Notes.Remove(id); if (note.Player != NotedPlayer)
return;
Notes.Remove(note.Id);
StateDirty(); StateDirty();
} }

View File

@@ -10,6 +10,7 @@ public static class AdminNotesExtensions
return new SharedAdminNote( return new SharedAdminNote(
note.Id, note.Id,
note.RoundId, note.RoundId,
note.PlayerUserId,
note.Message, note.Message,
note.CreatedBy.LastSeenUserName, note.CreatedBy.LastSeenUserName,
note.LastEditedBy.LastSeenUserName, note.LastEditedBy.LastSeenUserName,

View File

@@ -22,7 +22,7 @@ public sealed class AdminNotesManager : IAdminNotesManager, IPostInjectInit
public event Action<SharedAdminNote>? NoteAdded; public event Action<SharedAdminNote>? NoteAdded;
public event Action<SharedAdminNote>? NoteModified; public event Action<SharedAdminNote>? NoteModified;
public event Action<int>? NoteDeleted; public event Action<SharedAdminNote>? NoteDeleted;
private ISawmill _sawmill = default!; private ISawmill _sawmill = default!;
@@ -66,6 +66,7 @@ public sealed class AdminNotesManager : IAdminNotesManager, IPostInjectInit
var note = new SharedAdminNote( var note = new SharedAdminNote(
noteId, noteId,
round, round,
player,
message, message,
createdBy.Name, createdBy.Name,
createdBy.Name, createdBy.Name,
@@ -89,7 +90,17 @@ public sealed class AdminNotesManager : IAdminNotesManager, IPostInjectInit
var deletedAt = DateTime.UtcNow; var deletedAt = DateTime.UtcNow;
await _db.DeleteAdminNote(noteId, deletedBy.UserId, deletedAt); await _db.DeleteAdminNote(noteId, deletedBy.UserId, deletedAt);
NoteDeleted?.Invoke(noteId); var sharedNote = new SharedAdminNote(
noteId,
note.RoundId,
note.PlayerUserId,
note.Message,
note.CreatedBy.LastSeenUserName,
note.LastEditedBy.LastSeenUserName,
note.CreatedAt,
note.LastEditedAt
);
NoteDeleted?.Invoke(sharedNote);
} }
public async Task ModifyNote(int noteId, IPlayerSession editedBy, string message) public async Task ModifyNote(int noteId, IPlayerSession editedBy, string message)
@@ -110,6 +121,7 @@ public sealed class AdminNotesManager : IAdminNotesManager, IPostInjectInit
var sharedNote = new SharedAdminNote( var sharedNote = new SharedAdminNote(
noteId, noteId,
note.RoundId, note.RoundId,
note.PlayerUserId,
message, message,
note.CreatedBy.LastSeenUserName, note.CreatedBy.LastSeenUserName,
editedBy.Name, editedBy.Name,

View File

@@ -9,7 +9,7 @@ public interface IAdminNotesManager
{ {
event Action<SharedAdminNote>? NoteAdded; event Action<SharedAdminNote>? NoteAdded;
event Action<SharedAdminNote>? NoteModified; event Action<SharedAdminNote>? NoteModified;
event Action<int>? NoteDeleted; event Action<SharedAdminNote>? NoteDeleted;
bool CanCreate(IPlayerSession admin); bool CanCreate(IPlayerSession admin);
bool CanDelete(IPlayerSession admin); bool CanDelete(IPlayerSession admin);

View File

@@ -3,4 +3,4 @@
namespace Content.Shared.Administration.Notes; namespace Content.Shared.Administration.Notes;
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed record SharedAdminNote(int Id, int? Round, string Message, string CreatedByName, string EditedByName, DateTime CreatedAt, DateTime LastEditedAt); public sealed record SharedAdminNote(int Id, int? Round, Guid Player, string Message, string CreatedByName, string EditedByName, DateTime CreatedAt, DateTime LastEditedAt);