From 326292c79de32530de142ce727295f7bf8217da3 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 31 Mar 2021 14:08:05 +0200 Subject: [PATCH] More avatar updates, fewer repetitive calls --- OurUmbraco/Community/People/AvatarService.cs | 6 +++++- OurUmbraco/Our/Models/MemberData.cs | 1 - OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs | 6 ++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/OurUmbraco/Community/People/AvatarService.cs b/OurUmbraco/Community/People/AvatarService.cs index 348e664427..3b495d224e 100644 --- a/OurUmbraco/Community/People/AvatarService.cs +++ b/OurUmbraco/Community/People/AvatarService.cs @@ -245,7 +245,11 @@ internal static string GetCleanImagePath(string imgPath) { if (imgPath == null) return string.Empty; - + + var siteDirectory = HostingEnvironment.MapPath("~"); + if (imgPath.StartsWith(siteDirectory)) + imgPath = imgPath.Replace(siteDirectory, string.Empty).Replace("\\", "/"); + var cleanImagePath = imgPath.Replace(" ", "%20").TrimStart("~"); if (cleanImagePath.Contains("?")) cleanImagePath = cleanImagePath.Substring(0, cleanImagePath.IndexOf("?", StringComparison.Ordinal)); diff --git a/OurUmbraco/Our/Models/MemberData.cs b/OurUmbraco/Our/Models/MemberData.cs index 473b7a436b..c1befd9609 100644 --- a/OurUmbraco/Our/Models/MemberData.cs +++ b/OurUmbraco/Our/Models/MemberData.cs @@ -20,7 +20,6 @@ public class MemberData public int NumberOfForumPosts { get; set; } public string AvatarHtml { get; set; } public string AvatarPath { get; set; } - public Image AvatarImage { get; set; } public bool AvatarImageTooSmall { get; set; } public bool IsBlocked { get; set; } public bool NewTosAccepted { get; set; } diff --git a/OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs b/OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs index 90562049db..1b6f668be1 100644 --- a/OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs +++ b/OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs @@ -53,18 +53,16 @@ private static MemberData GetMemberData() if ((newTosDate - tosAccepted).TotalDays > 1) newTosAccepted = false; - var avatarPath = avatarService.GetMemberAvatar(member); - var avatarHtml = avatarService.GetImgWithSrcSet(avatarPath, member.Name, 100); + var avatarHtml = avatarService.GetImgWithSrcSet(memberAvatarPath, member.Name, 100); var data = new MemberData { Member = member, - AvatarImage = avatarImage, AvatarImageTooSmall = avatarImage != null && (avatarImage.Width < 400 || avatarImage.Height < 400), Roles = roles, LatestTopics = latestTopics, AvatarHtml = avatarHtml, - AvatarPath = avatarPath, + AvatarPath = memberAvatarPath, NumberOfForumPosts = member.ForumPosts(), Karma = member.Karma(), TwitterHandle = member.GetPropertyValue("twitter").Replace("@", string.Empty),