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) { if (string.IsNullOrEmpty(avatarId) || avatarId == fromAccountId) return; 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) { } } } }