using decePubClient.Models;
using decePubClient.Models.Mastodon;
using PrivaPub.ClientModels.Group;
namespace decePubClient.Services
{
///
/// 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.
///
public class FeedMemory
{
public static readonly TimeSpan Keep = TimeSpan.FromMinutes(10);
public FeedQuery Query { get; private set; }
public List Posts { get; private set; } = [];
public List Pending { get; private set; } = [];
public List Groups { get; private set; } = [];
public List 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 posts, List pending, List groups, List 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;
}
/// Whether what is kept is recent and belongs to this persona.
public bool Holds(string personaId) => Query is not null && Query.PersonaId == personaId && DateTime.UtcNow - SavedAt < Keep;
public void Forget()
{
Query = null;
Posts = [];
Pending = [];
}
}
}