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