[backend/razor] Extract identicon url generation into User.IdenticonUrlPath property

This commit is contained in:
Laura Hausmann 2024-09-18 21:31:27 +02:00
parent 7e55d4609b
commit e9ce3f3fa3
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 6 additions and 5 deletions

View file

@ -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<User>

View file

@ -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;
<div class="user">
<img src="@avatarUrl" class="avatar" alt="User avatar"/>

View file

@ -23,7 +23,7 @@ else
{
<meta name="og:description" content="@bio">
}
<meta name="og:image" content="@(Model.User.AvatarUrl ?? $"/identicon/{Model.User.Id}")">
<meta name="og:image" content="@(Model.User.AvatarUrl ?? Model.User.IdenticonUrlPath)">
}
<div class="user">