/// <summary> /// /// </summary> /// <param name="message"></param> public void ProcessCommentWorkItem(CommentAlertWorkItem comment) { var post = new PostRepository().GetByID(comment.PostID); var userIDsOnThread = post.PostComments.Where(pc => pc.UserID != comment.ByID).Select(pc => pc.UserID).Distinct().ToList(); var by = CfPerfCache.GetClimber(comment.ByID); var excerpt = comment.Content; if (excerpt.Length > 30) { excerpt = excerpt.Substring(0, 30); } var msg = string.Format("<a href='/climber/{0}'>{1}</a> made a <a href='/post/{2}'>comment</a><i> \"{3}...\"</i></a>", by.ID, by.DisplayName, comment.PostID, excerpt); //-- Also need to let the person who posted know incase they haven't commented on their own post or already part of the commentors if (by.ID != post.UserID && !userIDsOnThread.Contains(post.UserID)) { userIDsOnThread.Add(post.UserID); } foreach (var uID in userIDsOnThread) { var settings = GetUserSiteSettings(uID); if (settings.CommentsOnPostsAlertFeed || settings.CommentsOnPostsEmailRealTime || settings.CommentsOnPostsMobileRealTime) { var toUser = CfPerfCache.GetClimber(uID); var a = new Alert() { ID = Guid.NewGuid(), Utc = DateTime.UtcNow, TypeID = (byte)AlertType.CommentOnPost, UserID = toUser.ID, Message = msg }; if (settings.CommentsOnPostsAlertFeed) { a.ByFeed = true; } if (settings.CommentsOnPostsEmailRealTime) { a.ByEmail = true; MailMan.SendCommentEmail(toUser, by, comment.PostID, comment.Content); } if (settings.CommentsOnPostsMobileRealTime && !string.IsNullOrEmpty(settings.DeviceTypeRegistered)) { a.ByMobile = true; MobilePush_CommentAlert(comment.PostID, by.DisplayName, toUser.Email, settings.DeviceTypeRegistered); } new AlertRepository().Create(a); } } }
/// <summary> /// /// </summary> /// <param name="toID"></param> /// <param name="fromID"></param> /// <param name="postID"></param> /// <param name="content"></param> public void EnqueCommentWorkItem(Guid byID, Guid postID, string content) { var dto = new CommentAlertWorkItem() { ByID = byID, PostID = postID, Content = content }; if (Stgs.IsDevelopmentEnvironment) { ProcessCommentWorkItem(dto); } else { var queueMessage = new CloudQueueMessage(dto.ToJson()); new QueueRepository().PutMessage(CommentQueueName, queueMessage); } }