Skip to content
This repository has been archived by the owner on Feb 7, 2021. It is now read-only.

Commit

Permalink
#21: Implemented auto-follow ticket when creating a reply.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sipke Schoorstra committed Apr 11, 2014
1 parent 93a2421 commit bce3eab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Orchard.Web/Modules/OrchardPros/Handlers/ReplyPartHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Orchard.JobsQueue.Services;
using Orchard.Localization;
using OrchardPros.Models;
using OrchardPros.Services.Content;
using OrchardPros.Services.User;

namespace OrchardPros.Handlers {
Expand All @@ -15,15 +16,24 @@ public class ReplyPartHandler : ContentHandler {
private readonly IShapeFactory _shapeFactory;
private readonly IShapeDisplay _shapeDisplay;
private readonly IJobsQueueService _jobsQueueService;
private readonly ISubscriptionService _subscriptionService;

public ReplyPartHandler(
IUserManager userManager,
IShapeFactory shapeFactory,
IShapeDisplay shapeDisplay,
IJobsQueueService jobsQueueService,
ISubscriptionService subscriptionService) {

public ReplyPartHandler(IUserManager userManager, IShapeFactory shapeFactory, IShapeDisplay shapeDisplay, IJobsQueueService jobsQueueService) {
_userManager = userManager;
_shapeFactory = shapeFactory;
_shapeDisplay = shapeDisplay;
_jobsQueueService = jobsQueueService;
_subscriptionService = subscriptionService;
T = NullLocalizer.Instance;

OnCreated<ReplyPart>(UpdateStats);
OnCreated<ReplyPart>(Subscribe);
OnCreated<ReplyPart>(SendNotifications);
}

Expand All @@ -37,6 +47,16 @@ public class ReplyPartHandler : ContentHandler {
_userManager.AddActivityPoints(user, 5);
}

private void Subscribe(CreateContentContext context, ReplyPart part)
{
var user = part.User;
var ticket = part.ContainingContent.As<TicketPart>();
var subscriptionSource = ticket.As<SubscriptionSourcePart>();

if(!_subscriptionService.HasSubscription(subscriptionSource, user))
_subscriptionService.Subscribe(subscriptionSource, user);
}

private void SendNotifications(CreateContentContext context, ReplyPart part) {
var ticket = part.ContainingContent.As<TicketPart>();
var subscriptionSource = ticket.As<SubscriptionSourcePart>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface ISubscriptionService : IDependency {
Subscription Subscribe(SubscriptionSourcePart subscriptionSource, IUser user);
void Unsubscribe(SubscriptionSourcePart subscriptionSource, IUser user);
IPagedList<SubscriptionSourcePart> GetSubscriptionSourcesByUser(int userId, int? skip = null, int? take = null);
bool HasSubscription(SubscriptionSourcePart subscriptionSource, IUser user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ public class SubscriptionService : ISubscriptionService {
var ids = query.ToArray();
return _contentManager.GetMany<SubscriptionSourcePart>(ids, VersionOptions.Published, QueryHints.Empty).ToPagedList(count);
}

public bool HasSubscription(SubscriptionSourcePart subscriptionSource, IUser user) {
return subscriptionSource.Subscribers.Any(x => x.Id == user.Id);
}
}
}

0 comments on commit bce3eab

Please sign in to comment.