From 2f08aae86ad40f9c97d315d90d1968f296306fe8 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Mon, 25 Sep 2023 17:11:13 +0300 Subject: [PATCH] Notify: fix footer --- .../Notify/Engine/NotifyEngine.cs | 6 ++++ .../Notify/Engine/NotifyRequest.cs | 27 ++++++++++++++++ common/ASC.Core.Common/Notify/NotifySource.cs | 31 ++----------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs b/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs index 3bc6a26190..279840d44d 100644 --- a/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs +++ b/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs @@ -330,6 +330,12 @@ public class NotifyEngine //Do styling here if (!string.IsNullOrEmpty(pattern.Styler)) { + var tenantManager = serviceScope.ServiceProvider.GetService(); + var userManager = serviceScope.ServiceProvider.GetService(); + + var culture = await request.GetCulture(tenantManager, userManager); + CultureInfo.CurrentCulture = culture; + CultureInfo.CurrentUICulture = culture; //We need to run through styler before templating StyleMessage(serviceScope, noticeMessage); } diff --git a/common/ASC.Core.Common/Notify/Engine/NotifyRequest.cs b/common/ASC.Core.Common/Notify/Engine/NotifyRequest.cs index 92ed689ec1..73c71bf93f 100644 --- a/common/ASC.Core.Common/Notify/Engine/NotifyRequest.cs +++ b/common/ASC.Core.Common/Notify/Engine/NotifyRequest.cs @@ -139,4 +139,31 @@ public class NotifyRequest { return ((INotifySource)scope.ServiceProvider.GetService(_notifySource.GetType())).GetSubscriptionProvider(); } + + public async Task GetCulture(TenantManager tenantManager, UserManager userManager) + { + var tagCulture = Arguments.FirstOrDefault(a => a.Tag == "Culture"); + if (tagCulture != null) + { + return CultureInfo.GetCultureInfo((string)tagCulture.Value); + } + + CultureInfo culture = null; + + var tenant = await tenantManager.GetCurrentTenantAsync(false); + + if (tenant != null) + { + culture = tenant.GetCulture(); + } + + var user = await userManager.SearchUserAsync(Recipient.ID); + + if (!Core.Users.Constants.LostUser.Equals(user) && !string.IsNullOrEmpty(user.CultureName)) + { + culture = user.GetCulture(); + } + + return culture; + } } diff --git a/common/ASC.Core.Common/Notify/NotifySource.cs b/common/ASC.Core.Common/Notify/NotifySource.cs index 6c676bfb9d..3fa0d878dd 100644 --- a/common/ASC.Core.Common/Notify/NotifySource.cs +++ b/common/ASC.Core.Common/Notify/NotifySource.cs @@ -57,7 +57,7 @@ public abstract class NotifySource : INotifySource public async Task GetActionProvider(NotifyRequest r) { - var culture = await GetCulture(r); + var culture = await r.GetCulture(_tenantManager, _userManager); CultureInfo.CurrentCulture = culture; CultureInfo.CurrentUICulture = culture; @@ -74,7 +74,7 @@ public abstract class NotifySource : INotifySource public async Task GetPatternProvider(NotifyRequest r) { - var culture = await GetCulture(r); + var culture = await r.GetCulture(_tenantManager, _userManager); CultureInfo.CurrentCulture = culture; CultureInfo.CurrentUICulture = culture; @@ -117,31 +117,4 @@ public abstract class NotifySource : INotifySource return new RecipientProviderImpl(_userManager) ?? throw new NotifyException("Provider IRecipientsProvider not instanced."); } - - private async Task GetCulture(NotifyRequest r) - { - var tagCulture = r.Arguments.FirstOrDefault(a => a.Tag == "Culture"); - if (tagCulture != null) - { - return CultureInfo.GetCultureInfo((string)tagCulture.Value); - } - - CultureInfo culture = null; - - var tenant = await _tenantManager.GetCurrentTenantAsync(false); - - if (tenant != null) - { - culture = tenant.GetCulture(); - } - - var user = await _userManager.SearchUserAsync(r.Recipient.ID); - - if (!Users.Constants.LostUser.Equals(user) && !string.IsNullOrEmpty(user.CultureName)) - { - culture = user.GetCulture(); - } - - return culture; - } }