Datetime based changelogs
This commit is contained in:
parent
98ac140cad
commit
29510cb4be
|
|
@ -1,5 +1,6 @@
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Shared.Configuration;
|
||||
|
|
@ -25,8 +26,8 @@ namespace Content.Client.Changelog
|
|||
private ISawmill _sawmill = default!;
|
||||
|
||||
public bool NewChangelogEntries { get; private set; }
|
||||
public int LastReadId { get; private set; }
|
||||
public int MaxId { get; private set; }
|
||||
public DateTime LastReadTime { get; private set; }
|
||||
public DateTime MaxTime { get; private set; }
|
||||
|
||||
public event Action? NewChangelogEntriesChanged;
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ namespace Content.Client.Changelog
|
|||
/// stores the new ID to disk and clears <see cref="NewChangelogEntries"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="LastReadId"/> is NOT cleared
|
||||
/// <see cref="MaxTime"/> is NOT cleared
|
||||
/// since that's used in the changelog menu to show the "since you last read" bar.
|
||||
/// </remarks>
|
||||
public void SaveNewReadId()
|
||||
|
|
@ -43,9 +44,11 @@ namespace Content.Client.Changelog
|
|||
NewChangelogEntries = false;
|
||||
NewChangelogEntriesChanged?.Invoke();
|
||||
|
||||
using var sw = _resource.UserData.OpenWriteText(new ($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}"));
|
||||
using var sw =
|
||||
_resource.UserData.OpenWriteText(
|
||||
new($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_datetime"));
|
||||
|
||||
sw.Write(MaxId.ToString());
|
||||
sw.Write(MaxTime.ToString("O"));
|
||||
}
|
||||
|
||||
public async void Initialize()
|
||||
|
|
@ -80,15 +83,19 @@ namespace Content.Client.Changelog
|
|||
return;
|
||||
}
|
||||
|
||||
MaxId = changelog.Entries.Max(c => c.Id);
|
||||
MaxTime = changelog.Entries.Max(c => c.Time);
|
||||
|
||||
var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}");
|
||||
if (_resource.UserData.TryReadAllText(path, out var lastReadIdText))
|
||||
var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_datetime");
|
||||
if(_resource.UserData.TryReadAllText(path, out var lastReadTimeText))
|
||||
{
|
||||
LastReadId = int.Parse(lastReadIdText);
|
||||
if (Regex.IsMatch(lastReadTimeText,
|
||||
@"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$"))
|
||||
{
|
||||
LastReadTime = DateTime.ParseExact(lastReadTimeText, "O", CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
NewChangelogEntries = LastReadId < MaxId;
|
||||
NewChangelogEntries = LastReadTime < MaxTime;
|
||||
|
||||
NewChangelogEntriesChanged?.Invoke();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ public sealed partial class ChangelogTab : Control
|
|||
.OrderByDescending(c => c.Key);
|
||||
|
||||
var hasRead = changelog.Name != MainChangelogName ||
|
||||
_changelog.MaxId <= _changelog.LastReadId;
|
||||
_changelog.MaxTime <= _changelog.LastReadTime;
|
||||
|
||||
foreach (var dayEntries in byDay)
|
||||
{
|
||||
var day = dayEntries.Key;
|
||||
|
||||
var groupedEntries = dayEntries
|
||||
.GroupBy(c => (c.Author, Read: c.Id <= _changelog.LastReadId))
|
||||
.GroupBy(c => (c.Author, Read: c.Time <= _changelog.LastReadTime))
|
||||
.OrderBy(c => c.Key.Read)
|
||||
.ThenBy(c => c.Key.Author);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue