Added Pastes into the feed

This commit is contained in:
Gordon Pedersen 2024-07-25 13:39:36 +10:00
parent 04a5641650
commit 1fe82c18af
3 changed files with 15 additions and 9 deletions

View file

@ -24,7 +24,7 @@ namespace Neighbourhood.omg.lol {
public List<MarkupString>? EphemeralMessages { get; set; }
public List<string>? AddressDirectory { get; set; }
public List<StatusOrPic>? Feed { get; set; }
public List<FeedItem>? Feed { get; set; }
public Dictionary<string, Theme>? Themes { get; set; }
@ -316,12 +316,13 @@ namespace Neighbourhood.omg.lol {
await GetPastes(SelectedAddressName, forceRefresh: true);
}
public async Task<IOrderedEnumerable<StatusOrPic>> GetFeed(bool forceRefresh = false) {
public async Task<IOrderedEnumerable<FeedItem>> GetFeed(bool forceRefresh = false) {
if(forceRefresh || Feed == null || Feed.Count == 0) {
Feed = new List<StatusOrPic>();
Feed = new List<FeedItem>();
foreach(string address in Following ?? new List<string>()) {
Feed.AddRange((await GetStatuses(address, forceRefresh))?.Select(s => new StatusOrPic { Status = s }) ?? new List<StatusOrPic>());
Feed.AddRange((await GetPics(address, forceRefresh))?.Select(p => new StatusOrPic { Pic = p }) ?? new List<StatusOrPic>());
Feed.AddRange((await GetStatuses(address, forceRefresh))?.Select(s => new FeedItem { Status = s }) ?? new List<FeedItem>());
Feed.AddRange((await GetPics(address, forceRefresh))?.Select(p => new FeedItem { Pic = p }) ?? new List<FeedItem>());
Feed.AddRange((await GetPastes(address, forceRefresh))?.Select(p => new FeedItem { Paste = p }) ?? new List<FeedItem>());
}
}
return Feed.OrderByDescending(s => s.CreatedTime);

View file

@ -35,13 +35,16 @@ else {
<div class="responsive page-container">
<div id="feed" class="page no-padding active">
@if (feed != null){
foreach (StatusOrPic item in feed) {
foreach (FeedItem item in feed) {
if (item.IsStatus) {
<StatusCard Status="@item.Status"></StatusCard>
}
else if (item.IsPic) {
<PicCard Pic="@item.Pic"></PicCard>
}
else if (item.IsPaste) {
<PasteCard Paste="@item.Paste"></PasteCard>
}
}
}
<LoadingCard id="feedLoading" icon="fa-solid fa-list-timeline"></LoadingCard>
@ -75,7 +78,7 @@ else {
}
@code {
private IOrderedEnumerable<StatusOrPic>? feed;
private IOrderedEnumerable<FeedItem>? feed;
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();

View file

@ -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; }
}
}