private static void ThreadSendAlerts(Thread parentThread, List<int> alertedUsrs, Usr postingUsr, CommentAlertSet cas, IDiscussable parent) { #region Send alerts if (cas != null) { foreach (CommentAlert ca in cas) { try { if (!alertedUsrs.Contains(ca.UsrK) && postingUsr.K != ca.UsrK) { ThreadUsr tu = parentThread.GetThreadUsr(ca.Usr); tu.ChangeStatus(ThreadUsr.StatusEnum.NewWatchedForumAlert, parentThread.DateTime, false, false); tu.StatusChangeObjectK = ca.ParentObjectK; tu.StatusChangeObjectType = ca.ParentObjectType; tu.Update(null); Mailer usrMail = new Mailer(); usrMail.Subject = postingUsr.NickName + " posts: \"" + parentThread.SubjectSnip(40) + "\""; usrMail.Body += "<h1>" + postingUsr.NickName + " has posted a new topic</h1>"; usrMail.Body += "<p>The subject is: \"" + parentThread.Subject + "\"</p>"; usrMail.Body += "<p>To read and reply, check out the <a href=\"[LOGIN]\">topic page</a>.</p>"; string s = postingUsr.LinkEmail(); usrMail.Body += "<p>" + postingUsr.LinkEmail() + " posted it in the <a href=\"[LOGIN(" + ((IDiscussable)parent).UrlDiscussion() + ")]\">" + ((IName)parent).Name + " forum</a>.</p>"; if (ca.ParentObjectType.Equals(Model.Entities.ObjectType.Photo)) usrMail.Body += "<p>You're watching for comments posted on <a href=\"[LOGIN(" + ca.ParentPhoto.Url() + ")]\">this photo</a>.</p>"; else usrMail.Body += "<p>You're watching all new topics in the <a href=\"[LOGIN(" + ((IDiscussable)ca.ParentObject).UrlDiscussion() + ")]\">" + ((IName)ca.ParentObject).Name + " forum</a>. To stop receiving these emails, click the <i>Ignore new topics in this forum</i> button on the forum page.</p>"; usrMail.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; usrMail.RedirectUrl = parentThread.UrlDiscussion(); usrMail.UsrRecipient = ca.Usr; usrMail.Bulk = true; usrMail.Inbox = true; usrMail.Send(); alertedUsrs.Add(ca.UsrK); } } catch (Exception ex) { Bobs.Global.Log("9a9f2ee1-41ea-4e2b-8187-caa75ddd1b8e - UsrK=" + postingUsr.K.ToString() + " ThreadK=" + parentThread.K.ToString(), ex); } } } #endregion }
private static void ThreadSendMessagesToCommentAlerts(Thread parentThread, Usr postingUsr, List<int> alertedUsrKs) { #region Send messages to CommentAlerts try { CommentAlertSet cas = null; IDiscussable parent = null; try { parent = parentThread.ParentForumObject; } catch (Exception ex) { Bobs.Global.Log("316e602c-f6ce-4fa5-a628-b05335596a57", ex); } if (parentThread.GroupK == 0) { if (!parentThread.Private && !parentThread.ParentObjectType.Equals(Model.Entities.ObjectType.None) && !parentThread.ParentObjectType.Equals(Model.Entities.ObjectType.Country)) { Query q = new Query(); List<Q> al = new List<Q>(); try { #region Build query if (parentThread.ArticleK > 0) al.Add(new And(new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Article), new Q(CommentAlert.Columns.ParentObjectK, parentThread.ArticleK))); if (parentThread.PhotoK > 0) al.Add(new And(new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Photo), new Q(CommentAlert.Columns.ParentObjectK, parentThread.PhotoK))); if (parentThread.EventK > 0) { al.Add(new And(new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Event), new Q(CommentAlert.Columns.ParentObjectK, parentThread.EventK))); Event ev = new Event(parentThread.EventK); foreach (Brand b in ev.Brands) al.Add(new And(new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Brand), new Q(CommentAlert.Columns.ParentObjectK, b.K))); } if (parentThread.VenueK > 0) al.Add(new And(new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Venue), new Q(CommentAlert.Columns.ParentObjectK, parentThread.VenueK))); if (parentThread.PlaceK > 0) al.Add(new And(new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Place), new Q(CommentAlert.Columns.ParentObjectK, parentThread.PlaceK))); #endregion } catch (Exception ex) { Bobs.Global.Log("2120d49c-25e6-4988-9517-f6253583f6e6", ex); } if (al.Count > 0) { try { #region Get commentAlerts if (al.Count == 1) { q.QueryCondition = (Q)al[0]; } else { Q[] qarr = al.ToArray(); q.QueryCondition = new Or(qarr); } q.OrderBy = new OrderBy(CommentAlert.Columns.ParentObjectType); q.TableElement = new Join(CommentAlert.Columns.UsrK, new Column(CommentAlert.Columns.UsrK, Usr.Columns.K)); q.Columns = new ColumnSet( CommentAlert.Columns.ParentObjectK, CommentAlert.Columns.ParentObjectType, CommentAlert.Columns.UsrK, new JoinedColumnSet(CommentAlert.Columns.UsrK, Usr.EmailColumns) ); cas = new CommentAlertSet(q); #endregion } catch (Exception ex) { Bobs.Global.Log("345a3a46-4c6e-406b-909b-ee79997f21ee", ex); } } } } else { try { #region Get group commentAlerts Query q = new Query(); q.TableElement = new Join(CommentAlert.Columns.UsrK, new Column(CommentAlert.Columns.UsrK, Usr.Columns.K)); if (parentThread.GroupPrivate || parentThread.PrivateGroup) { q.QueryCondition = new And( new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Group), new Q(CommentAlert.Columns.ParentObjectK, parentThread.GroupK), new Q(GroupUsr.Columns.Status, GroupUsr.StatusEnum.Member)); q.TableElement = new Join( q.TableElement, new TableElement(TablesEnum.GroupUsr), QueryJoinType.Inner, new And( new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Group), new Q(CommentAlert.Columns.ParentObjectK, GroupUsr.Columns.GroupK, true), new Q(CommentAlert.Columns.UsrK, GroupUsr.Columns.UsrK, true), new Q(GroupUsr.Columns.Status, GroupUsr.StatusEnum.Member))); } else { q.QueryCondition = new And( new Q(CommentAlert.Columns.ParentObjectType, Model.Entities.ObjectType.Group), new Q(CommentAlert.Columns.ParentObjectK, parentThread.GroupK)); } q.OrderBy = new OrderBy(CommentAlert.Columns.ParentObjectType); q.Columns = new ColumnSet( CommentAlert.Columns.ParentObjectK, CommentAlert.Columns.ParentObjectType, CommentAlert.Columns.UsrK, new JoinedColumnSet(CommentAlert.Columns.UsrK, Usr.EmailColumns) ); cas = new CommentAlertSet(q); #endregion } catch (Exception ex) { Bobs.Global.Log("45e3f62f-cdfc-4d34-a506-b7a0b1fe9b94", ex); } } ThreadSendAlerts(parentThread, alertedUsrKs, postingUsr, cas, parent); } catch (Exception ex) { Bobs.Global.Log("1dacb724-64b1-4c53-9d95-f043221b1d39", ex); } #endregion }