2019-08-02 10:25:33 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2020-02-17 08:58:14 +00:00
|
|
|
|
using ASC.Common;
|
2019-08-02 10:25:33 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Web.Core.Notify
|
|
|
|
|
{
|
|
|
|
|
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; }
|
2019-09-09 12:56:33 +00:00
|
|
|
|
|
2019-10-11 15:03:03 +00:00
|
|
|
|
public StudioNotifyServiceHelper(StudioNotifyHelper studioNotifyHelper, AuthContext authContext, TenantManager tenantManager, 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;
|
2019-10-11 15:03:03 +00:00
|
|
|
|
Cache = cache;
|
2019-09-09 12:56:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-02 10:25: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)
|
2019-08-02 10:25:33 +00:00
|
|
|
|
{
|
|
|
|
|
var subscriptionSource = StudioNotifyHelper.NotifySource.GetSubscriptionProvider();
|
2019-09-12 11:34:58 +00:00
|
|
|
|
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);
|
2019-08-02 10:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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(),
|
2019-08-02 10:25:33 +00:00
|
|
|
|
Action = (NotifyAction)action,
|
|
|
|
|
CheckSubsciption = checkSubsciption
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-15 12:04:42 +00:00
|
|
|
|
if (objectID != null)
|
2019-08-02 10:25:33 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2019-08-02 10:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-31 11:28:30 +00:00
|
|
|
|
|
2019-11-11 09:03:49 +00:00
|
|
|
|
public static class StudioNotifyServiceHelperExtension
|
2019-10-31 11:28:30 +00:00
|
|
|
|
{
|
2020-02-17 08:58:14 +00:00
|
|
|
|
public static DIHelper AddStudioNotifyServiceHelper(this DIHelper services)
|
2019-10-31 11:28:30 +00:00
|
|
|
|
{
|
2020-07-17 10:52:28 +00:00
|
|
|
|
if (services.TryAddScoped<StudioNotifyServiceHelper>())
|
|
|
|
|
{
|
|
|
|
|
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
|
|
|
|
|
|
|
|
|
return services
|
|
|
|
|
.AddAuthContextService()
|
|
|
|
|
.AddStudioNotifyHelperService()
|
|
|
|
|
.AddTenantManagerService();
|
|
|
|
|
}
|
2019-10-31 11:28:30 +00:00
|
|
|
|
|
2020-07-17 10:52:28 +00:00
|
|
|
|
return services;
|
2019-10-31 11:28:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
|
}
|