Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple changelogs #897

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions Content.Client/Changelog/ChangelogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public sealed partial class ChangelogManager : IPostInjectInit
private ISawmill _sawmill = default!;

public bool NewChangelogEntries { get; private set; }
public int LastReadId { get; private set; }
public int MaxId { get; private set; }
public Dictionary<string, int> LastReadId { get; private set; } = new Dictionary<string, int>();
public Dictionary<string, int> MaxId { get; private set; } = new Dictionary<string, int>();

public event Action? NewChangelogEntriesChanged;

Expand All @@ -36,14 +36,18 @@ public sealed partial class ChangelogManager : IPostInjectInit
/// <see cref="LastReadId"/> is NOT cleared
/// since that's used in the changelog menu to show the "since you last read" bar.
/// </remarks>
public void SaveNewReadId()
public async void SaveNewReadId()
{
NewChangelogEntries = false;
NewChangelogEntriesChanged?.Invoke();

using var sw = _resource.UserData.OpenWriteText(new ($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}"));
var changelogs = await LoadChangelog();

sw.Write(MaxId.ToString());
foreach (var changelog in changelogs)
{
using var sw = _resource.UserData.OpenWriteText(new($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_{changelog.Name}"));
sw.Write(MaxId[changelog.Name].ToString());
}
}

public async void Initialize()
Expand All @@ -67,26 +71,30 @@ private void UpdateChangelogs(List<Changelog> changelogs)
return;
}

var changelog = changelogs[0];
if (mainChangelogs.Length > 1)
{
_sawmill.Error($"More than one file found in Resource/Changelog with name {MainChangelogName}");
}

if (changelog.Entries.Count == 0)
{
if (changelogs[0].Entries.Count == 0)
return;
}

MaxId = changelog.Entries.Max(c => c.Id);
NewChangelogEntries = false;

var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}");
if (_resource.UserData.TryReadAllText(path, out var lastReadIdText))
foreach (var changelog in changelogs)
{
LastReadId = int.Parse(lastReadIdText);
}
var name = changelog.Name;

NewChangelogEntries = LastReadId < MaxId;
MaxId.Add(name, changelog.Entries.Max(c => c.Id));
LastReadId.Add(name, 0);

var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_{name}");
if (_resource.UserData.TryReadAllText(path, out var lastReadIdText))
{
LastReadId[name] = int.Parse(lastReadIdText);
}

if (!changelog.AdminOnly)
NewChangelogEntries = NewChangelogEntries || LastReadId[name] < MaxId[name];
}

NewChangelogEntriesChanged?.Invoke();
}
Expand Down
7 changes: 4 additions & 3 deletions Content.Client/Changelog/ChangelogTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ public ChangelogTab()

public void PopulateChangelog(ChangelogManager.Changelog changelog)
{
var name = changelog.Name;

var byDay = changelog.Entries
.GroupBy(e => e.Time.ToLocalTime().Date)
.OrderByDescending(c => c.Key);

var hasRead = changelog.Name != MainChangelogName ||
_changelog.MaxId <= _changelog.LastReadId;
var hasRead = _changelog.MaxId[name] <= _changelog.LastReadId[name];

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.Id <= _changelog.LastReadId[name]))
.OrderBy(c => c.Key.Read)
.ThenBy(c => c.Key.Author);

Expand Down
Loading