Files
tbd-station-14/Content.Server/Administration/Notes/AdminMessageEui.cs
Pieter-Jan Briers d776c4b392 Improve admin message seen/dismiss state. (#26223)
Fixes #26211

Admin messages now have separate "seen" and "dismissed" fields. The idea is that an admin should be able to tell whether a user pressed the "dismiss for now" button. Instead of using "seen" as "show this message to players when they join", "dismissed" is now used for this.

Existing notes in the database will automatically be marked as dismissed on migration. A note cannot be dismissed without being seen (enforced via constraint in the database too, aren't I fancy).

As part of this, it has become impossible for a player to play without dismissing the message in some form. Instead of a shitty popup window, the popup is now a fullscreen overlay that blocks clicks behind it, making the game unplayable. Also, if a user somehow has multiple messages they will be combined into one popup.

Also I had enough respect for the codebase to make it look better and clean up the code somewhat. Yippee.
2024-03-21 16:15:46 +01:00

66 lines
1.9 KiB
C#

using System.Linq;
using Content.Server.Database;
using Content.Server.EUI;
using Content.Shared.Administration.Notes;
using Content.Shared.CCVar;
using Content.Shared.Eui;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using static Content.Shared.Administration.Notes.AdminMessageEuiMsg;
namespace Content.Server.Administration.Notes;
public sealed class AdminMessageEui : BaseEui
{
[Dependency] private readonly IAdminNotesManager _notesMan = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
private readonly TimeSpan _closeWait;
private readonly TimeSpan _endTime;
private readonly AdminMessageRecord[] _messages;
public AdminMessageEui(AdminMessageRecord[] messages)
{
IoCManager.InjectDependencies(this);
_closeWait = TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.MessageWaitTime));
_endTime = _gameTiming.RealTime + _closeWait;
_messages = messages;
}
public override void Opened()
{
StateDirty();
}
public override EuiStateBase GetNewState()
{
return new AdminMessageEuiState(
_closeWait,
_messages.Select(x => new AdminMessageEuiState.Message(
x.Message,
x.CreatedBy?.LastSeenUserName ?? Loc.GetString("admin-notes-fallback-admin-name"),
x.CreatedAt.UtcDateTime)).ToArray()
);
}
public override async void HandleMessage(EuiMessageBase msg)
{
base.HandleMessage(msg);
switch (msg)
{
case Dismiss dismiss:
if (_gameTiming.RealTime < _endTime)
return;
foreach (var message in _messages)
{
await _notesMan.MarkMessageAsSeen(message.Id, dismiss.Permanent);
}
Close();
break;
}
}
}