A persona's lists (PrivaPub's /api/v1/lists): made, renamed, given a replies policy and made exclusive on /lists, filled from the accounts it follows (accounts/search?following=true), and read as the feed's Lists tab. A followed account's profile has a Lists menu to put it in or take it out. ListService does the calls; the e2e tests check each step against PrivaPub's own answer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
115 lines
3.1 KiB
C#
115 lines
3.1 KiB
C#
using collAnon.Client.Services;
|
|
using System.Collections.Specialized;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
using System.Web;
|
|
|
|
using Blazored.LocalStorage;
|
|
|
|
using decePubClient.Models;
|
|
using decePubClient.Models.Types;
|
|
using decePubClient.Resources;
|
|
using decePubClient.Services;
|
|
|
|
using DnetIndexedDb;
|
|
using DnetIndexedDb.Fluent;
|
|
using DnetIndexedDb.Models;
|
|
|
|
using Markdig;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
namespace decePubClient.Extensions;
|
|
|
|
public static class GenericExtensions
|
|
{
|
|
public static IServiceCollection AddIndexedDb(this IServiceCollection services)
|
|
{
|
|
return services.AddIndexedDbDatabase<IndexedDb>(options =>
|
|
{
|
|
var model = new IndexedDbDatabaseModel()
|
|
.WithName("data")
|
|
.WithVersion(3)
|
|
.WithModelId(1);
|
|
|
|
// IStorage.AddLog numbers entries itself (max key + 1), so the key is Id rather than generated. Version 2
|
|
// added this store; version 3 left the mock feed's Message store out of the model.
|
|
model.AddStore(nameof(ClientLogs))
|
|
.WithKey(nameof(ClientLogs.Id))
|
|
.AddUniqueIndex(nameof(ClientLogs.Id))
|
|
.AddIndex(nameof(ClientLogs.TimeStamp));
|
|
|
|
options.UseDatabase(model);
|
|
});
|
|
}
|
|
|
|
public static string GetPassedTime(this DateTime dateTime, CoalescingStringLocalizer localizer)
|
|
{
|
|
var timeframe = DateTime.Now - dateTime.ToLocalTime();
|
|
return (int)timeframe.TotalHours switch
|
|
{
|
|
>= 24 => localizer["{0}d", (int)timeframe.TotalDays],
|
|
>= 1 => localizer["{0}h", (int)timeframe.TotalHours],
|
|
_ => localizer["{0}m", (int)timeframe.TotalMinutes]
|
|
};
|
|
}
|
|
|
|
public static string GetFileSize(this long size, CoalescingStringLocalizer localizer) => size switch
|
|
{
|
|
>= 1_048_576 => localizer["{0}MB", size / 1_048_576],
|
|
_ => localizer["{0}KB", size / 1_024]
|
|
};
|
|
|
|
public static string GetMessageTypeIcon(this MessageType messageType)
|
|
{
|
|
switch (messageType)
|
|
{
|
|
case MessageType.Public:
|
|
return "ion-md-globe";
|
|
case MessageType.Unlisted:
|
|
return "ion-md-unlock";
|
|
case MessageType.FollowersOnly:
|
|
return "ion-md-lock";
|
|
case MessageType.Direct:
|
|
return "ion-md-paper-plane";
|
|
default:
|
|
return default;
|
|
}
|
|
}
|
|
|
|
public static string GetTimelineTypeIcon(this TimelineType timelineType) => timelineType switch
|
|
{
|
|
TimelineType.Home => "ion-md-home",
|
|
TimelineType.Local => "ion-md-people",
|
|
TimelineType.Federation => "ion-md-globe",
|
|
TimelineType.Nearby => "ion-md-locate",
|
|
TimelineType.Groups => "ion-md-contacts",
|
|
TimelineType.Direct => "ion-md-mail",
|
|
TimelineType.Notifications => "ion-md-notifications",
|
|
TimelineType.Favourites => "ion-md-heart",
|
|
TimelineType.Bookmarks => "ion-md-bookmark",
|
|
TimelineType.Tag => "ion-md-pricetag",
|
|
TimelineType.Lists => "ion-md-list",
|
|
_ => default
|
|
};
|
|
|
|
public static string GetMediaTypeIcon(this MediaType mediaType)
|
|
{
|
|
switch (mediaType)
|
|
{
|
|
case MediaType.Images:
|
|
return "ion-md-images";
|
|
case MediaType.Video:
|
|
return "ion-md-videocam";
|
|
case MediaType.Documents:
|
|
return "ion-md-document";
|
|
case MediaType.Audio:
|
|
return "ion-md-volume-high";
|
|
default:
|
|
return default;
|
|
}
|
|
}
|
|
} |