diff options
| author | Michael <[email protected]> | 2017-04-16 21:41:35 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-16 21:41:35 -0400 |
| commit | ebc74ab7e7c6b2c1ee2198a3f5f701a95cafa13c (patch) | |
| tree | 7709821a4e44556e9227d0ff435e241b62f2def7 | |
| parent | ef1360b87339ba911c2d7d35a151278a1a3609ab (diff) | |
| download | project-unite-ebc74ab7e7c6b2c1ee2198a3f5f701a95cafa13c.tar.gz project-unite-ebc74ab7e7c6b2c1ee2198a3f5f701a95cafa13c.tar.bz2 project-unite-ebc74ab7e7c6b2c1ee2198a3f5f701a95cafa13c.zip | |
Allow user mentions.
| -rw-r--r-- | Project-Unite/ACL.cs | 20 |
1 files changed, 20 insertions, 0 deletions
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))); } |
