Files
tbd-station-14/Content.Server/Administration/Notes/AdminMessageEui.cs
Pieter-Jan Briers 2e6eaa45c5 Fix admin notes and database time nonsense. (#25280)
God bloody christ. There's like three layers of shit here.

So firstly, apparently we were still using Npgsql.EnableLegacyTimestampBehavior. This means that time values (which are stored UTC in the database) were converted to local time when read out. This meant they were passed around as kind Local to clients (instead of UTC in the case of SQLite). That's easy enough to fix just turn off the flag and fix the couple spots we're passing a local DateTime ez.

Oh but it turns out there's a DIFFERENT problem with SQLite: See SQLite we definitely store the DateTimes as UTC, but when Microsoft.Data.Sqlite reads them it reads them as Kind Unspecified instead of Utc.

Why are these so bad? Because the admin notes system passes DateTime instances from EF Core straight to the rest of the game code. And that means it's a PAIN IN THE ASS to run the necessary conversions to fix the DateTime instances. GOD DAMNIT now I have to make a whole new set of "Record" entities so we avoid leaking the EF Core model entities. WAAAAAAA.

Fixes #19897
2024-02-20 10:13:31 +01:00

64 lines
1.8 KiB
C#

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 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!;
private readonly float _closeWait;
private AdminMessageRecord? _message;
private DateTime _startTime;
public AdminMessageEui()
{
IoCManager.InjectDependencies(this);
_closeWait = _cfg.GetCVar(CCVars.MessageWaitTime);
}
public void SetMessage(AdminMessageRecord message)
{
_message = message;
_startTime = DateTime.UtcNow;
StateDirty();
}
public override EuiStateBase GetNewState()
{
if (_message == null)
return new AdminMessageEuiState(float.MaxValue, "An error has occurred.", string.Empty, DateTime.MinValue);
return new AdminMessageEuiState(
_closeWait,
_message.Message,
_message.CreatedBy?.LastSeenUserName ?? "[System]",
_message.CreatedAt.UtcDateTime
);
}
public override async void HandleMessage(EuiMessageBase msg)
{
base.HandleMessage(msg);
switch (msg)
{
case Accept:
if (_message == null)
break;
// No escape
if (DateTime.UtcNow - _startTime >= TimeSpan.FromSeconds(_closeWait))
await _notesMan.MarkMessageAsSeen(_message.Id);
Close();
break;
case Dismiss:
Close();
break;
}
}
}