···
"github.com/bluesky-social/indigo/atproto/syntax"
···
"tangled.org/core/appview/notify"
"tangled.org/core/idresolver"
15
+
"tangled.org/oppi.li/sets"
type databaseNotifier struct {
···
actorDid := syntax.DID(star.Did)
53
-
recipients := []syntax.DID{syntax.DID(repo.Did)}
53
+
recipients := sets.Singleton(syntax.DID(repo.Did))
eventType := models.NotificationTypeRepoStarred
entityId := star.RepoAt.String()
···
func (n *databaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) {
79
-
// build the recipients list
80
-
// - owner of the repo
81
-
// - collaborators in the repo
82
-
var recipients []syntax.DID
83
-
recipients = append(recipients, syntax.DID(issue.Repo.Did))
collaborators, err := db.GetCollaborators(n.db, orm.FilterEq("repo_at", issue.Repo.RepoAt()))
log.Printf("failed to fetch collaborators: %v", err)
84
+
// build the recipients list
85
+
// - owner of the repo
86
+
// - collaborators in the repo
87
+
// - remove users already mentioned
88
+
recipients := sets.Singleton(syntax.DID(issue.Repo.Did))
for _, c := range collaborators {
90
-
recipients = append(recipients, c.SubjectDid)
90
+
recipients.Insert(c.SubjectDid)
92
+
for _, m := range mentions {
93
+
recipients.Remove(m)
actorDid := syntax.DID(issue.Did)
···
115
+
sets.Collect(slices.Values(mentions)),
models.NotificationTypeUserMentioned,
···
134
-
var recipients []syntax.DID
135
-
recipients = append(recipients, syntax.DID(issue.Repo.Did))
137
+
// built the recipients list:
138
+
// - the owner of the repo
139
+
// - | if the comment is a reply -> everybody on that thread
140
+
// | if the comment is a top level -> just the issue owner
141
+
// - remove mentioned users from the recipients list
142
+
recipients := sets.Singleton(syntax.DID(issue.Repo.Did))
// if this comment is a reply, then notify everybody in that thread
parentAtUri := *comment.ReplyTo
140
-
allThreads := issue.CommentList()
// find the parent thread, and add all DIDs from here to the recipient list
143
-
for _, t := range allThreads {
149
+
for _, t := range issue.CommentList() {
if t.Self.AtUri().String() == parentAtUri {
145
-
recipients = append(recipients, t.Participants()...)
151
+
for _, p := range t.Participants() {
152
+
recipients.Insert(p)
// not a reply, notify just the issue author
150
-
recipients = append(recipients, syntax.DID(issue.Did))
158
+
recipients.Insert(syntax.DID(issue.Did))
161
+
for _, m := range mentions {
162
+
recipients.Remove(m)
actorDid := syntax.DID(comment.Did)
···
184
+
sets.Collect(slices.Values(mentions)),
models.NotificationTypeUserMentioned,
···
func (n *databaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {
actorDid := syntax.DID(follow.UserDid)
188
-
recipients := []syntax.DID{syntax.DID(follow.SubjectDid)}
200
+
recipients := sets.Singleton(syntax.DID(follow.SubjectDid))
eventType := models.NotificationTypeFollowed
entityId := follow.UserDid
···
log.Printf("NewPull: failed to get repos: %v", err)
217
-
// build the recipients list
218
-
// - owner of the repo
219
-
// - collaborators in the repo
220
-
var recipients []syntax.DID
221
-
recipients = append(recipients, syntax.DID(repo.Did))
collaborators, err := db.GetCollaborators(n.db, orm.FilterEq("repo_at", repo.RepoAt()))
log.Printf("failed to fetch collaborators: %v", err)
234
+
// build the recipients list
235
+
// - owner of the repo
236
+
// - collaborators in the repo
237
+
recipients := sets.Singleton(syntax.DID(repo.Did))
for _, c := range collaborators {
228
-
recipients = append(recipients, c.SubjectDid)
239
+
recipients.Insert(c.SubjectDid)
actorDid := syntax.DID(pull.OwnerDid)
···
// build up the recipients list:
// - all pull participants
271
-
var recipients []syntax.DID
272
-
recipients = append(recipients, syntax.DID(repo.Did))
282
+
// - remove those already mentioned
283
+
recipients := sets.Singleton(syntax.DID(repo.Did))
for _, p := range pull.Participants() {
274
-
recipients = append(recipients, syntax.DID(p))
285
+
recipients.Insert(syntax.DID(p))
287
+
for _, m := range mentions {
288
+
recipients.Remove(m)
actorDid := syntax.DID(comment.OwnerDid)
···
312
+
sets.Collect(slices.Values(mentions)),
models.NotificationTypeUserMentioned,
···
func (n *databaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {
325
-
// build up the recipients list:
327
-
// - repo collaborators
328
-
// - all issue participants
329
-
var recipients []syntax.DID
330
-
recipients = append(recipients, syntax.DID(issue.Repo.Did))
collaborators, err := db.GetCollaborators(n.db, orm.FilterEq("repo_at", issue.Repo.RepoAt()))
log.Printf("failed to fetch collaborators: %v", err)
345
+
// build up the recipients list:
347
+
// - repo collaborators
348
+
// - all issue participants
349
+
recipients := sets.Singleton(syntax.DID(issue.Repo.Did))
for _, c := range collaborators {
337
-
recipients = append(recipients, c.SubjectDid)
351
+
recipients.Insert(c.SubjectDid)
for _, p := range issue.Participants() {
340
-
recipients = append(recipients, syntax.DID(p))
354
+
recipients.Insert(syntax.DID(p))
···
376
-
// build up the recipients list:
378
-
// - all pull participants
379
-
var recipients []syntax.DID
380
-
recipients = append(recipients, syntax.DID(repo.Did))
collaborators, err := db.GetCollaborators(n.db, orm.FilterEq("repo_at", repo.RepoAt()))
log.Printf("failed to fetch collaborators: %v", err)
396
+
// build up the recipients list:
398
+
// - all pull participants
399
+
recipients := sets.Singleton(syntax.DID(repo.Did))
for _, c := range collaborators {
387
-
recipients = append(recipients, c.SubjectDid)
401
+
recipients.Insert(c.SubjectDid)
for _, p := range pull.Participants() {
390
-
recipients = append(recipients, syntax.DID(p))
404
+
recipients.Insert(syntax.DID(p))
···
func (n *databaseNotifier) notifyEvent(
426
-
recipients []syntax.DID,
440
+
recipients sets.Set[syntax.DID],
eventType models.NotificationType,
···
434
-
if eventType == models.NotificationTypeUserMentioned && len(recipients) > maxMentions {
435
-
recipients = recipients[:maxMentions]
448
+
// if the user is attempting to mention >maxMentions users, this is probably spam, do not mention anybody
449
+
if eventType == models.NotificationTypeUserMentioned && recipients.Len() > maxMentions {
437
-
recipientSet := make(map[syntax.DID]struct{})
438
-
for _, did := range recipients {
439
-
// everybody except actor themselves
440
-
if did != actorDid {
441
-
recipientSet[did] = struct{}{}
453
+
recipients.Remove(actorDid)
prefMap, err := db.GetNotificationPreferences(
447
-
orm.FilterIn("user_did", slices.Collect(maps.Keys(recipientSet))),
457
+
orm.FilterIn("user_did", slices.Collect(recipients.All())),
// failed to get prefs for users
···
// filter based on preferences
463
-
for recipientDid := range recipientSet {
473
+
for recipientDid := range recipients.All() {
prefs, ok := prefMap[recipientDid]
prefs = models.DefaultNotificationPreferences(recipientDid)