From 1fe82c18afc710330b91ac4af842261ac9647e63 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Thu, 25 Jul 2024 13:39:36 +1000 Subject: [PATCH] Added Pastes into the feed --- Classes/State.cs | 11 ++++++----- Components/Pages/Feed.razor | 7 +++++-- Models/{StatusOrPic.cs => FeedItem.cs} | 6 ++++-- 3 files changed, 15 insertions(+), 9 deletions(-) rename Models/{StatusOrPic.cs => FeedItem.cs} (63%) diff --git a/Classes/State.cs b/Classes/State.cs index 399dcff..e848f44 100644 --- a/Classes/State.cs +++ b/Classes/State.cs @@ -24,7 +24,7 @@ namespace Neighbourhood.omg.lol { public List? EphemeralMessages { get; set; } public List? AddressDirectory { get; set; } - public List? Feed { get; set; } + public List? Feed { get; set; } public Dictionary? Themes { get; set; } @@ -316,12 +316,13 @@ namespace Neighbourhood.omg.lol { await GetPastes(SelectedAddressName, forceRefresh: true); } - public async Task> GetFeed(bool forceRefresh = false) { + public async Task> GetFeed(bool forceRefresh = false) { if(forceRefresh || Feed == null || Feed.Count == 0) { - Feed = new List(); + Feed = new List(); foreach(string address in Following ?? new List()) { - Feed.AddRange((await GetStatuses(address, forceRefresh))?.Select(s => new StatusOrPic { Status = s }) ?? new List()); - Feed.AddRange((await GetPics(address, forceRefresh))?.Select(p => new StatusOrPic { Pic = p }) ?? new List()); + Feed.AddRange((await GetStatuses(address, forceRefresh))?.Select(s => new FeedItem { Status = s }) ?? new List()); + Feed.AddRange((await GetPics(address, forceRefresh))?.Select(p => new FeedItem { Pic = p }) ?? new List()); + Feed.AddRange((await GetPastes(address, forceRefresh))?.Select(p => new FeedItem { Paste = p }) ?? new List()); } } return Feed.OrderByDescending(s => s.CreatedTime); diff --git a/Components/Pages/Feed.razor b/Components/Pages/Feed.razor index 9386a44..bcd718a 100644 --- a/Components/Pages/Feed.razor +++ b/Components/Pages/Feed.razor @@ -35,13 +35,16 @@ else {
@if (feed != null){ - foreach (StatusOrPic item in feed) { + foreach (FeedItem item in feed) { if (item.IsStatus) { } else if (item.IsPic) { } + else if (item.IsPaste) { + + } } } @@ -75,7 +78,7 @@ else { } @code { - private IOrderedEnumerable? feed; + private IOrderedEnumerable? feed; protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); diff --git a/Models/StatusOrPic.cs b/Models/FeedItem.cs similarity index 63% rename from Models/StatusOrPic.cs rename to Models/FeedItem.cs index 5542be4..345c173 100644 --- a/Models/StatusOrPic.cs +++ b/Models/FeedItem.cs @@ -1,11 +1,13 @@ namespace Neighbourhood.omg.lol.Models { - public class StatusOrPic { + public class FeedItem { public Status? Status { get; set; } public Pic? Pic { get; set; } + public Paste? Paste { get; set; } public bool IsStatus { get => Status != null; } public bool IsPic { get => Pic != null; } + public bool IsPaste { get => Paste != null; } - public DateTimeOffset? CreatedTime { get => Status?.CreatedTime ?? Pic?.CreatedTime; } + public DateTimeOffset? CreatedTime { get => Status?.CreatedTime ?? Pic?.CreatedTime ?? Paste?.ModifiedTime; } } }