diff --git a/OurUmbraco.Site/Views/DisplayTopic.cshtml b/OurUmbraco.Site/Views/DisplayTopic.cshtml index ffa2ff79..170c02c6 100644 --- a/OurUmbraco.Site/Views/DisplayTopic.cshtml +++ b/OurUmbraco.Site/Views/DisplayTopic.cshtml @@ -1,6 +1,54 @@ -@inherits UmbracoTemplatePage +@using OurUmbraco.Forum.Extensions +@using OurUmbraco.Forum.Services +@using OurUmbraco.NotificationsWeb.Library +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage @{ Layout = "~/Views/Master.cshtml"; + + var topicService = new TopicService(ApplicationContext.DatabaseContext); + var topic = topicService.CurrentTopic(Context, ApplicationContext.ApplicationCache.RequestCache, MemberData); + var subscribed = false; + if (MemberData != null && MemberData.Member != null) + { + subscribed = Utils.IsSubscribedToForumTopic(topic.Id, MemberData.Member.Id); + } + + var currentMember = MemberData != null && MemberData.Member != null ? MemberData.Member : null; + + var topicAuthor = currentMember != null && topic.MemberId == currentMember.Id ? currentMember : Members.GetById(topic.MemberId); + var topicMembers = new List { topicAuthor }; + + var memberRoles = currentMember != null && topic.MemberId == currentMember.Id + ? new Dictionary> { { topicAuthor.Id, MemberData.Roles.ToList() } } + : new Dictionary> { { topicAuthor.Id, topicAuthor.GetRoles() } }; + + foreach (var comment in topic.Comments) + { + if (topicMembers.Any(x => x.Id == comment.MemberId) == false) + { + IPublishedContent commentAuthor; + if (MemberData != null && MemberData.Member != null && MemberData.Member.Id == comment.MemberId) + { + commentAuthor = currentMember; + if (memberRoles.ContainsKey(comment.MemberId) == false) + { + var roles = MemberData.Roles.ToList(); + memberRoles.Add(comment.MemberId, roles); + } + } + else + { + commentAuthor = Members.GetById(comment.MemberId); + if (memberRoles.ContainsKey(comment.MemberId) == false) + { + var roles = commentAuthor.GetRoles(); + memberRoles.Add(comment.MemberId, roles); + } + + } + topicMembers.Add(commentAuthor); + } + } }
@@ -8,15 +56,21 @@
- @Html.Action("Render", "Breadcrumb", new { linkToCurrent = true }) + @Html.Action("Render", "Breadcrumb", new {linkToCurrent = true}) - @Html.Partial("~/Views/Partials/Forum/TopicActions.cshtml") + @Html.Partial("~/Views/Partials/Forum/TopicActions.cshtml", topic, new ViewDataDictionary { { "subscribed", subscribed }, { "topicMembers", topicMembers } })
- @Html.Partial("~/Views/Partials/Forum/Thread.cshtml") + @Html.Partial("~/Views/Partials/Forum/Thread.cshtml", topic, new ViewDataDictionary + { + { "subscribed", subscribed }, + { "content", Model.Content }, + { "topicMembers", topicMembers }, + { "memberRoles", memberRoles } + })
@Html.Partial("~/Views/Partials/Forum/TopicForm.cshtml") \ No newline at end of file diff --git a/OurUmbraco.Site/Views/Partials/Forum/Comment.cshtml b/OurUmbraco.Site/Views/Partials/Forum/Comment.cshtml index 33fb39e9..a167712f 100644 --- a/OurUmbraco.Site/Views/Partials/Forum/Comment.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/Comment.cshtml @@ -5,19 +5,12 @@ @{ var currentMember = Model.MemberData != null && Model.MemberData.Member != null ? Model.MemberData.Member : null; var answer = (int)ViewData["answer"]; - var roles = new List(); - - var commentAuthor = Members.GetById(Model.MemberId); - // author could have been deleted (spammer) so make sure to check if they exist - if (commentAuthor != null) - { - roles = commentAuthor.GetRoles(); - } + var commentAuthor = (IPublishedContent)ViewData["commentAuthor"]; + var roles = (List)ViewData["roles"]; var topicParentId = (int)ViewData["topicParentId"]; var forum = Umbraco.TypedContent(topicParentId); var forumReadOnly = forum.NewTopicsAllowed() == false; - } @* If author exists and comment is either not spam or the viewer is a the author or an admin admin *@ @if (commentAuthor != null && (Model.IsSpam == false || (currentMember != null && currentMember.Id == commentAuthor.Id) || Model.MemberData != null && Model.MemberData.IsAdmin)) diff --git a/OurUmbraco.Site/Views/Partials/Forum/Question.cshtml b/OurUmbraco.Site/Views/Partials/Forum/Question.cshtml index c049bb09..003f9b59 100644 --- a/OurUmbraco.Site/Views/Partials/Forum/Question.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/Question.cshtml @@ -4,14 +4,13 @@ @{ var currentMember = Model.MemberData != null && Model.MemberData.Member != null ? Model.MemberData.Member : null; - var topicAuthor = Members.GetById(Model.MemberId); + var topicAuthor = (IPublishedContent) ViewData["topicAuthor"]; @* If author exists and question is either not spam or the viewer is a the author or an admin admin *@ if (topicAuthor != null && (Model.IsSpam == false || (currentMember != null && currentMember.Id == topicAuthor.Id) || Model.MemberData != null && Model.MemberData.IsAdmin)) { var forum = Umbraco.TypedContent(Model.ParentId); - var roles = topicAuthor.GetRoles(); - + var roles = (List)ViewData["roles"];
  • diff --git a/OurUmbraco.Site/Views/Partials/Forum/Thread.cshtml b/OurUmbraco.Site/Views/Partials/Forum/Thread.cshtml index 58e644fd..0ae998d4 100644 --- a/OurUmbraco.Site/Views/Partials/Forum/Thread.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/Thread.cshtml @@ -1,19 +1,20 @@ -@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage +@model ReadOnlyTopic @using System.Web.Mvc.Html @using OurUmbraco.Forum.Extensions -@using OurUmbraco.Forum.Services -@using OurUmbraco.NotificationsWeb.Library +@using OurUmbraco.Forum.Models @using Umbraco.Core.Logging @{ - var topicService = new TopicService(ApplicationContext.DatabaseContext); - var topic = topicService.CurrentTopic(Context, ApplicationContext.ApplicationCache.RequestCache, MemberData); - - var notification = Model.Content.GetPropertyValue("mainNotification"); + var topic = Model; + var content = (IPublishedContent)ViewData["content"]; + var subscribed = (bool)ViewData["subscribed"]; + var memberRoles = (Dictionary>)ViewData["memberRoles"]; + var notification = content.GetPropertyValue("mainNotification"); if (string.IsNullOrWhiteSpace(notification)) { notification = "This forum is in read only mode, you can no longer reply"; } + var topicMembers = (List)ViewData["topicMembers"]; } @@ -32,7 +33,7 @@ -@if (MemberData != null) +@if (Model.MemberData != null) {

    Are you sure?

    @@ -55,7 +56,7 @@ @if (topic != null) { - if (Model.Content.NewTopicsAllowed() == false) + if (content.NewTopicsAllowed() == false) {
    @Html.Raw(notification) @@ -67,7 +68,11 @@ @{ try { - @Html.Partial("forum/question", topic) + var topicAuthor = topicMembers.SingleOrDefault(m => m.Id == topic.MemberId); + var roles = new List(); + memberRoles.TryGetValue(topic.MemberId, out roles); + + @Html.Partial("forum/question", topic, new ViewDataDictionary { { "topicAuthor", topicAuthor }, { "roles", roles } }) } catch (Exception ex) { @@ -78,9 +83,12 @@ @foreach (var comment in topic.Comments.Where(x => x.ParentCommentId == 0)) { var comm = comment; - comm.MemberData = MemberData; + comm.MemberData = Model.MemberData; + var commentAuthor = topicMembers.SingleOrDefault(m => m.Id == comm.MemberId); + var roles = new List(); + memberRoles.TryGetValue(comm.MemberId, out roles); - Html.RenderPartial("forum/comment", comm, new ViewDataDictionary { { "level", 1 }, { "answer", topic.Answer }, { "topicParentId", topic.ParentId } }); + Html.RenderPartial("forum/comment", comm, new ViewDataDictionary { { "level", 1 }, { "answer", topic.Answer }, { "topicParentId", topic.ParentId }, { "commentAuthor", commentAuthor }, { "roles", roles } }); if (comm.HasChildren) { @@ -88,15 +96,21 @@ foreach (var child in children.Where(c => c.ParentCommentId == comm.Id)) { - Html.RenderPartial("forum/comment", child, new ViewDataDictionary { { "level", 2 }, { "answer", topic.Answer }, { "topicParentId", topic.ParentId } }); + var commChild = child; + child.MemberData = Model.MemberData; + var commentChildAuthor = topicMembers.SingleOrDefault(m => m.Id == commChild.MemberId); + var childRoles = new List(); + memberRoles.TryGetValue(commChild.MemberId, out childRoles); + + Html.RenderPartial("forum/comment", child, new ViewDataDictionary { { "level", 2 }, { "answer", topic.Answer }, { "topicParentId", topic.ParentId }, { "commentAuthor", commentChildAuthor }, { "roles", childRoles } }); } } } - if (MemberData != null) + if (Model.MemberData != null) { - if (Model.Content.NewTopicsAllowed()) + if (content.NewTopicsAllowed()) {
     Reply to topic @@ -105,13 +119,7 @@
    @{ - var subscribed = false; - if (MemberData.Member != null) - { - subscribed = Utils.IsSubscribedToForumTopic(topic.Id, MemberData.Member.Id); - } - - if (MemberData.IsAdmin) + if (Model.MemberData.IsAdmin) { Delete thread diff --git a/OurUmbraco.Site/Views/Partials/Forum/TopicActions.cshtml b/OurUmbraco.Site/Views/Partials/Forum/TopicActions.cshtml index df1fb0f5..17034daf 100644 --- a/OurUmbraco.Site/Views/Partials/Forum/TopicActions.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/TopicActions.cshtml @@ -1,37 +1,29 @@ -@using OurUmbraco.Forum.Services -@using OurUmbraco.NotificationsWeb.Library -@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage +@using OurUmbraco.Forum.Models +@model ReadOnlyTopic @{ - var topicService = new TopicService(ApplicationContext.DatabaseContext); - var topic = topicService.CurrentTopic(Context, ApplicationContext.ApplicationCache.RequestCache, MemberData); + var subscribed = (bool)ViewData["subscribed"]; }
    - @if (topic != null) + @if (Model != null) { - if (MemberData != null) + if (Model.MemberData != null) { - var subscribed = false; - if (MemberData != null) + if (Model.MemberData.IsAdmin) { - subscribed = Utils.IsSubscribedToForumTopic(topic.Id, MemberData.Member.Id); - } - - if (MemberData.IsAdmin) - { - + Delete thread } - } - if (topic.Answer > 0) + if (Model.Answer > 0) { - + Go to solution } diff --git a/OurUmbraco/Forum/Extensions/ForumExtensions.cs b/OurUmbraco/Forum/Extensions/ForumExtensions.cs index 06af2701..f3874f3f 100644 --- a/OurUmbraco/Forum/Extensions/ForumExtensions.cs +++ b/OurUmbraco/Forum/Extensions/ForumExtensions.cs @@ -158,7 +158,9 @@ namespace OurUmbraco.Forum.Extensions public static List GetRoles(this IPublishedContent member) { - var roles = Roles.GetRolesForUser(member.GetPropertyValue("UserName")); + const string sql = @"SELECT [umbracoNode].[text] FROM [cmsMember2MemberGroup] LEFT JOIN [umbracoNode] ON [cmsMember2MemberGroup].[MemberGroup] = [umbracoNode].[id] WHERE [cmsMember2MemberGroup].[Member] = @memberId"; + var roles = ApplicationContext.Current.DatabaseContext.Database.Fetch(sql, new { memberId = member.Id }); + var memberRoles = new List(); foreach (var role in roles)