2012-12-17 09:41:11 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using NotificationsCore;
|
|
|
|
|
using umbraco.presentation.nodeFactory;
|
|
|
|
|
using umbraco.cms.businesslogic.member;
|
2015-01-26 13:13:06 +01:00
|
|
|
using Umbraco.Core;
|
2015-02-17 11:51:06 +01:00
|
|
|
using NotificationsWeb.Services;
|
2015-07-26 12:31:15 +02:00
|
|
|
using OurUmbraco.Forum;
|
|
|
|
|
using OurUmbraco.Forum.Services;
|
2015-06-03 00:53:15 +02:00
|
|
|
using Umbraco.Web.Security;
|
2012-12-17 09:41:11 +01:00
|
|
|
|
|
|
|
|
namespace NotificationsWeb.EventHandlers
|
|
|
|
|
{
|
2015-01-26 13:13:06 +01:00
|
|
|
public class Forum : ApplicationEventHandler
|
2012-12-17 09:41:11 +01:00
|
|
|
{
|
2015-02-23 19:54:15 +01:00
|
|
|
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
2012-12-17 09:41:11 +01:00
|
|
|
{
|
2015-01-26 13:13:06 +01:00
|
|
|
//sub comment author to topic
|
|
|
|
|
CommentService.Created += CommentService_Created;
|
2012-12-17 09:41:11 +01:00
|
|
|
|
2015-01-26 13:13:06 +01:00
|
|
|
//sub owner to topic
|
|
|
|
|
TopicService.Created += TopicService_Created;
|
2012-12-17 09:41:11 +01:00
|
|
|
|
2015-01-26 13:13:06 +01:00
|
|
|
//If its a project forum, subscribe the owner to all topics
|
|
|
|
|
ForumService.Created += ForumService_Created;
|
2012-12-17 09:41:11 +01:00
|
|
|
|
2015-01-26 13:13:06 +01:00
|
|
|
//remove all forum subs
|
|
|
|
|
ForumService.Deleted += ForumService_Deleted;
|
2012-12-17 09:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-26 12:31:15 +02:00
|
|
|
void ForumService_Deleted(object sender, ForumEventArgs e)
|
2012-12-17 09:41:11 +01:00
|
|
|
{
|
2015-03-02 13:52:07 +11:00
|
|
|
var ns = new NotificationService(ApplicationContext.Current.DatabaseContext);
|
|
|
|
|
ns.RemoveAllForumSubscriptions(e.Forum.Id);
|
2012-12-17 09:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-26 12:31:15 +02:00
|
|
|
void ForumService_Created(object sender, ForumEventArgs e)
|
2012-12-17 09:41:11 +01:00
|
|
|
{
|
2015-01-26 13:13:06 +01:00
|
|
|
var content = Umbraco.Web.UmbracoContext.Current.Application.Services.ContentService.GetById(e.Forum.ParentId);
|
|
|
|
|
if (content.ContentType.Alias == "Project")
|
2012-12-17 09:41:11 +01:00
|
|
|
{
|
2015-01-26 13:13:06 +01:00
|
|
|
var owner = content.GetValue<int>("owner");
|
2015-02-17 11:51:06 +01:00
|
|
|
//NotificationsWeb.BusinessLogic.Forum.Subscribe(e.Forum.Id, owner);
|
2015-03-02 13:52:07 +11:00
|
|
|
var ns = new NotificationService(ApplicationContext.Current.DatabaseContext);
|
|
|
|
|
ns.SubscribeToForum(e.Forum.Id, owner);
|
2012-12-17 09:41:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-26 12:31:15 +02:00
|
|
|
void TopicService_Created(object sender, TopicEventArgs e)
|
2012-12-17 09:41:11 +01:00
|
|
|
{
|
2015-02-17 11:51:06 +01:00
|
|
|
|
2015-03-02 13:52:07 +11:00
|
|
|
var ns = new NotificationService(ApplicationContext.Current.DatabaseContext);
|
|
|
|
|
ns.SubscribeToForumTopic(e.Topic.Id, e.Topic.MemberId);
|
2012-12-17 09:41:11 +01:00
|
|
|
|
|
|
|
|
//send notification
|
|
|
|
|
InstantNotification not = new InstantNotification();
|
|
|
|
|
|
2015-01-26 13:13:06 +01:00
|
|
|
//data for notification:
|
2015-06-03 00:53:15 +02:00
|
|
|
var membershipHelper = new MembershipHelper(Umbraco.Web.UmbracoContext.Current);
|
|
|
|
|
var member = membershipHelper.GetById(e.Topic.MemberId);
|
|
|
|
|
var memberName = string.Empty;
|
|
|
|
|
if (member != null)
|
|
|
|
|
memberName = member.Name;
|
|
|
|
|
|
|
|
|
|
not.Invoke(Config.ConfigurationFile, Config.AssemblyDir, "NewTopic", e.Topic, e.Topic.GetUrl(), memberName);
|
2012-12-17 09:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-26 12:31:15 +02:00
|
|
|
void CommentService_Created(object sender, CommentEventArgs e)
|
2012-12-17 09:41:11 +01:00
|
|
|
{
|
2015-03-02 13:52:07 +11:00
|
|
|
var ts = new TopicService(ApplicationContext.Current.DatabaseContext);
|
|
|
|
|
|
2015-01-26 13:13:06 +01:00
|
|
|
//Subscribe to topic
|
2015-03-02 13:52:07 +11:00
|
|
|
var ns = new NotificationService(ApplicationContext.Current.DatabaseContext);
|
|
|
|
|
ns.SubscribeToForumTopic(e.Comment.TopicId, e.Comment.MemberId);
|
|
|
|
|
|
2015-01-26 13:13:06 +01:00
|
|
|
//data for notification:
|
2015-06-03 00:53:15 +02:00
|
|
|
var membershipHelper = new MembershipHelper(Umbraco.Web.UmbracoContext.Current);
|
2015-06-14 14:30:53 +02:00
|
|
|
var member = membershipHelper.GetById(e.Comment.MemberId);
|
2015-06-03 00:53:15 +02:00
|
|
|
var memberName = string.Empty;
|
|
|
|
|
if (member != null)
|
|
|
|
|
memberName = member.Name;
|
2015-03-02 13:52:07 +11:00
|
|
|
var topic = ts.GetById(e.Comment.TopicId);
|
2015-01-26 13:13:06 +01:00
|
|
|
|
|
|
|
|
//send notifications
|
|
|
|
|
InstantNotification not = new InstantNotification();
|
2015-06-03 00:53:15 +02:00
|
|
|
not.Invoke(Config.ConfigurationFile, Config.AssemblyDir, "NewComment", e.Comment, topic, topic.GetUrl(), memberName);
|
2012-12-17 09:41:11 +01:00
|
|
|
}
|
2015-01-26 13:13:06 +01:00
|
|
|
|
|
|
|
|
|
2012-12-17 09:41:11 +01:00
|
|
|
}
|
|
|
|
|
}
|