1
0

UserNotesEui.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using Content.Server.EUI;
  4. using Content.Shared.Administration.Notes;
  5. using Content.Shared.CCVar;
  6. using Content.Shared.Database;
  7. using Content.Shared.Eui;
  8. using Robust.Shared.Configuration;
  9. namespace Content.Server.Administration.Notes;
  10. public sealed class UserNotesEui : BaseEui
  11. {
  12. [Dependency] private readonly IAdminNotesManager _notesMan = default!;
  13. [Dependency] private readonly IConfigurationManager _cfg = default!;
  14. private readonly bool _seeOwnNotes;
  15. public UserNotesEui()
  16. {
  17. IoCManager.InjectDependencies(this);
  18. _seeOwnNotes = _cfg.GetCVar(CCVars.SeeOwnNotes);
  19. if (!_seeOwnNotes)
  20. {
  21. Logger.WarningS("admin.notes", "User notes initialized when see_own_notes set to false");
  22. }
  23. }
  24. private Dictionary<(int, NoteType), SharedAdminNote> Notes { get; set; } = new();
  25. public override EuiStateBase GetNewState()
  26. {
  27. return new UserNotesEuiState(
  28. Notes
  29. );
  30. }
  31. public async Task UpdateNotes()
  32. {
  33. if (!_seeOwnNotes)
  34. {
  35. Logger.WarningS("admin.notes", $"User {Player.Name} with ID {Player.UserId} tried to update their own user notes when see_own_notes was set to false");
  36. return;
  37. }
  38. Notes = (await _notesMan.GetVisibleRemarks(Player.UserId)).Select(note => note.ToShared()).ToDictionary(note => (note.Id, note.NoteType));
  39. StateDirty();
  40. }
  41. }