Check account notification preferences after the synchronization. (#647)
This commit is contained in:
@@ -162,4 +162,12 @@ public interface IAccountService
|
|||||||
/// <param name="accountId">Identifies the account for which the synchronization identifier is being updated.</param>
|
/// <param name="accountId">Identifies the account for which the synchronization identifier is being updated.</param>
|
||||||
/// <param name="syncIdentifier">Represents the new synchronization identifier to be set for the specified account.</param>
|
/// <param name="syncIdentifier">Represents the new synchronization identifier to be set for the specified account.</param>
|
||||||
Task<string> UpdateSyncIdentifierRawAsync(Guid accountId, string syncIdentifier);
|
Task<string> UpdateSyncIdentifierRawAsync(Guid accountId, string syncIdentifier);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether the notifications are enabled for the given account id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="accountId">Account id.</param>
|
||||||
|
/// <returns>Whether the notifications should be created after sync or not.</returns>
|
||||||
|
Task<bool> IsNotificationsEnabled(Guid accountId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,14 +23,17 @@ public class MailSynchronizationRequestHandler : ServerMessageHandler<NewMailSyn
|
|||||||
|
|
||||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||||
private readonly INotificationBuilder _notificationBuilder;
|
private readonly INotificationBuilder _notificationBuilder;
|
||||||
|
private readonly IAccountService _accountService;
|
||||||
private readonly IFolderService _folderService;
|
private readonly IFolderService _folderService;
|
||||||
|
|
||||||
public MailSynchronizationRequestHandler(ISynchronizerFactory synchronizerFactory,
|
public MailSynchronizationRequestHandler(ISynchronizerFactory synchronizerFactory,
|
||||||
INotificationBuilder notificationBuilder,
|
INotificationBuilder notificationBuilder,
|
||||||
|
IAccountService accountService,
|
||||||
IFolderService folderService)
|
IFolderService folderService)
|
||||||
{
|
{
|
||||||
_synchronizerFactory = synchronizerFactory;
|
_synchronizerFactory = synchronizerFactory;
|
||||||
_notificationBuilder = notificationBuilder;
|
_notificationBuilder = notificationBuilder;
|
||||||
|
_accountService = accountService;
|
||||||
_folderService = folderService;
|
_folderService = folderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +56,9 @@ public class MailSynchronizationRequestHandler : ServerMessageHandler<NewMailSyn
|
|||||||
{
|
{
|
||||||
var synchronizationResult = await synchronizer.SynchronizeMailsAsync(message.Options, cancellationToken).ConfigureAwait(false);
|
var synchronizationResult = await synchronizer.SynchronizeMailsAsync(message.Options, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (synchronizationResult.DownloadedMessages?.Any() ?? false || !synchronizer.Account.Preferences.IsNotificationsEnabled)
|
bool isNotificationsEnabled = await _accountService.IsNotificationsEnabled(synchronizer.Account.Id).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (isNotificationsEnabled && (synchronizationResult.DownloadedMessages?.Any() ?? false))
|
||||||
{
|
{
|
||||||
var accountInboxFolder = await _folderService.GetSpecialFolderByAccountIdAsync(message.Options.AccountId, SpecialFolderType.Inbox);
|
var accountInboxFolder = await _folderService.GetSpecialFolderByAccountIdAsync(message.Options.AccountId, SpecialFolderType.Inbox);
|
||||||
|
|
||||||
|
|||||||
@@ -615,4 +615,11 @@ public class AccountService : BaseDatabaseService, IAccountService
|
|||||||
var account = await GetAccountAsync(accountId);
|
var account = await GetAccountAsync(accountId);
|
||||||
return account.Preferences.IsFocusedInboxEnabled.GetValueOrDefault();
|
return account.Preferences.IsFocusedInboxEnabled.GetValueOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> IsNotificationsEnabled(Guid accountId)
|
||||||
|
{
|
||||||
|
var account = await GetAccountAsync(accountId);
|
||||||
|
|
||||||
|
return account?.Preferences?.IsNotificationsEnabled ?? false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user