2019-05-15 14:56:09 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
*
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-08-15 12:04:42 +00:00
|
|
|
using System;
|
2020-08-27 14:01:37 +00:00
|
|
|
|
2020-08-31 09:01:23 +00:00
|
|
|
using ASC.Common;
|
2019-05-15 14:56:09 +00:00
|
|
|
using ASC.Core.Notify.Senders;
|
|
|
|
using ASC.Core.Tenants;
|
|
|
|
using ASC.Notify.Messages;
|
|
|
|
using ASC.Notify.Sinks;
|
2020-08-27 14:01:37 +00:00
|
|
|
|
2019-09-09 12:56:33 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
2019-05-15 14:56:09 +00:00
|
|
|
namespace ASC.Core.Notify
|
|
|
|
{
|
|
|
|
class JabberSenderSink : Sink
|
|
|
|
{
|
|
|
|
private static readonly string senderName = ASC.Core.Configuration.Constants.NotifyMessengerSenderSysName;
|
|
|
|
private readonly INotifySender sender;
|
|
|
|
|
|
|
|
|
2019-09-09 12:56:33 +00:00
|
|
|
public JabberSenderSink(INotifySender sender, IServiceProvider serviceProvider)
|
2019-08-15 13:20:23 +00:00
|
|
|
{
|
2022-01-24 10:49:00 +00:00
|
|
|
this.sender = sender ?? throw new ArgumentNullException(nameof(sender));
|
2019-09-09 12:56:33 +00:00
|
|
|
ServiceProvider = serviceProvider;
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:58:08 +00:00
|
|
|
private IServiceProvider ServiceProvider { get; }
|
2019-05-15 14:56:09 +00:00
|
|
|
|
|
|
|
public override SendResponse ProcessMessage(INoticeMessage message)
|
|
|
|
{
|
|
|
|
try
|
2019-09-09 12:56:33 +00:00
|
|
|
{
|
|
|
|
using var scope = ServiceProvider.CreateScope();
|
2020-08-31 09:01:23 +00:00
|
|
|
var scopeClass = scope.ServiceProvider.GetService<JabberSenderSinkScope>();
|
|
|
|
(var userManager, var tenantManager) = scopeClass;
|
2019-05-15 14:56:09 +00:00
|
|
|
var result = SendResult.OK;
|
2019-09-09 12:56:33 +00:00
|
|
|
var username = userManager.GetUsers(new Guid(message.Recipient.ID)).UserName;
|
2019-05-15 14:56:09 +00:00
|
|
|
if (string.IsNullOrEmpty(username))
|
|
|
|
{
|
|
|
|
result = SendResult.IncorrectRecipient;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var m = new NotifyMessage
|
|
|
|
{
|
|
|
|
To = username,
|
|
|
|
Subject = message.Subject,
|
|
|
|
ContentType = message.ContentType,
|
|
|
|
Content = message.Body,
|
|
|
|
Sender = senderName,
|
2019-08-01 08:47:15 +00:00
|
|
|
CreationDate = DateTime.UtcNow.Ticks,
|
2019-05-15 14:56:09 +00:00
|
|
|
};
|
|
|
|
|
2019-09-18 12:14:15 +00:00
|
|
|
var tenant = tenantManager.GetCurrentTenant(false);
|
2019-05-15 14:56:09 +00:00
|
|
|
m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;
|
|
|
|
|
2020-10-12 19:39:23 +00:00
|
|
|
sender.Send(m);
|
2019-05-15 14:56:09 +00:00
|
|
|
}
|
|
|
|
return new SendResponse(message, senderName, result);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
return new SendResponse(message, senderName, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-28 20:02:03 +00:00
|
|
|
|
|
|
|
[Scope]
|
2020-08-31 09:01:23 +00:00
|
|
|
public class JabberSenderSinkScope
|
|
|
|
{
|
|
|
|
private UserManager UserManager { get; }
|
|
|
|
private TenantManager TenantManager { get; }
|
|
|
|
|
|
|
|
public JabberSenderSinkScope(UserManager userManager, TenantManager tenantManager)
|
|
|
|
{
|
|
|
|
TenantManager = tenantManager;
|
|
|
|
UserManager = userManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Deconstruct(out UserManager userManager, out TenantManager tenantManager)
|
2020-09-30 14:47:42 +00:00
|
|
|
{
|
|
|
|
(userManager, tenantManager) = (UserManager, TenantManager);
|
|
|
|
}
|
2020-08-31 09:01:23 +00:00
|
|
|
}
|
2019-05-15 14:56:09 +00:00
|
|
|
}
|