using SiberTek.Xenta.Entities;
using SiberTek.Xenta.Enums;
using SiberTek.Xenta.Managers;
using SiberTek.Xenta.Utils;
namespace SiberTek.Xenta.Extensions
{
/// <summary>
/// Contains message manager extension methods
/// </summary>
public static class ForumMessageManagerExtesion
{
#region Methods
public static bool SendForumPostNotification(this MessageManager mgr, int postID)
{
ForumPostInfo post = ForumPostManager.Instance.GetForumPost(postID);
if(post == null)
{
return false;
}
ForumTopicInfo topic = post.Topic;
if(topic == null)
{
return false;
}
ForumInfo forum = topic.Forum;
if(forum == null)
{
return false;
}
int msgCount = 0;
foreach(ForumSubscriptionInfo subscription in topic.Subscriptions)
{
UserInfo user = subscription.User;
MessageTemplateInfo template = mgr.GetMessageTemplateByName(user.LanguageID, "forum-post-notification");
if(template == null)
{
continue;
}
string subject = template.Subject;
string text = template.Text;
subject = subject.Replace("[Token:Forum.Title]", forum.Title);
subject = subject.Replace("[Token:ForumTopic.Title]", topic.Title);
subject = subject.Replace("[Token:ForumPost.Title]", post.Title);
subject = subject.Replace("[Token:ForumPost.Author]", post.Author.Username);
text = text.Replace("[Token:Forum.ID]", forum.ForumID.ToString());
text = text.Replace("[Token:Forum.Title]", forum.Title);
text = text.Replace("[Token:Forum.Description]", StringHelper.ConvertBBCodeToHtml(forum.Description));
text = text.Replace("[Token:ForumTopic.ID]", topic.TopicID.ToString());
text = text.Replace("[Token:ForumTopic.Title]", topic.Title);
text = text.Replace("[Token:ForumTopic.Description]", StringHelper.ConvertBBCodeToHtml(topic.Description));
text = text.Replace("[Token:ForumPost.ID]", post.PostID.ToString());
text = text.Replace("[Token:ForumPost.Title]", post.Title);
text = text.Replace("[Token:ForumPost.Text]", StringHelper.ConvertBBCodeToHtml(post.Text));
text = text.Replace("[Token:ForumPost.Author]", post.Author.Username);
MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, user.Email, template.BccTo, subject, text);
msgCount++;
}
return msgCount > 0;
}
public static bool SendForumTopicNotification(this MessageManager mgr, int topicID)
{
ForumTopicInfo topic = ForumTopicManager.Instance.GetForumTopic(topicID);
if(topic == null)
{
return false;
}
ForumInfo forum = topic.Forum;
if(topic == null)
{
return false;
}
int msgCount = 0;
foreach(ForumSubscriptionInfo subscription in forum.Subscriptions)
{
UserInfo user = subscription.User;
MessageTemplateInfo template = mgr.GetMessageTemplateByName(user.LanguageID, "forum-topic-notification");
if(template == null)
{
continue;
}
string subject = template.Subject;
string text = template.Text;
subject = subject.Replace("[Token:Forum.Title]", forum.Title);
subject = subject.Replace("[Token:ForumTopic.Title]", topic.Title);
subject = subject.Replace("[Token:ForumTopic.Author]", topic.Author.Username);
text = text.Replace("[Token:Forum.ID]", forum.ForumID.ToString());
text = text.Replace("[Token:Forum.Title]", forum.Title);
text = text.Replace("[Token:Forum.Description]", StringHelper.ConvertBBCodeToHtml(forum.Description));
text = text.Replace("[Token:ForumTopic.ID]", topic.TopicID.ToString());
text = text.Replace("[Token:ForumTopic.Title]", topic.Title);
text = text.Replace("[Token:ForumTopic.Author]", topic.Author.Username);
text = text.Replace("[Token:ForumTopic.Description]", StringHelper.ConvertBBCodeToHtml(topic.Description));
MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, user.Email, template.BccTo, template.Subject, text);
msgCount++;
}
return msgCount > 0;
}
#endregion
}
}