Fixing notification actions.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
public const string LocalDraftStartPrefix = "localDraft_";
|
||||
|
||||
public const string ToastMailItemIdKey = nameof(ToastMailItemIdKey);
|
||||
public const string ToastMailItemRemoteFolderIdKey = nameof(ToastMailItemRemoteFolderIdKey);
|
||||
public const string ToastActionKey = nameof(ToastActionKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ namespace Wino.Core.UWP.Services
|
||||
builder.AddArgument(Constants.ToastMailItemIdKey, mailItem.UniqueId.ToString());
|
||||
builder.AddArgument(Constants.ToastActionKey, MailOperation.Navigate);
|
||||
|
||||
builder.AddButton(GetMarkedAsRead(mailItem.Id));
|
||||
builder.AddButton(GetDeleteButton(mailItem.Id));
|
||||
builder.AddButton(GetMarkedAsRead(mailItem.Id, mailItem.AssignedFolder.RemoteFolderId));
|
||||
builder.AddButton(GetDeleteButton(mailItem.Id, mailItem.AssignedFolder.RemoteFolderId));
|
||||
builder.AddButton(GetDismissButton());
|
||||
|
||||
builder.Show();
|
||||
@@ -103,19 +103,21 @@ namespace Wino.Core.UWP.Services
|
||||
.SetDismissActivation()
|
||||
.SetImageUri(new Uri("ms-appx:///Assets/NotificationIcons/dismiss.png"));
|
||||
|
||||
private ToastButton GetDeleteButton(string mailCopyId)
|
||||
private ToastButton GetDeleteButton(string mailCopyId, string remoteFolderId)
|
||||
=> new ToastButton()
|
||||
.SetContent(Translator.MailOperation_Delete)
|
||||
.SetImageUri(new Uri("ms-appx:///Assets/NotificationIcons/delete.png"))
|
||||
.AddArgument(Constants.ToastMailItemIdKey, mailCopyId)
|
||||
.AddArgument(Constants.ToastMailItemRemoteFolderIdKey, remoteFolderId)
|
||||
.AddArgument(Constants.ToastActionKey, MailOperation.SoftDelete)
|
||||
.SetBackgroundActivation();
|
||||
|
||||
private ToastButton GetMarkedAsRead(string mailCopyId)
|
||||
private ToastButton GetMarkedAsRead(string mailCopyId, string remoteFolderId)
|
||||
=> new ToastButton()
|
||||
.SetContent(Translator.MailOperation_MarkAsRead)
|
||||
.SetImageUri(new System.Uri("ms-appx:///Assets/NotificationIcons/markread.png"))
|
||||
.AddArgument(Constants.ToastMailItemIdKey, mailCopyId)
|
||||
.AddArgument(Constants.ToastMailItemRemoteFolderIdKey, remoteFolderId)
|
||||
.AddArgument(Constants.ToastActionKey, MailOperation.MarkAsRead)
|
||||
.SetBackgroundActivation();
|
||||
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
using Serilog;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.Background;
|
||||
using Windows.ApplicationModel.Core;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Notifications;
|
||||
using Wino.Core;
|
||||
using Wino.Core.Domain;
|
||||
@@ -59,14 +56,8 @@ namespace Wino.Activation
|
||||
|
||||
if (taskName == BackgroundTaskService.ToastActivationTaskEx)
|
||||
{
|
||||
// ToastNotificationActionTriggerDetail somehow use UI thread.
|
||||
// Calling this without a dispatcher will result in error.
|
||||
|
||||
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
|
||||
{
|
||||
if (instance.TriggerDetails is ToastNotificationActionTriggerDetail toastNotificationActionTriggerDetail)
|
||||
_toastArguments = ToastArguments.Parse(toastNotificationActionTriggerDetail.Argument);
|
||||
});
|
||||
if (instance.TriggerDetails is ToastNotificationActionTriggerDetail toastNotificationActionTriggerDetail)
|
||||
_toastArguments = ToastArguments.Parse(toastNotificationActionTriggerDetail.Argument);
|
||||
|
||||
// All toast activation mail actions are handled here like mark as read or delete.
|
||||
// This should not launch the application on the foreground.
|
||||
@@ -75,10 +66,10 @@ namespace Wino.Activation
|
||||
// Prepare package and send to delegator.
|
||||
|
||||
if (_toastArguments.TryGetValue(Constants.ToastMailItemIdKey, out string mailItemId) &&
|
||||
_toastArguments.TryGetValue(Constants.ToastActionKey, out MailOperation action))
|
||||
_toastArguments.TryGetValue(Constants.ToastActionKey, out MailOperation action) &&
|
||||
_toastArguments.TryGetValue(Constants.ToastMailItemRemoteFolderIdKey, out string remoteFolderId))
|
||||
{
|
||||
// TODO: Remote folder id.
|
||||
var mailItem = await _mailService.GetSingleMailItemAsync(mailItemId, string.Empty);
|
||||
var mailItem = await _mailService.GetSingleMailItemAsync(mailItemId, remoteFolderId);
|
||||
|
||||
if (mailItem == null) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user