public int Invite( List<int> inviteKs, Usr invitingUsr, DateTime inviteDateTime, List<int> alertedUsrs, bool isNewThread, Comment postedComment, bool joinChatRoom) { IDiscussable Parent = this.ParentForumObject; Query qInvites = new Query(); List<Q> qList = new List<Q>(); qList.Add(new Q(false)); if (inviteKs != null && inviteKs.Count > 0) qList.Add(new InListQ(Usr.Columns.K, inviteKs)); qInvites.QueryCondition = new Or(qList.ToArray()); qInvites.Columns = new ColumnSet( Usr.EmailColumns, Usr.LinkColumns, Usr.Columns.IsLoggedOn, Usr.Columns.DateTimeLastPageRequest, Usr.Columns.AddedByGroupK); UsrSet usInvites = new UsrSet(qInvites); int count = 0; GroupUsr guInvitingUsr = null; if (this.GroupK > 0) guInvitingUsr = this.Group.GetGroupUsr(invitingUsr); List<int> addedThreadUsrsUsrKs = new List<int>(); foreach (Usr u in usInvites) { if (!alertedUsrs.Contains(u.K)) { try { ThreadUsr tuInvite = new ThreadUsr(this.K, u.K); } catch (Bobs.BobNotFound) { bool sendInviteAlerts = true; bool addThreadUsr = true; if (this.GroupK > 0) { GroupUsr gu = this.Group.GetGroupUsr(u); if (this.GroupPrivate || this.PrivateGroup) { //if this thread is private to the group or in a private group, there's a danger that we're //inviting someone to a thread that they can't see. Also - if the group is made public, many //threads may appear in peoples inboxes. This bit stops us sending these dodgy invites out... if (gu == null) { //if they don't have a GroupUsr record, lets send a group invite, but hold off on the thread alert sendInviteAlerts = false; this.Group.Invite(u, gu, invitingUsr, guInvitingUsr, "", false); } else if (gu.IsMember) { //if they are a member, we can send the thread invite } else if (gu.Status.Equals(GroupUsr.StatusEnum.Recommend) || gu.Status.Equals(GroupUsr.StatusEnum.RecommendRejected) || gu.Status.Equals(GroupUsr.StatusEnum.Request) || gu.Status.Equals(GroupUsr.StatusEnum.RequestRejected)) { //if we might be able to invite or join them to the group, we give it a try (the outcome will depend on some rather complex code) this.Group.Invite(u, gu, invitingUsr, guInvitingUsr, "", false); if (!gu.IsMember) { //if we didn't join them straight up, they still won't be able to see the thread, so we hold off on the thread alert email sendInviteAlerts = false; if (!gu.Status.Equals(GroupUsr.StatusEnum.Invite)) { //if we didn't join them straight up AND we didn't invite them, lets not bother inviting them to the thread addThreadUsr = false; } } } else { //ok so they have a GroupUsr, but they're not a member, and we can't invite or join them, so we're not going to bother inviting them to the thread addThreadUsr = false; } } } //We still add this user to the alertedusers list (even if !addThreadUsr) - this just makes sure we don't attempt to send them an invite a second time. alertedUsrs.Add(u.K); if (addThreadUsr) { ThreadUsr tu = this.GetThreadUsr(u); tu.ChangeStatus(ThreadUsr.StatusEnum.NewInvite, DateTime.Now, false, false); try { addedThreadUsrsUsrKs.Add(u.K); } catch { } tu.InvitingUsrK = invitingUsr.K; tu.StatusChangeObjectK = invitingUsr.K; tu.StatusChangeObjectType = Model.Entities.ObjectType.Usr; tu.Update(); count++; #region sendInviteAlerts if (sendInviteAlerts) { try { Mailer usrMail = new Mailer(); if (isNewThread && this.Private && this.ParentObjectType.Equals(Model.Entities.ObjectType.Photo)) { usrMail.Subject = invitingUsr.NickName + " sent you a photo"; usrMail.Body += "<h1>" + invitingUsr.NickName + " sent you a photo</h1>"; usrMail.Body += "<p align=\"center\"><a href=\"[LOGIN]\"><img border=\"0\" src=\"" + this.ParentPhoto.WebPath + "\" width=\"" + this.ParentPhoto.WebWidth + "\" height=\"" + this.ParentPhoto.WebHeight + "\" class=\"BorderBlack All\" /></a></p>"; } else if (isNewThread) { usrMail.Subject = invitingUsr.NickName + " posts: \"" + this.SubjectSnip(40) + "\""; usrMail.Body += "<h1>" + invitingUsr.NickName + " has posted a new topic</h1>"; } else { usrMail.Subject = invitingUsr.NickName + " invites you to: \"" + this.SubjectSnip(40) + "\""; usrMail.Body += "<h1>" + invitingUsr.NickName + " invites you to a topic</h1>"; } usrMail.Body += "<p>The subject is: \"" + this.Subject + "\"</p>"; usrMail.Body += "<p>To read " + invitingUsr.HisString(false) + " message, check out the <a href=\"[LOGIN]\">topic page</a>.</p>"; usrMail.Body += "<p>If you want to stop " + invitingUsr.HimString(false) + " inviting you to topics, click the <i>Stop " + invitingUsr.NickName + " inviting me to chat topics</i> button on <a href=\"[LOGIN(" + invitingUsr.Url() + ")]\">" + invitingUsr.HisString(false) + " profile page</a>.</p>"; usrMail.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; usrMail.RedirectUrl = this.UrlDiscussion(); usrMail.UsrRecipient = u; //usrMail.Bulk=usInvites.Count>5; usrMail.Bulk = false; // This is interesting... if people are invited by email, they should get the invite really... usrMail.Inbox = true; usrMail.Send(); } catch (Exception ex) { Global.Log("1d3726bf-0715-4404-9059-4e53ca9e3dc5", ex); } //try //{ // if (u.IsLoggedOn && u.DateTimeLastPageRequest > DateTime.Now.AddMinutes(-5)) // { // XmlDocument xmlDoc = new XmlDocument(); // XmlNode n = xmlDoc.CreateElement("privateMessageAlert"); // n.AddAttribute("nickName", invitingUsr.NickNameSafe); // n.AddAttribute("stmu", invitingUsr.StmuParams); // n.AddAttribute("usrK", invitingUsr.K.ToString()); // if (invitingUsr.HasPic) // n.AddAttribute("pic", invitingUsr.Pic.ToString()); // else // n.AddAttribute("pic", "0"); // n.AddAttribute("k", this.K.ToString()); // if (postedComment == null) // { // n.InnerText = this.Url(); // } // else // { // n.InnerText = postedComment.Url(this); // } // Chat.SendChatItem(ItemType.Invite, n, DateTime.Now.Ticks, u.K, Guid.NewGuid()); // } //} //catch (Exception ex) { Global.Log("2902fd82-e8a4-49c2-9e33-ccfca01ca1f9", ex); } } #endregion } } } } if (joinChatRoom) { Guid room = this.GetRoomSpec().Guid; Chat.JoinRoom(room, addedThreadUsrsUsrKs.ToArray()); } return count; }
public bool SendWelcomeEmail(Usr invitingUsr, Group invitingGroup, string inviteMessage) { if (this.EmailHold) return false; Mailer sm = new Mailer(); sm.UsrRecipient = this; if (invitingGroup == null) { if (invitingUsr == null) { sm.Subject = "We've created you a Don't Stay In account!"; sm.Body = @" <p> Don't Stay In is <i>the</i> place to plan your clubbing calendar. Our team of spotters are busy taking photos of clubbers at the hottest parties in your area and throughout the world. </p> <p> If you've had your photo taken, you can look through our galleries to find it. You can chat live with other clubbers and catch up with the latest gossip. </p> <p align=""center"" style=""margin:10px 0px 8px 0px;""> <a href=""[LOGIN]"" style=""font-size:18px;font-weight:bold;"">Click here to go to DontStayIn</a> </p> "; } else { sm.Subject = invitingUsr.NickName + " has invited you to DontStayIn!"; sm.Body = "<p><b>" + invitingUsr.NickName + @" has invited you to DontStayIn!</b></p> <p> DontStayIn is <i>the</i> place to plan your clubbing calendar. Our team of spotters are busy taking photos of clubbers at the hottest parties in your area and throughout the world. </p> <p> If you've had your photo taken, you can look through our galleries to find it. You can chat live with other clubbers and catch up with the latest gossip. </p> <p align=""center"" style=""margin:10px 0px 8px 0px;""> <a href=""[LOGIN]"" style=""font-size:18px;font-weight:bold;"">Click here to go to DontStayIn</a> </p> "; } } else { GroupUsr invitingGroupUsr = invitingGroup.GetGroupUsr(invitingUsr); sm.RedirectUrl = invitingGroup.Url(); sm.Subject = invitingUsr.NickName + @" has invited you to " + (invitingGroupUsr != null && invitingGroupUsr.Moderator ? invitingUsr.HisString(false) : "a") + @" DontStayIn group: " + invitingGroup.FriendlyName; string pic = @"<table cellspacing=""0"" cellpadding=""0"" border=""0"" style=""margin:10px 5px 5px 1px;""><tr><td valign=""top"">"; string picEnd = "</td></tr></table>"; if (invitingUsr.HasPic) { pic = @"<table cellspacing=""0"" cellpadding=""0"" border=""0"" style=""margin:10px 5px 5px 1px;""><tr><td valign=""top"" style=""padding:0px 10px 0px 0px;"">"; pic += "<a href=\"[LOGIN]\"><img src=\"" + invitingUsr.PicPath + "\" class=\"BorderBlack All\" width=\"100\" height=\"100\" vspace=\"3\" border=\"0\"></a></td><td valign=\"top\">"; picEnd = "</td></tr></table>"; } string members = ""; if (invitingGroup.TotalMembers > 5) { Query q = new Query(); q.TableElement = Usr.GroupJoin; q.QueryCondition = new And(new Q(Group.Columns.K, invitingGroup.K), new Q(Usr.Columns.Pic, QueryOperator.NotEqualTo, Guid.Empty)); q.TopRecords = 5; q.OrderBy = new OrderBy(OrderBy.OrderDirection.Random); q.Columns = Usr.LinkColumns; UsrSet us = new UsrSet(q); if (us.Count == 5) { members = @"<p><b>" + invitingGroup.FriendlyName + @"</b> has " + invitingGroup.TotalMembers.ToString("#,##0") + @" members. Here's a few of them:</p>"; members += @"<table cellspacing=""4"" cellpadding=""4"" border=""0"" width=""100%""><tr>"; foreach (Usr uPic in us) { members += "<td width=\"20%\" valign=\"top\"><center><a href=\"[LOGIN(" + uPic.Url() + ")]\"><img src=\"" + uPic.PicPath + "\" width=\"75\" height=\"75\" style=\"margin:0px 0px 5px 0px;\" class=\"BorderBlack All\"><br>" + Cambro.Misc.Utility.Snip(uPic.NickName, 12) + "</a></center></td>"; } members += @"</tr></table>"; } } sm.Body = @" " + pic + @" <i style=""font-size:18px;""><b>""</b>" + Cambro.Web.Helpers.Strip(inviteMessage, true, true, false, true).Replace("\n", "<br>") + @"<b>""</b></i> " + picEnd + @" <p>" + invitingUsr.LinkEmail() + @" (" + invitingUsr.FirstName + @") has invited you to " + (invitingGroupUsr != null && invitingGroupUsr.Moderator ? invitingUsr.HisString(false) : "a") + @" DontStayIn group! You can use this to keep in contact with your friends. Here's a quick description of <b>" + invitingGroup.FriendlyName + @"</b>:</p> <p> <i>" + invitingGroup.Description + @"</i> </p> " + members + @" "; } sm.Send(); return true; }
private void InvitePrivate(Usr InvitedUsr, GroupUsr InvitedGroupUsr, Usr InvitingUsr, GroupUsr InvitingGroupUsr, string InviteMessage) { string inviteMessageStripped = Cambro.Web.Helpers.Strip(InviteMessage,true,true,false,true); if (InvitedGroupUsr==null) { InvitedGroupUsr = new GroupUsr(); InvitedGroupUsr.UsrK = InvitedUsr.K; InvitedGroupUsr.GroupK = this.K; } InvitedGroupUsr.Status = GroupUsr.StatusEnum.Invite; InvitedGroupUsr.StatusChangeDateTime = DateTime.Now; InvitedGroupUsr.StatusChangeUsrK = InvitingUsr.K; if (InvitedGroupUsr.InviteUsrK==0) { InvitedGroupUsr.InviteUsrK = InvitingUsr.K; InvitedGroupUsr.InviteMessage = inviteMessageStripped; } else if (InvitedGroupUsr.InviteUsrK != InvitingUsr.K) { //already had an inviting usr InvitingUsr = InvitedGroupUsr.InviteUsr; InvitingGroupUsr = GetGroupUsr(InvitingUsr); InviteMessage = InvitedGroupUsr.InviteMessage; inviteMessageStripped = Cambro.Web.Helpers.Strip(InviteMessage, true, true, false, true); } if (InvitedUsr.AddedByGroupK!=this.K) { string messageString = ""; if (InviteMessage.Length>0) messageString = "</p><p>"+InvitedGroupUsr.InviteUsr.LinkEmail()+" left you this messsage:</p><p><b>"+inviteMessageStripped+"</b></p><p>"; Mailer sm = new Mailer(); sm.UsrRecipient = InvitedUsr; sm.RedirectUrl = this.Url(); sm.Subject = InvitingUsr.NickName + @" has invited you to " + (InvitingGroupUsr!=null && InvitingGroupUsr.Moderator ? InvitingUsr.HisString(false) : "a") + @" group: " + this.FriendlyName; string pic = "<p>"; string picEnd = "</p>"; if (InvitingUsr.HasPic) { pic = @"<table cellspacing=""0"" cellpadding=""0"" border=""0"" style=""margin:10px 5px 5px 1px;""><tr><td valign=""top"" style=""padding:0px 10px 0px 0px;"">"; pic += "<a href=\"[LOGIN(" + InvitingUsr.Url() + ")]\"><img src=\"" + InvitingUsr.PicPath + "\" class=\"BorderBlack All\" width=\"100\" height=\"100\" vspace=\"3\" border=\"0\"></a></td><td valign=\"top\">"; picEnd = "</td></tr></table>"; } string members = ""; if (this.TotalMembers>5) { Query q = new Query(); q.TableElement = Usr.GroupJoin; q.QueryCondition = new And(new Q(Group.Columns.K, this.K), new Q(Usr.Columns.Pic,QueryOperator.NotEqualTo,Guid.Empty)); q.TopRecords=5; q.OrderBy=new OrderBy(OrderBy.OrderDirection.Random); q.Columns=Usr.LinkColumns; UsrSet us = new UsrSet(q); if (us.Count==5) { members = @"<p><b>"+this.FriendlyName+@"</b> has "+this.TotalMembers.ToString("#,##0")+@" members. Here's a few of them:</p>"; members += @"<table cellspacing=""4"" cellpadding=""4"" border=""0"" width=""100%""><tr>"; foreach (Usr uPic in us) { members += "<td width=\"20%\" valign=\"top\"><center><a href=\"[LOGIN(" + uPic.Url() + ")]\"><img src=\"" + uPic.PicPath + "\" width=\"75\" height=\"75\" style=\"margin:0px 0px 5px 0px;\" class=\"BorderBlack All\"><br>" + Cambro.Misc.Utility.Snip(uPic.NickName, 12) + "</a></center></td>"; } members += @"</tr></table>"; } } string inviteMessage = ""; if (Cambro.Web.Helpers.Strip(InviteMessage,true,true,true,true).Length==0) inviteMessage = "Hi!"; else inviteMessage = Cambro.Web.Helpers.Strip(InviteMessage,true,true,false,true).Replace("\n","<br>"); sm.Body=@" "+pic+@" <i style=""font-size:18px;""><b>""</b>"+inviteMessage+@"<b>""</b></i> "+picEnd+@" <p>" + InvitingUsr.LinkEmail() + @" has invited you to " + (InvitingGroupUsr != null && InvitingGroupUsr.Moderator ? InvitingUsr.HisString(false) : "a") + @" group! You can use this to keep in contact with your friends. Here's a quick description of <b>" +this.FriendlyName+@"</b>:</p> <p> <i>"+this.Description+@"</i> </p> "+members+ @" <p align=""center"" style=""margin:10px 0px 8px 0px;""> <a href=""[LOGIN("+this.UrlApp("join")+@")]"" style=""font-size:18px;font-weight:bold;"">Join the group</a> | <a href=""[LOGIN]"" style=""font-size:18px;font-weight:bold;"">decline the invite</a> </p> "; sm.Send(); } InvitedGroupUsr.Update(); }