Monorepo for Tangled tangled.org
1package notify 2 3import ( 4 "context" 5 "reflect" 6 "sync" 7 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(method string, args ...any) { 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 v := reflect.ValueOf(notifier).MethodByName(method) 29 in := make([]reflect.Value, len(args)) 30 for i, arg := range args { 31 in[i] = reflect.ValueOf(arg) 32 } 33 v.Call(in) 34 }(n) 35 } 36 wg.Wait() 37} 38 39func (m *mergedNotifier) NewRepo(ctx context.Context, repo *models.Repo) { 40 m.fanout("NewRepo", ctx, repo) 41} 42 43func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) { 44 m.fanout("NewStar", ctx, star) 45} 46 47func (m *mergedNotifier) DeleteStar(ctx context.Context, star *models.Star) { 48 m.fanout("DeleteStar", ctx, star) 49} 50 51func (m *mergedNotifier) NewIssue(ctx context.Context, issue *models.Issue) { 52 m.fanout("NewIssue", ctx, issue) 53} 54 55func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) { 56 m.fanout("NewIssueComment", ctx, comment) 57} 58 59func (m *mergedNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) { 60 m.fanout("NewIssueClosed", ctx, issue) 61} 62 63func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 64 m.fanout("NewFollow", ctx, follow) 65} 66 67func (m *mergedNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) { 68 m.fanout("DeleteFollow", ctx, follow) 69} 70 71func (m *mergedNotifier) NewPull(ctx context.Context, pull *models.Pull) { 72 m.fanout("NewPull", ctx, pull) 73} 74 75func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) { 76 m.fanout("NewPullComment", ctx, comment) 77} 78 79func (m *mergedNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) { 80 m.fanout("NewPullMerged", ctx, pull) 81} 82 83func (m *mergedNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) { 84 m.fanout("NewPullClosed", ctx, pull) 85} 86 87func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { 88 m.fanout("UpdateProfile", ctx, profile) 89} 90 91func (m *mergedNotifier) NewString(ctx context.Context, s *models.String) { 92 m.fanout("NewString", ctx, s) 93} 94 95func (m *mergedNotifier) EditString(ctx context.Context, s *models.String) { 96 m.fanout("EditString", ctx, s) 97} 98 99func (m *mergedNotifier) DeleteString(ctx context.Context, did, rkey string) { 100 m.fanout("DeleteString", ctx, did, rkey) 101}