/// <summary> /// Handle Commands for restoring an old Message Version /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void RevisionsList_ItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e) { switch (e.CommandName) { case "restore": var currentMessage = LegacyDb.MessageList(this.messageID).FirstOrDefault(); DataRow restoreMessage = null; var revisionsTable = LegacyDb.messagehistory_list( this.messageID, this.PageContext.BoardSettings.MessageHistoryDaysToLog).AsEnumerable(); foreach (var row in Enumerable.Where(revisionsTable, row => row["Edited"].ToType <string>().Equals(e.CommandArgument.ToType <string>()))) { restoreMessage = row; } if (restoreMessage != null) { LegacyDb.message_update( this.messageID, currentMessage.Priority, restoreMessage["Message"], currentMessage.Description, currentMessage.Status, currentMessage.Styles, currentMessage.Topic, currentMessage.Flags.BitValue, restoreMessage["EditReason"], this.PageContext.PageUserID != currentMessage.UserID, this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess, currentMessage.Message, this.PageContext.PageUserID); this.PageContext.AddLoadMessage(this.GetText("MESSAGE_RESTORED"), MessageTypes.success); } break; } }
private SimpleTopic LoadSimpleTopic([NotNull] DataRow row, [NotNull] SimpleForum forum) { CodeContracts.VerifyNotNull(row, "row"); CodeContracts.VerifyNotNull(forum, "forum"); return(new SimpleTopic { TopicID = row.Field <int>("TopicID"), CreatedDate = row.Field <DateTime>("Posted"), Subject = row.Field <string>("Subject"), StartedUserID = row.Field <int>("UserID"), StartedUserName = UserMembershipHelper.GetDisplayNameFromID(row.Field <int>("UserID")), Replies = row.Field <int>("Replies"), LastPostDate = row.Field <DateTime>("LastPosted"), LastUserID = row.Field <int>("LastUserID"), LastUserName = UserMembershipHelper.GetDisplayNameFromID(row.Field <int>("LastUserID")), LastMessageID = row.Field <int>("LastMessageID"), FirstMessage = row.Field <string>("FirstMessage"), LastMessage = LegacyDb.MessageList(row.Field <int>("LastMessageID")).First().Message, Forum = forum }); }
/// <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); } } }
/// <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); } }