Beispiel #1
0
        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IEnumerable <TypedUserFind> usersWithAll = new List <TypedUserFind>();

            if (this.BoardSettings.AllowNotificationAllPostsAllTopics)
            {
                // TODO: validate permissions!
                usersWithAll = LegacyDb.UserFind(
                    YafContext.Current.PageBoardID,
                    false,
                    null,
                    null,
                    null,
                    UserNotificationSetting.AllTopics.ToInt(),
                    null);
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            string languageFile = this.BoardSettings.Language;
            string boardName    = this.BoardSettings.Name;
            string forumEmail   = this.BoardSettings.ForumEmail;

            foreach (var message in LegacyDb.MessageList(newMessageId))
            {
                int userId = message.UserID ?? 0;

                var watchEmail = new YafTemplateEmail("TOPICPOST")
                {
                    TemplateLanguageFile = languageFile
                };

                // cleaned body as text...
                var bodyText =
                    BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message)))
                    .RemoveMultipleWhitespace();

                // Send track mails
                var subject =
                    this.Get <ILocalization>()
                    .GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile)
                    .FormatWith(boardName);

                watchEmail.TemplateParams["{forumname}"]     = boardName;
                watchEmail.TemplateParams["{topic}"]         = HttpUtility.HtmlDecode(message.Topic);
                watchEmail.TemplateParams["{postedby}"]      = UserMembershipHelper.GetDisplayNameFromID(userId);
                watchEmail.TemplateParams["{body}"]          = bodyText;
                watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
                watchEmail.TemplateParams["{link}"]          = YafBuildLink.GetLinkNotEscaped(
                    ForumPages.posts,
                    true,
                    "m={0}#post{0}",
                    newMessageId);

                watchEmail.CreateWatch(message.TopicID ?? 0, userId, new MailAddress(forumEmail, boardName), subject);

                // create individual watch emails for all users who have All Posts on...
                foreach (var user in usersWithAll.Where(x => x.UserID.HasValue && x.UserID.Value != userId))
                {
                    // Make sure its not a guest
                    if (user.ProviderUserKey == null)
                    {
                        continue;
                    }

                    var membershipUser = UserMembershipHelper.GetUser(user.ProviderUserKey);

                    if (membershipUser == null || !membershipUser.Email.IsSet())
                    {
                        continue;
                    }

                    watchEmail.TemplateLanguageFile = !string.IsNullOrEmpty(user.LanguageFile)
                                                          ? user.LanguageFile
                                                          : this.Get <ILocalization>().LanguageFileName;
                    watchEmail.SendEmail(
                        new MailAddress(forumEmail, boardName),
                        new MailAddress(membershipUser.Email, membershipUser.UserName),
                        subject,
                        true);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IList <User> usersWithAll = new List <User>();

            if (this.BoardSettings.AllowNotificationAllPostsAllTopics)
            {
                usersWithAll = this.GetRepository <User>()
                               .FindUserTyped(filter: false, notificationType: UserNotificationSetting.AllTopics.ToInt());
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            var languageFile = this.BoardSettings.Language;
            var boardName    = this.BoardSettings.Name;
            var forumEmail   = this.BoardSettings.ForumEmail;

            var message = LegacyDb.MessageList(newMessageId).FirstOrDefault();

            var messageAuthorUserID = message.UserID ?? 0;

            var watchEmail = new YafTemplateEmail("TOPICPOST")
            {
                TemplateLanguageFile = languageFile
            };

            // cleaned body as text...
            var bodyText =
                BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message)))
                .RemoveMultipleWhitespace();

            // Send track mails
            var subject =
                this.Get <ILocalization>()
                .GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile)
                .FormatWith(boardName);

            watchEmail.TemplateParams["{forumname}"]     = boardName;
            watchEmail.TemplateParams["{topic}"]         = HttpUtility.HtmlDecode(message.Topic);
            watchEmail.TemplateParams["{postedby}"]      = UserMembershipHelper.GetDisplayNameFromID(messageAuthorUserID);
            watchEmail.TemplateParams["{body}"]          = bodyText;
            watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
            watchEmail.TemplateParams["{link}"]          = YafBuildLink.GetLinkNotEscaped(
                ForumPages.posts,
                true,
                "m={0}#post{0}",
                newMessageId);

            watchEmail.CreateWatch(
                message.TopicID ?? 0,
                messageAuthorUserID,
                new MailAddress(forumEmail, boardName),
                subject);

            // create individual watch emails for all users who have All Posts on...
            foreach (var user in usersWithAll.Where(x => x.UserID != messageAuthorUserID && x.ProviderUserKey != null))
            {
                var membershipUser = UserMembershipHelper.GetUser(user.ProviderUserKey);

                if (membershipUser == null || membershipUser.Email.IsNotSet())
                {
                    continue;
                }

                watchEmail.TemplateLanguageFile = user.LanguageFile.IsSet()
                                                      ? user.LanguageFile
                                                      : this.Get <ILocalization>().LanguageFileName;
                watchEmail.SendEmail(
                    new MailAddress(forumEmail, boardName),
                    new MailAddress(membershipUser.Email, membershipUser.UserName),
                    subject,
                    true);
            }
        }
Beispiel #3
0
        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IEnumerable<TypedUserFind> usersWithAll = new List<TypedUserFind>();

            if (this.Get<YafBoardSettings>().AllowNotificationAllPostsAllTopics)
            {
                // TODO: validate permissions!
                usersWithAll = CommonDb.UserFind(YafContext.Current.PageModuleID, YafContext.Current.PageBoardID,
                    false,
                    null,
                    null,
                    null,
                    UserNotificationSetting.AllTopics.ToInt(),
                    null);
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            var languageFile =  this.Get<YafBoardSettings>().Language;

            foreach (var message in CommonDb.MessageList(YafContext.Current.PageModuleID, newMessageId))
            {
                int userId = message.UserID ?? 0;

                var watchEmail = new YafTemplateEmail("TOPICPOST") { TemplateLanguageFile = languageFile };

                // cleaned body as text...
                var bodyText =
                    StringExtensions.RemoveMultipleWhitespace(
                        BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message))));

                // Send track mails
                var subject =
                    this.Get<ILocalization>().GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile).FormatWith(
                        this.Get<YafBoardSettings>().Name);

                watchEmail.TemplateParams["{forumname}"] = this.Get<YafBoardSettings>().Name;
                watchEmail.TemplateParams["{topic}"] = HttpUtility.HtmlDecode(message.Topic);
                watchEmail.TemplateParams["{postedby}"] = UserMembershipHelper.GetDisplayNameFromID(userId);
                watchEmail.TemplateParams["{body}"] = bodyText;
                watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
                watchEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                    ForumPages.posts, true, "m={0}#post{0}", newMessageId);

                watchEmail.CreateWatch(
                    message.TopicID ?? 0,
                    userId,
                    new MailAddress(this.Get<YafBoardSettings>().ForumEmail, this.Get<YafBoardSettings>().Name),
                    subject);

                // create individual watch emails for all users who have All Posts on...
                foreach (var user in usersWithAll.Where(x => x.UserID.HasValue && x.UserID.Value != userId))
                {
                    // Make sure its not a guest
                    if (user.ProviderUserKey == null)
                    {
                        continue;
                    }

                    var membershipUser = UserMembershipHelper.GetUser(user.ProviderUserKey);

                    if (!membershipUser.Email.IsSet())
                    {
                        continue;
                    }

                    watchEmail.TemplateLanguageFile = !string.IsNullOrEmpty(user.LanguageFile)
                                                          ? user.LanguageFile
                                                          : this.Get<ILocalization>().LanguageFileName;
                    watchEmail.SendEmail(
                        new MailAddress(this.Get<YafBoardSettings>().ForumEmail, this.Get<YafBoardSettings>().Name),
                        new MailAddress(membershipUser.Email, membershipUser.UserName),
                        subject,
                        true);
                }
            }
        }
        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IList<User> usersWithAll = new List<User>();

            if (this.BoardSettings.AllowNotificationAllPostsAllTopics)
            {
                usersWithAll = this.GetRepository<User>()
                    .FindUserTyped(filter: false, notificationType: UserNotificationSetting.AllTopics.ToInt());
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            var languageFile = this.BoardSettings.Language;
            var boardName = this.BoardSettings.Name;
            var forumEmail = this.BoardSettings.ForumEmail;

            var message = LegacyDb.MessageList(newMessageId).FirstOrDefault();

            var messageAuthorUserID = message.UserID ?? 0;

            var watchEmail = new YafTemplateEmail("TOPICPOST") { TemplateLanguageFile = languageFile };

            // cleaned body as text...
            var bodyText =
                BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message)))
                    .RemoveMultipleWhitespace();

            // Send track mails
            var subject =
                this.Get<ILocalization>()
                    .GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile)
                    .FormatWith(boardName);

            watchEmail.TemplateParams["{forumname}"] = boardName;
            watchEmail.TemplateParams["{topic}"] = HttpUtility.HtmlDecode(message.Topic);
            watchEmail.TemplateParams["{postedby}"] = UserMembershipHelper.GetDisplayNameFromID(messageAuthorUserID);
            watchEmail.TemplateParams["{body}"] = bodyText;
            watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
            watchEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                ForumPages.posts,
                true,
                "m={0}#post{0}",
                newMessageId);

            watchEmail.CreateWatch(
                message.TopicID ?? 0,
                messageAuthorUserID,
                new MailAddress(forumEmail, boardName),
                subject);

            // create individual watch emails for all users who have All Posts on...
            foreach (var user in usersWithAll.Where(x => x.UserID != messageAuthorUserID && x.ProviderUserKey != null))
            {
                var membershipUser = UserMembershipHelper.GetUser(user.Name);

                if (membershipUser == null || membershipUser.Email.IsNotSet())
                {
                    continue;
                }

                watchEmail.TemplateLanguageFile = user.LanguageFile.IsSet()
                                                      ? user.LanguageFile
                                                      : this.Get<ILocalization>().LanguageFileName;
                watchEmail.SendEmail(
                    new MailAddress(forumEmail, boardName),
                    new MailAddress(membershipUser.Email, membershipUser.UserName),
                    subject,
                    true);
            }
        }
        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            // Always send watch mails with boards default language
            var languageFile = this.BoardSettings.Language;

            var boardName  = this.BoardSettings.Name;
            var forumEmail = this.BoardSettings.ForumEmail;

            var message = this.GetRepository <Message>().MessageList(newMessageId).FirstOrDefault();

            var messageAuthorUserID = message.UserID ?? 0;

            var watchEmail = new YafTemplateEmail("TOPICPOST")
            {
                TemplateLanguageFile = languageFile
            };

            // cleaned body as text...
            var bodyText = this.Get <IBadWordReplace>()
                           .Replace(BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message))))
                           .RemoveMultipleWhitespace();

            // Send track mails
            var subject = string.Format(
                this.Get <ILocalization>().GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile),
                boardName);

            var logoUrl =
                $"{YafForumInfo.ForumClientFileRoot}{YafBoardFolders.Current.Logos}/{this.BoardSettings.ForumLogo}";
            var themeCss =
                $"{this.Get<YafBoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}";

            watchEmail.TemplateParams["{forumname}"] = boardName;
            watchEmail.TemplateParams["{topic}"]     =
                HttpUtility.HtmlDecode(this.Get <IBadWordReplace>().Replace(message.Topic));
            watchEmail.TemplateParams["{postedby}"]      = UserMembershipHelper.GetDisplayNameFromID(messageAuthorUserID);
            watchEmail.TemplateParams["{body}"]          = bodyText;
            watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
            watchEmail.TemplateParams["{link}"]          = YafBuildLink.GetLinkNotEscaped(
                ForumPages.posts,
                true,
                "m={0}#post{0}",
                newMessageId);
            watchEmail.TemplateParams["{subscriptionlink}"] =
                YafBuildLink.GetLinkNotEscaped(ForumPages.cp_subscriptions, true);
            watchEmail.TemplateParams["{forumname}"] = this.BoardSettings.Name;
            watchEmail.TemplateParams["{forumlink}"] = $"{YafForumInfo.ForumURL}";
            watchEmail.TemplateParams["{themecss}"]  = themeCss;
            watchEmail.TemplateParams["{logo}"]      = $"{this.Get<YafBoardSettings>().BaseUrlMask}{logoUrl}";

            watchEmail.CreateWatch(
                message.TopicID ?? 0,
                messageAuthorUserID,
                new MailAddress(forumEmail, boardName),
                subject);

            if (!this.BoardSettings.AllowNotificationAllPostsAllTopics)
            {
                return;
            }

            var usersWithAll = this.GetRepository <User>().FindUserTyped(
                false,
                notificationType: UserNotificationSetting.AllTopics.ToInt());

            // create individual watch emails for all users who have All Posts on...
            usersWithAll.Where(x => x.ID != messageAuthorUserID && x.ProviderUserKey != null).ForEach(
                user =>
            {
                if (user.Email.IsNotSet())
                {
                    return;
                }

                watchEmail.TemplateLanguageFile = user.LanguageFile.IsSet()
                                                              ? user.LanguageFile
                                                              : this.Get <ILocalization>().LanguageFileName;
                watchEmail.SendEmail(
                    new MailAddress(forumEmail, boardName),
                    new MailAddress(
                        user.Email,
                        this.BoardSettings.EnableDisplayName ? user.DisplayName : user.Name),
                    subject,
                    true);
            });
        }