From e9ce3f3fa374f3c3cce223ed2b31a59336a2c232 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 18 Sep 2024 21:31:27 +0200 Subject: [PATCH] [backend/razor] Extract identicon url generation into User.IdenticonUrlPath property --- Iceshrimp.Backend/Core/Database/Tables/User.cs | 7 ++++--- Iceshrimp.Backend/Pages/Note.cshtml | 2 +- Iceshrimp.Backend/Pages/User.cshtml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Iceshrimp.Backend/Core/Database/Tables/User.cs b/Iceshrimp.Backend/Core/Database/Tables/User.cs index 9c4d9a46..96def218 100644 --- a/Iceshrimp.Backend/Core/Database/Tables/User.cs +++ b/Iceshrimp.Backend/Core/Database/Tables/User.cs @@ -491,8 +491,9 @@ public class User : IEntity [NotMapped] public bool? PrecomputedIsRequested { get; set; } [NotMapped] public bool? PrecomputedIsRequestedBy { get; set; } - [Projectable] public bool IsLocalUser => Host == null; - [Projectable] public bool IsRemoteUser => Host != null; + [Projectable] public bool IsLocalUser => Host == null; + [Projectable] public bool IsRemoteUser => Host != null; + [Projectable] public string IdenticonUrlPath => $"/identicon/{Id}"; [Key] [Column("id")] @@ -622,7 +623,7 @@ public class User : IEntity ? $"https://{webDomain}/@{Username}" : throw new Exception("Cannot access PublicUrl for remote user"); - public string GetIdenticonUrl(string webDomain) => $"https://{webDomain}/identicon/{Id}"; + public string GetIdenticonUrl(string webDomain) => $"https://{webDomain}{IdenticonUrlPath}"; } public class UserEntityTypeConfiguration : IEntityTypeConfiguration diff --git a/Iceshrimp.Backend/Pages/Note.cshtml b/Iceshrimp.Backend/Pages/Note.cshtml index 01eae345..fb2c0a67 100644 --- a/Iceshrimp.Backend/Pages/Note.cshtml +++ b/Iceshrimp.Backend/Pages/Note.cshtml @@ -19,7 +19,7 @@ else var acct = "@" + note.User.Username + (note.User.IsLocalUser ? "" : "@" + note.User.Host); var displayName = note.User.DisplayName; var username = note.User.Username; - var avatarUrl = note.User.AvatarUrl == null || !Model.ShowMedia ? $"/identicon/{note.User.Id}" : note.User.AvatarUrl; + var avatarUrl = note.User.AvatarUrl == null || !Model.ShowMedia ? note.User.IdenticonUrlPath : note.User.AvatarUrl;
User avatar diff --git a/Iceshrimp.Backend/Pages/User.cshtml b/Iceshrimp.Backend/Pages/User.cshtml index c6e3bdd5..34e6eb0c 100644 --- a/Iceshrimp.Backend/Pages/User.cshtml +++ b/Iceshrimp.Backend/Pages/User.cshtml @@ -23,7 +23,7 @@ else { } - + }