Files
decePubClient/Services/FeedMemory.cs
T
thepraandClaude Opus 5.5 23dbc68fb4 Coming back to the feed shows it as it was left
Leaving the feed keeps it in Services/FeedMemory.cs (posts, waiting posts, cursors and scroll; ten minutes, for the same
feed of the same persona), so coming back from a thread or a profile shows it again at once, older pages included,
instead of reading it anew; newer posts come behind the "new" button and through the stream as before.
tests/e2e FeedMemoryTests goes to a thread and back without a new read of the home timeline; the whole suite passes
(123, 5 skipped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
2026-10-06 01:21:41 +02:00

52 lines
1.7 KiB
C#

using decePubClient.Models;
using decePubClient.Models.Mastodon;
using PrivaPub.ClientModels.Group;
namespace decePubClient.Services
{
/// <summary>
/// The feed as the reader left it: its query, posts, waiting posts, cursors and scroll. Coming back from a thread or a
/// profile shows it again at once instead of reading it anew; newer posts come behind the "new" button as usual. Kept
/// ten minutes, and only for the same feed of the same persona.
/// </summary>
public class FeedMemory
{
public static readonly TimeSpan Keep = TimeSpan.FromMinutes(10);
public FeedQuery Query { get; private set; }
public List<FeedPost> Posts { get; private set; } = [];
public List<FeedPost> Pending { get; private set; } = [];
public List<ViewGroup> Groups { get; private set; } = [];
public List<MastodonList> Lists { get; private set; } = [];
public string MinId { get; private set; }
public string MaxId { get; private set; }
public double ScrollTop { get; private set; }
public DateTime SavedAt { get; private set; }
public void Save(FeedQuery query, List<FeedPost> posts, List<FeedPost> pending, List<ViewGroup> groups, List<MastodonList> lists,
string minId, string maxId, double scrollTop)
{
Query = query;
Posts = posts;
Pending = pending;
Groups = groups;
Lists = lists;
MinId = minId;
MaxId = maxId;
ScrollTop = scrollTop;
SavedAt = DateTime.UtcNow;
}
/// <summary>Whether what is kept is recent and belongs to this persona.</summary>
public bool Holds(string personaId) => Query is not null && Query.PersonaId == personaId && DateTime.UtcNow - SavedAt < Keep;
public void Forget()
{
Query = null;
Posts = [];
Pending = [];
}
}
}