public void CheckComment(ICommentWithEntry comment, IEntryLinkFactory entryLinkFactory, IDatabaseContext <User> ctx) { var userMatches = Regex.Matches(comment.Message, @"@(\w+)"); if (userMatches.Count == 0) { return; } var userNames = userMatches.Cast <Match>().Select(m => m.Groups[1].Value).ToArray(); var users = ctx.Query().Where(u => u.Active && userNames.Contains(u.Name)).ToArray(); if (!users.Any()) { return; } var commentMsg = comment.Message.Truncate(200); var msg = $"{comment.AuthorName} mentioned you in a comment for {MarkdownHelper.CreateMarkdownLink(entryLinkFactory.GetFullEntryUrl(comment.Entry), comment.Entry.DefaultName)}\n\n{commentMsg}"; foreach (var user in users) { var notification = new UserMessage(user, "Mentioned in a comment", msg, false); ctx.OfType <UserMessage>().Save(notification); } }
private string CreateMessageBody(Artist[] followedArtists, User user, IEntryWithNames entry, bool markdown, string entryTypeName) { var entryName = entry.Names.SortNames[user.DefaultLanguageSelection]; var url = entryLinkFactory.GetFullEntryUrl(entry); string entryLink; if (markdown) { entryLink = MarkdownHelper.CreateMarkdownLink(url, entryName); } else { entryLink = string.Format("{0} ( {1} )", entryName, url); } string msg; if (followedArtists.Length == 1) { var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection]; msg = string.Format("A new {0}, '{1}', by {2} was just added.", entryTypeName, entryLink, artistName); } else { msg = string.Format("A new {0}, '{1}', by multiple artists you're following was just added.", entryTypeName, entryLink); } msg += "\nYou're receiving this notification because you're following the artist(s)."; return(msg); }
private string CreateMessageBody(Tag[] followedArtists, User user, IEntryWithNames entry, IEntryLinkFactory entryLinkFactory, bool markdown, string entryTypeName) { var entryName = entry.Names.SortNames[user.DefaultLanguageSelection]; var url = entryLinkFactory.GetFullEntryUrl(entry); string entryLink; if (markdown) { entryLink = MarkdownHelper.CreateMarkdownLink(url, entryName); } else { entryLink = $"{entryName} ( {url} )"; } string msg; if (followedArtists.Length == 1) { var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection]; msg = $"A new {entryTypeName}, '{entryLink}', tagged with {artistName} was just added."; } else { msg = $"A new {entryTypeName}, '{entryLink}', tagged with multiple tags you're following was just added."; } msg += "\nYou're receiving this notification because you're following the tag(s)."; return(msg); }
public void SendReportNotification(IDatabaseContext <UserMessage> ctx, ArchivedObjectVersion?reportedVersion, string?notes, IEntryLinkFactory entryLinkFactory, string?reportName) { if (reportedVersion == null) { return; } var receiver = reportedVersion.Author; if (receiver == null) { return; } var entry = reportedVersion.EntryBase; string body, title; using (new ImpersonateUICulture(CultureHelper.GetCultureOrDefault(receiver.LanguageOrLastLoginCulture))) { body = EntryReportStrings.EntryVersionReportBody; title = EntryReportStrings.EntryVersionReportTitle; } // Report type name + notes string?notesAndName = notes; if (!string.IsNullOrEmpty(reportName) && !string.IsNullOrEmpty(notes)) { notesAndName = $"{reportName} ({notes})"; } else if (string.IsNullOrEmpty(notes)) { notesAndName = reportName; } var message = string.Format(body, MarkdownHelper.CreateMarkdownLink(entryLinkFactory.GetFullEntryUrl(entry), entry.DefaultName), notesAndName); var notification = new UserMessage(receiver, string.Format(title, entry.DefaultName), message, false); ctx.Save(notification); }
public void CheckComment(Comment comment, IEntryLinkFactory entryLinkFactory, IRepositoryContext <User> ctx) { var userMatches = Regex.Match(comment.Message, @"@(\w+)"); if (!userMatches.Success) { return; } var userNames = userMatches.Groups.Cast <Group>().Skip(1).Select(g => g.Value).ToArray(); var users = ctx.Query().Where(u => u.Active && userNames.Contains(u.Name)).ToArray(); if (!users.Any()) { return; } var commentMsg = comment.Message.Truncate(200); var msg = string.Format("{0} mentioned you in a comment for {1}\n\n{2}", comment.AuthorName, MarkdownHelper.CreateMarkdownLink(entryLinkFactory.GetFullEntryUrl(comment.Entry), comment.Entry.DefaultName), commentMsg); foreach (var user in users) { var notification = new UserMessage(user, "Mentioned in a comment", msg, false); ctx.OfType <UserMessage>().Save(notification); } }