Monorepo for Tangled
at df9dddd24e954f28be6151ec9c4a5b4726e7eabf 107 lines 3.5 kB view raw
1package notify 2 3import ( 4 "context" 5 "sync" 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 8 "tangled.org/core/appview/models" 9) 10 11type mergedNotifier struct { 12 notifiers []Notifier 13} 14 15func NewMergedNotifier(notifiers []Notifier) Notifier { 16 return &mergedNotifier{notifiers} 17} 18 19var _ Notifier = &mergedNotifier{} 20 21// fanout calls the same method on all notifiers concurrently 22func (m *mergedNotifier) fanout(callback func(Notifier)) { 23 var wg sync.WaitGroup 24 for _, n := range m.notifiers { 25 wg.Add(1) 26 go func(notifier Notifier) { 27 defer wg.Done() 28 callback(n) 29 }(n) 30 } 31} 32 33func (m *mergedNotifier) NewRepo(ctx context.Context, repo *models.Repo) { 34 m.fanout(func(n Notifier) { n.NewRepo(ctx, repo) }) 35} 36 37func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) { 38 m.fanout(func(n Notifier) { n.NewStar(ctx, star) }) 39} 40 41func (m *mergedNotifier) DeleteStar(ctx context.Context, star *models.Star) { 42 m.fanout(func(n Notifier) { n.DeleteStar(ctx, star) }) 43} 44 45func (m *mergedNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { 46 m.fanout(func(n Notifier) { n.NewIssue(ctx, issue, mentions) }) 47} 48 49func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) { 50 m.fanout(func(n Notifier) { n.NewIssueComment(ctx, comment, mentions) }) 51} 52 53func (m *mergedNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 54 m.fanout(func(n Notifier) { n.NewIssueState(ctx, actor, issue) }) 55} 56 57func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { 58 m.fanout(func(n Notifier) { n.DeleteIssue(ctx, issue) }) 59} 60 61func (m *mergedNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) { 62 m.fanout(func(n Notifier) { n.NewIssueLabelOp(ctx, issue) }) 63} 64 65func (m *mergedNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) { 66 m.fanout(func(n Notifier) { n.NewPullLabelOp(ctx, pull) }) 67} 68 69func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 70 m.fanout(func(n Notifier) { n.NewFollow(ctx, follow) }) 71} 72 73func (m *mergedNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) { 74 m.fanout(func(n Notifier) { n.DeleteFollow(ctx, follow) }) 75} 76 77func (m *mergedNotifier) NewPull(ctx context.Context, pull *models.Pull) { 78 m.fanout(func(n Notifier) { n.NewPull(ctx, pull) }) 79} 80 81func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) { 82 m.fanout(func(n Notifier) { n.NewPullComment(ctx, comment, mentions) }) 83} 84 85func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 86 m.fanout(func(n Notifier) { n.NewPullState(ctx, actor, pull) }) 87} 88 89func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { 90 m.fanout(func(n Notifier) { n.UpdateProfile(ctx, profile) }) 91} 92 93func (m *mergedNotifier) NewString(ctx context.Context, s *models.String) { 94 m.fanout(func(n Notifier) { n.NewString(ctx, s) }) 95} 96 97func (m *mergedNotifier) EditString(ctx context.Context, s *models.String) { 98 m.fanout(func(n Notifier) { n.EditString(ctx, s) }) 99} 100 101func (m *mergedNotifier) DeleteString(ctx context.Context, did, rkey string) { 102 m.fanout(func(n Notifier) { n.DeleteString(ctx, did, rkey) }) 103} 104 105func (m *mergedNotifier) Push(ctx context.Context, repo *models.Repo, ref, oldSha, newSha, committerDid string) { 106 m.fanout(func(n Notifier) { n.Push(ctx, repo, ref, oldSha, newSha, committerDid) }) 107}