From ebc74ab7e7c6b2c1ee2198a3f5f701a95cafa13c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Apr 2017 21:41:35 -0400 Subject: [PATCH] Allow user mentions. --- Project-Unite/ACL.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index 39c58de..9e75043 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -91,8 +91,28 @@ namespace Project_Unite return hpr.ActionLink(topic.Subject, "ViewTopic", "Forum", new { id = topic.Discriminator }, null); } + public static string ResolveUserLinksInMarkdown(string mkdn) + { + string[] words = mkdn.Split(' '); + foreach(var word in words) + { + if (word.StartsWith("@")) + { + string uname = word.Remove(0, 1); + var db = new ApplicationDbContext(); + var user = db.Users.FirstOrDefault(x => x.DisplayName == uname); + if(user != null) + { + mkdn = mkdn.Replace(word, $"[{word}(/Profiles/ViewProfile/{uname})"); + } + } + } + return mkdn; + } + public static IHtmlString Markdown(this HtmlHelper hpr, string md) { + md = ResolveUserLinksInMarkdown(md); return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md))); }