🔊 Add logs to notification pushing
This commit is contained in:
parent
6965744d5a
commit
28ff78d3e2
@ -226,6 +226,9 @@ public class NotificationService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_logger.LogDebug(
|
||||||
|
$"Pushing notification {notification.Topic} #{notification.Id} to device #{subscription.DeviceId}");
|
||||||
|
|
||||||
var body = string.Empty;
|
var body = string.Empty;
|
||||||
switch (subscription.Provider)
|
switch (subscription.Provider)
|
||||||
{
|
{
|
||||||
@ -245,7 +248,7 @@ public class NotificationService
|
|||||||
["message"] = new Dictionary<string, object>
|
["message"] = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["token"] = subscription.DeviceToken,
|
["token"] = subscription.DeviceToken,
|
||||||
["notification"] = new Dictionary<string, object>
|
["notification"] = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["title"] = notification.Title ?? string.Empty,
|
["title"] = notification.Title ?? string.Empty,
|
||||||
["body"] = body
|
["body"] = body
|
||||||
@ -265,14 +268,14 @@ public class NotificationService
|
|||||||
throw new InvalidOperationException("The apple notification push service is not initialized.");
|
throw new InvalidOperationException("The apple notification push service is not initialized.");
|
||||||
|
|
||||||
var alertDict = new Dictionary<string, object>();
|
var alertDict = new Dictionary<string, object>();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(notification.Title))
|
if (!string.IsNullOrEmpty(notification.Title))
|
||||||
alertDict["title"] = notification.Title;
|
alertDict["title"] = notification.Title;
|
||||||
if (!string.IsNullOrEmpty(notification.Subtitle))
|
if (!string.IsNullOrEmpty(notification.Subtitle))
|
||||||
alertDict["subtitle"] = notification.Subtitle;
|
alertDict["subtitle"] = notification.Subtitle;
|
||||||
if (!string.IsNullOrEmpty(notification.Content))
|
if (!string.IsNullOrEmpty(notification.Content))
|
||||||
alertDict["body"] = notification.Content;
|
alertDict["body"] = notification.Content;
|
||||||
|
|
||||||
var payload = new Dictionary<string, object>
|
var payload = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["topic"] = notification.Topic,
|
["topic"] = notification.Topic,
|
||||||
@ -303,7 +306,12 @@ public class NotificationService
|
|||||||
// Log the exception
|
// Log the exception
|
||||||
// Consider implementing a retry mechanism
|
// Consider implementing a retry mechanism
|
||||||
// Rethrow or handle as needed
|
// Rethrow or handle as needed
|
||||||
|
_logger.LogError(
|
||||||
|
$"Failed to push notification #{notification.Id} to device... {ex.Message} {ex.StackTrace}");
|
||||||
throw new Exception($"Failed to send notification to {subscription.Provider}: {ex.Message}", ex);
|
throw new Exception($"Failed to send notification to {subscription.Provider}: {ex.Message}", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
$"Pushed notification #{notification.Id} to device #{subscription.DeviceId}");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -69,21 +69,31 @@ public class ChatService(
|
|||||||
|
|
||||||
var members = await scopedCrs.ListRoomMembers(room.Id);
|
var members = await scopedCrs.ListRoomMembers(room.Id);
|
||||||
|
|
||||||
|
var metaDict =
|
||||||
|
new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["sender_name"] = sender.Nick ?? sender.Account.Nick,
|
||||||
|
["user_id"] = sender.AccountId,
|
||||||
|
["sender_id"] = sender.Id,
|
||||||
|
["message_id"] = message.Id,
|
||||||
|
["room_id"] = room.Id,
|
||||||
|
["images"] = message.Attachments
|
||||||
|
.Where(a => a.MimeType != null && a.MimeType.StartsWith("image"))
|
||||||
|
.Select(a => a.Id).ToList()
|
||||||
|
};
|
||||||
|
if (sender.Account.Profile is not { PictureId: null })
|
||||||
|
metaDict["pfp"] = sender.Account.Profile.PictureId;
|
||||||
|
if (!string.IsNullOrEmpty(room.Name))
|
||||||
|
metaDict["room_name"] = room.Name;
|
||||||
|
|
||||||
var notification = new Notification
|
var notification = new Notification
|
||||||
{
|
{
|
||||||
Topic = "messages.new",
|
Topic = "messages.new",
|
||||||
Title = $"{sender.Nick ?? sender.Account.Nick ?? "Unknown"} ({roomSubject})",
|
Title = $"{sender.Nick ?? sender.Account.Nick ?? "Unknown"} ({roomSubject})",
|
||||||
Content = !string.IsNullOrEmpty(message.Content)
|
Content = !string.IsNullOrEmpty(message.Content)
|
||||||
? message.Content[..Math.Min(message.Content.Length, 100)]
|
? message.Content[..Math.Min(message.Content.Length, 100)]
|
||||||
: "<attachments>",
|
: "<no content>",
|
||||||
Meta = new Dictionary<string, object>
|
Meta = metaDict,
|
||||||
{
|
|
||||||
["message_id"] = message.Id,
|
|
||||||
["room_id"] = room.Id,
|
|
||||||
["images"] = message.Attachments
|
|
||||||
.Where(a => a.MimeType != null && a.MimeType.StartsWith("image"))
|
|
||||||
.Select(a => a.Id).ToList()
|
|
||||||
},
|
|
||||||
Priority = 10,
|
Priority = 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,7 +106,7 @@ public class ChatService(
|
|||||||
Type = type,
|
Type = type,
|
||||||
Data = message
|
Data = message
|
||||||
});
|
});
|
||||||
|
|
||||||
// Only add accounts that aren't null
|
// Only add accounts that aren't null
|
||||||
if (member.Account.Id != sender.AccountId)
|
if (member.Account.Id != sender.AccountId)
|
||||||
accountsToNotify.Add(member.Account);
|
accountsToNotify.Add(member.Account);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAccessToken_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fb370f448e9f5fca62da785172d83a214319335e27ac4d51840349c6dce15d68_003FAccessToken_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAccessToken_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fb370f448e9f5fca62da785172d83a214319335e27ac4d51840349c6dce15d68_003FAccessToken_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AApnSender_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F6aadc2cf048f477d8636fb2def7b73648200_003Fc5_003F2a1973a9_003FApnSender_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AApnSender_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F6aadc2cf048f477d8636fb2def7b73648200_003Fc5_003F2a1973a9_003FApnSender_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AApnSettings_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F6aadc2cf048f477d8636fb2def7b73648200_003F0f_003F51443844_003FApnSettings_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthenticationMiddleware_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe49de78932194d52a02b07486c6d023a24600_003F2f_003F7ab1cc57_003FAuthenticationMiddleware_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthenticationMiddleware_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe49de78932194d52a02b07486c6d023a24600_003F2f_003F7ab1cc57_003FAuthenticationMiddleware_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthenticationSchemeOptions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe49de78932194d52a02b07486c6d023a24600_003Ff0_003F595b6eda_003FAuthenticationSchemeOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthenticationSchemeOptions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe49de78932194d52a02b07486c6d023a24600_003Ff0_003F595b6eda_003FAuthenticationSchemeOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthorizationAppBuilderExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F2ff26593f91746d7a53418a46dc419d1f200_003F4b_003F56550da2_003FAuthorizationAppBuilderExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAuthorizationAppBuilderExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F2ff26593f91746d7a53418a46dc419d1f200_003F4b_003F56550da2_003FAuthorizationAppBuilderExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user