a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend/razor] Port Federation List page to .razor

authored by

pancakes and committed by
Laura Hausmann
65d2332e 96f7bbff

+171 -174
-94
Iceshrimp.Backend/Pages/FederationList.cshtml
··· 1 - @page "/federation" 2 - @using Iceshrimp.Backend.Core.Extensions 3 - @model Iceshrimp.Backend.Pages.FederationList 4 - 5 - <h2>Federation List (@(Model.ModeString) Instances)</h2> 6 - 7 - @if (Model.ShouldShowList) 8 - { 9 - @if (Model.IsBlocklist && Model.ReasonsRegOnly && !Model.ShouldShowReasons) 10 - { 11 - <p> 12 - <i>Note: Block reasons are only shown to registered users on this instance.</i> 13 - </p> 14 - } 15 - else if (Model.IsBlocklist && !Model.ShouldShowReasons) 16 - { 17 - <p> 18 - <i>Note: Block reasons are only displayed to admins of this instance.</i> 19 - </p> 20 - } 21 - <table> 22 - <thead> 23 - <th>Host</th> 24 - @if (Model.IsBlocklist && Model.ShouldShowReasons) 25 - { 26 - <th>Reason</th> 27 - } 28 - </thead> 29 - <tbody> 30 - @if (Model.IsBlocklist) 31 - { 32 - @foreach (var instance in Model.BlockedInstances) 33 - { 34 - <tr> 35 - @{ 36 - var host = instance.Host; 37 - if (host.StartsWith("xn--")) 38 - host = $"{host.FromPunycode()} ({host})"; 39 - } 40 - <td>@host</td> 41 - 42 - @if (Model.ShouldShowReasons) 43 - { 44 - <td> 45 - @if (instance.Reason is not null) 46 - { 47 - @instance.Reason 48 - } 49 - else 50 - { 51 - <i>No reason set</i> 52 - } 53 - </td> 54 - } 55 - </tr> 56 - } 57 - } 58 - else 59 - { 60 - @foreach (var instance in Model.AllowedInstances) 61 - { 62 - <tr> 63 - @{ 64 - var host = instance.Host; 65 - if (host.StartsWith("xn--")) 66 - host = host.FromPunycode() + $"({instance.Host})"; 67 - } 68 - <td>@host</td> 69 - </tr> 70 - } 71 - } 72 - </tbody> 73 - </table> 74 - } 75 - else if (Model.ListRegOnly) 76 - { 77 - <p> 78 - <i>This list is only available to registered users on this instance.</i> 79 - </p> 80 - } 81 - else 82 - { 83 - <p> 84 - <i>This list is only displayed to admins of this instance.</i> 85 - </p> 86 - } 87 - 88 - 89 - @if (Model.ShouldShowList && Model.BlockedInstances is [] && Model.AllowedInstances is []) 90 - { 91 - <p> 92 - <i>No instances @(Model.ModeString?.ToLower()).</i> 93 - </p> 94 - }
-80
Iceshrimp.Backend/Pages/FederationList.cshtml.cs
··· 1 - using Iceshrimp.Backend.Core.Configuration; 2 - using Iceshrimp.Backend.Core.Database; 3 - using Iceshrimp.Backend.Core.Database.Tables; 4 - using Iceshrimp.Backend.Core.Middleware; 5 - using Microsoft.AspNetCore.Mvc.RazorPages; 6 - using Microsoft.EntityFrameworkCore; 7 - using Microsoft.Extensions.Options; 8 - 9 - namespace Iceshrimp.Backend.Pages; 10 - 11 - [Authenticate] 12 - public class FederationList ( 13 - DatabaseContext db, 14 - IOptionsSnapshot<Config.SecuritySection> security 15 - ) : PageModel 16 - { 17 - public bool IsBlocklist; 18 - public string? ModeString; 19 - 20 - public bool ListRegOnly; 21 - public bool ReasonsRegOnly; 22 - 23 - public bool IsLoggedIn; 24 - public bool IsAdmin; 25 - 26 - public bool ShouldShowList; 27 - public bool ShouldShowReasons; 28 - 29 - public BlockedInstance[] BlockedInstances = []; 30 - public AllowedInstance[] AllowedInstances = []; 31 - 32 - public async Task OnGet() 33 - { 34 - if (Request.Cookies.TryGetValue("sessions", out var sessions)) 35 - { 36 - var tokens = sessions.Split('|'); 37 - if (await db.Sessions.AnyAsync(p => tokens.Contains(p.Token))) 38 - { 39 - IsLoggedIn = true; 40 - Request.HttpContext.HideFooter(); 41 - } 42 - } 43 - else 44 - { 45 - IsLoggedIn = false; 46 - } 47 - 48 - if (Request.Cookies.TryGetValue("admin_session", out var admSession) 49 - && await db.Sessions.AnyAsync(p => p.Token == admSession && p.Active && p.User.IsAdmin)) 50 - { 51 - IsAdmin = true; 52 - } 53 - 54 - IsBlocklist = security.Value.FederationMode == Enums.FederationMode.BlockList; 55 - ModeString = IsBlocklist ? "Blocked" : "Allowed"; 56 - 57 - ListRegOnly = security.Value.ExposeFederationList == Enums.ItemVisibility.Registered; 58 - ReasonsRegOnly = security.Value.ExposeBlockReasons == Enums.ItemVisibility.Registered; 59 - 60 - ShouldShowList = (security.Value.ExposeFederationList == Enums.ItemVisibility.Public) || (ListRegOnly && IsLoggedIn) || IsAdmin; 61 - ShouldShowReasons = (security.Value.ExposeBlockReasons == Enums.ItemVisibility.Public) || (ReasonsRegOnly && IsLoggedIn) || IsAdmin; 62 - 63 - if (!ShouldShowList) return; 64 - 65 - if (IsBlocklist) 66 - { 67 - BlockedInstances = await db.BlockedInstances 68 - .Select(p => new BlockedInstance { Host = p.Host, Reason = p.Reason }) 69 - .OrderBy(p => p.Host) 70 - .ToArrayAsync(); 71 - } 72 - else 73 - { 74 - AllowedInstances = await db.AllowedInstances 75 - .Select(p => new AllowedInstance { Host = p.Host }) 76 - .OrderBy(p => p.Host) 77 - .ToArrayAsync(); 78 - } 79 - } 80 - }
+107
Iceshrimp.Backend/Pages/FederationList.razor
··· 1 + @page "/federation" 2 + @using Iceshrimp.Backend.Core.Configuration 3 + @inherits AsyncComponentBase 4 + 5 + @if (IsAllowList) 6 + { 7 + <PageTitle>Allowed Instances - @(InstanceName ?? "Iceshrimp.NET")</PageTitle> 8 + @if (List.Count != 0) 9 + { 10 + <h2>Federation List (@(List.Count) Allowed Instances)</h2> 11 + } 12 + else 13 + { 14 + <h2>Federation List (Allowed Instances)</h2> 15 + } 16 + } 17 + else 18 + { 19 + <PageTitle>Blocked Instances - @(InstanceName ?? "Iceshrimp.NET")</PageTitle> 20 + @if (List.Count != 0) 21 + { 22 + <h2>Federation List (@(List.Count) Blocked Instances)</h2> 23 + } 24 + else 25 + { 26 + <h2>Federation List (Blocked Instances)</h2> 27 + } 28 + } 29 + 30 + @if (DisplayList == Enums.ItemVisibility.Registered && !IsLoggedIn) 31 + { 32 + <p> 33 + <i>This list is only available to registered users on this instance.</i> 34 + </p> 35 + 36 + return; 37 + } 38 + @if (DisplayList == Enums.ItemVisibility.Hide && !IsAdmin) 39 + { 40 + <p> 41 + <i>This list is only displayed to admins of this instance.</i> 42 + </p> 43 + 44 + return; 45 + } 46 + 47 + @if (DisplayReasons == Enums.ItemVisibility.Registered && !IsLoggedIn) 48 + { 49 + <p> 50 + <i>Note: Block reasons are only shown to registered users on this instance.</i> 51 + </p> 52 + } 53 + else if (DisplayReasons == Enums.ItemVisibility.Hide && !IsAdmin) 54 + { 55 + <p> 56 + <i>Note: Block reasons are only displayed to the admins of this instance.</i> 57 + </p> 58 + } 59 + 60 + <table> 61 + <thead> 62 + <tr> 63 + <th>Host</th> 64 + @if (!IsAllowList && !HideReasons) 65 + { 66 + <th>Reason</th> 67 + } 68 + </tr> 69 + </thead> 70 + <tbody> 71 + @foreach (var entry in List) 72 + { 73 + <tr> 74 + <td>@entry.Key</td> 75 + @if (!IsAllowList && !HideReasons) 76 + { 77 + <td> 78 + @if (string.IsNullOrWhiteSpace(entry.Value)) 79 + { 80 + <i>No reason set</i> 81 + } 82 + else 83 + { 84 + @entry.Value 85 + } 86 + </td> 87 + } 88 + </tr> 89 + } 90 + </tbody> 91 + </table> 92 + 93 + @if (List.Count == 0) 94 + { 95 + @if (IsAllowList) 96 + { 97 + <p> 98 + <i>This instance does not allow any instances.</i> 99 + </p> 100 + } 101 + else 102 + { 103 + <p> 104 + <i>This instance does not block any instances.</i> 105 + </p> 106 + } 107 + }
+64
Iceshrimp.Backend/Pages/FederationList.razor.cs
··· 1 + using Iceshrimp.Backend.Components.Helpers; 2 + using Iceshrimp.Backend.Core.Configuration; 3 + using Microsoft.AspNetCore.Components; 4 + using Microsoft.EntityFrameworkCore; 5 + using Microsoft.Extensions.Options; 6 + 7 + namespace Iceshrimp.Backend.Pages; 8 + 9 + public partial class FederationList(IOptionsSnapshot<Config.SecuritySection> security) : AsyncComponentBase 10 + { 11 + [CascadingParameter(Name = "InstanceName")] 12 + public required string? InstanceName { get; set; } 13 + 14 + private bool IsAllowList { get; set; } 15 + private bool IsLoggedIn { get; set; } 16 + private bool IsAdmin { get; set; } 17 + private Enums.ItemVisibility DisplayList { get; set; } 18 + private Enums.ItemVisibility DisplayReasons { get; set; } 19 + private bool HideReasons { get; set; } 20 + private Dictionary<string, string> List { get; set; } = []; 21 + 22 + protected override async Task OnInitializedAsync() 23 + { 24 + if (Context.Request.Cookies.TryGetValue("sessions", out var sessions)) 25 + { 26 + var tokens = sessions.Split('|'); 27 + if (await Database.Sessions.AnyAsync(p => tokens.Contains(p.Token))) 28 + { 29 + IsLoggedIn = true; 30 + } 31 + } 32 + 33 + if (Context.Request.Cookies.TryGetValue("admin_session", out var admSession) 34 + && await Database.Sessions.AnyAsync(p => p.Token == admSession && p.Active && p.User.IsAdmin)) 35 + { 36 + IsAdmin = true; 37 + } 38 + 39 + IsAllowList = security.Value.FederationMode == Enums.FederationMode.AllowList; 40 + DisplayList = security.Value.ExposeFederationList; 41 + DisplayReasons = security.Value.ExposeBlockReasons; 42 + 43 + if ((DisplayList == Enums.ItemVisibility.Registered && !IsLoggedIn) 44 + || (DisplayList == Enums.ItemVisibility.Hide && !IsAdmin)) 45 + return; 46 + 47 + if ((DisplayReasons == Enums.ItemVisibility.Registered && !IsLoggedIn) 48 + || (DisplayReasons == Enums.ItemVisibility.Hide && !IsAdmin)) 49 + HideReasons = true; 50 + 51 + if (IsAllowList) 52 + { 53 + List = await Database.AllowedInstances 54 + .OrderBy(p => p.Host) 55 + .ToDictionaryAsync(p => p.Host, p => ""); 56 + } 57 + else 58 + { 59 + List = await Database.BlockedInstances 60 + .OrderBy(p => p.Host) 61 + .ToDictionaryAsync(p => p.Host, p => p.Reason ?? ""); 62 + } 63 + } 64 + }