2026-10-01 11:32:33 +02:00
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using MongoDB.Entities;
|
|
|
|
|
|
|
|
|
|
using PrivaPub.Models.Social;
|
|
|
|
|
|
|
|
|
|
namespace PrivaPub.Domain.Social
|
|
|
|
|
{
|
|
|
|
|
public static class Notifications
|
|
|
|
|
{
|
|
|
|
|
public static async Task Add(string avatarId, NotificationType type, string fromAccountId, string fromActorUri, string postId,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
2026-10-01 18:35:20 +02:00
|
|
|
if (string.IsNullOrEmpty(avatarId) || avatarId == fromAccountId && type != NotificationType.Poll)
|
2026-10-01 11:32:33 +02:00
|
|
|
return;
|
2026-10-01 12:13:57 +02:00
|
|
|
if ((await Relationships.Hidden.AuthorsHiddenFrom(avatarId, new[] { fromActorUri }, forNotifications: true, token)).Count > 0)
|
|
|
|
|
return;
|
2026-10-01 11:32:33 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await DB.Default.SaveAsync(new Notification
|
|
|
|
|
{
|
|
|
|
|
AvatarId = avatarId,
|
|
|
|
|
Type = type,
|
|
|
|
|
FromAccountId = fromAccountId,
|
|
|
|
|
FromActorURI = fromActorUri,
|
|
|
|
|
PostId = postId,
|
|
|
|
|
DedupeKey = $"{type}|{avatarId}|{fromActorUri}|{postId}"
|
|
|
|
|
}, token);
|
|
|
|
|
}
|
|
|
|
|
catch (MongoWriteException ex) when (ex.WriteError?.Category == ServerErrorCategory.DuplicateKey)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|