DocSpace-buildtools/web/ASC.Web.Core/Notify/StudioNotifyServiceHelper.cs

124 lines
4.7 KiB
C#
Raw Normal View History

using System.Linq;
2020-02-17 08:58:14 +00:00
using ASC.Common;
using ASC.Common.Caching;
using ASC.Core;
using ASC.Notify.Model;
using ASC.Notify.Patterns;
using ASC.Notify.Recipients;
using ASC.Web.Studio.Core.Notify;
2020-10-30 15:42:56 +00:00
using ASC.Web.Studio.Utility;
namespace ASC.Web.Core.Notify
{
2020-10-19 15:53:15 +00:00
[Scope]
public class StudioNotifyServiceHelper
{
2020-08-12 09:58:08 +00:00
private ICacheNotify<NotifyItem> Cache { get; }
private StudioNotifyHelper StudioNotifyHelper { get; }
private AuthContext AuthContext { get; }
private TenantManager TenantManager { get; }
2020-10-30 15:42:56 +00:00
public CommonLinkUtility CommonLinkUtility { get; }
2019-09-09 12:56:33 +00:00
2020-10-30 14:57:31 +00:00
public StudioNotifyServiceHelper(
StudioNotifyHelper studioNotifyHelper,
AuthContext authContext,
TenantManager tenantManager,
2020-10-30 15:42:56 +00:00
CommonLinkUtility commonLinkUtility,
2020-10-30 14:57:31 +00:00
ICacheNotify<NotifyItem> cache)
2019-09-09 12:56:33 +00:00
{
StudioNotifyHelper = studioNotifyHelper;
AuthContext = authContext;
2019-09-18 12:14:15 +00:00
TenantManager = tenantManager;
2020-10-30 15:42:56 +00:00
CommonLinkUtility = commonLinkUtility;
2019-10-11 15:03:03 +00:00
Cache = cache;
2019-09-09 12:56:33 +00:00
}
public void SendNoticeToAsync(INotifyAction action, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
{
SendNoticeToAsync(action, null, recipients, senderNames, false, args);
}
2020-02-17 08:58:14 +00:00
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
{
SendNoticeToAsync(action, objectID, recipients, senderNames, false, args);
}
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, params ITagValue[] args)
{
SendNoticeToAsync(action, objectID, recipients, null, false, args);
}
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, bool checkSubscription, params ITagValue[] args)
{
SendNoticeToAsync(action, objectID, recipients, null, checkSubscription, args);
}
public void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, params ITagValue[] args)
{
SendNoticeToAsync(action, objectID, new[] { recipient }, null, false, args);
}
public void SendNoticeAsync(INotifyAction action, string objectID, params ITagValue[] args)
{
var subscriptionSource = StudioNotifyHelper.NotifySource.GetSubscriptionProvider();
var recipients = subscriptionSource.GetRecipients(action, objectID);
2019-08-15 12:04:42 +00:00
2020-02-17 08:58:14 +00:00
SendNoticeToAsync(action, objectID, recipients, null, false, args);
}
public void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, bool checkSubscription, params ITagValue[] args)
{
SendNoticeToAsync(action, objectID, new[] { recipient }, null, checkSubscription, args);
}
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
{
var item = new NotifyItem
{
2019-09-18 12:14:15 +00:00
TenantId = TenantManager.GetCurrentTenant().TenantId,
2019-09-09 12:56:33 +00:00
UserId = AuthContext.CurrentAccount.ID.ToString(),
Action = (NotifyAction)action,
2020-10-30 15:42:56 +00:00
CheckSubsciption = checkSubsciption,
BaseUrl = CommonLinkUtility.GetFullAbsolutePath("")
};
2019-08-15 12:04:42 +00:00
if (objectID != null)
{
item.ObjectID = objectID;
}
if (recipients != null)
{
foreach (var r in recipients)
{
var recipient = new Recipient { ID = r.ID, Name = r.Name };
if (r is IDirectRecipient d)
{
recipient.Addresses.AddRange(d.Addresses);
recipient.CheckActivation = d.CheckActivation;
}
if (r is IRecipientsGroup g)
{
recipient.IsGroup = true;
}
item.Recipients.Add(recipient);
}
}
if (senderNames != null)
{
item.SenderNames.AddRange(senderNames);
}
2020-09-10 09:02:26 +00:00
if (args != null)
{
item.Tags.AddRange(args.Select(r => new Tag { Tag_ = r.Tag, Value = r.Value.ToString() }));
}
2019-10-11 15:03:03 +00:00
Cache.Publish(item, CacheNotifyAction.Any);
}
}
}