Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
3.1 kB · 107 lines
Go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108package notify
import ( "context" "log/slog" "reflect" "sync"
"github.com/bluesky-social/indigo/atproto/syntax" "tangled.org/core/appview/models" "tangled.org/core/log")
type mergedNotifier struct { notifiers []Notifier logger *slog.Logger}
func NewMergedNotifier(notifiers []Notifier, logger *slog.Logger) Notifier { return &mergedNotifier{notifiers, logger}}
var _ Notifier = &mergedNotifier{}
// fanout calls the same method on all notifiers concurrentlyfunc (m *mergedNotifier) fanout(method string, ctx context.Context, args ...any) { ctx = log.IntoContext(ctx, m.logger.With("method", method)) var wg sync.WaitGroup for _, n := range m.notifiers { wg.Add(1) go func(notifier Notifier) { defer wg.Done() v := reflect.ValueOf(notifier).MethodByName(method) in := make([]reflect.Value, len(args)+1) in[0] = reflect.ValueOf(ctx) for i, arg := range args { in[i+1] = reflect.ValueOf(arg) } v.Call(in) }(n) } wg.Wait()}
func (m *mergedNotifier) NewRepo(ctx context.Context, repo *models.Repo) { m.fanout("NewRepo", ctx, repo)}
func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) { m.fanout("NewStar", ctx, star)}
func (m *mergedNotifier) DeleteStar(ctx context.Context, star *models.Star) { m.fanout("DeleteStar", ctx, star)}
func (m *mergedNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { m.fanout("NewIssue", ctx, issue, mentions)}
func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) { m.fanout("NewIssueComment", ctx, comment, mentions)}
func (m *mergedNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { m.fanout("NewIssueState", ctx, actor, issue)}
func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { m.fanout("DeleteIssue", ctx, issue)}
func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { m.fanout("NewFollow", ctx, follow)}
func (m *mergedNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) { m.fanout("DeleteFollow", ctx, follow)}
func (m *mergedNotifier) NewPull(ctx context.Context, pull *models.Pull) { m.fanout("NewPull", ctx, pull)}
func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) { m.fanout("NewPullComment", ctx, comment, mentions)}
func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { m.fanout("NewPullState", ctx, actor, pull)}
func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { m.fanout("UpdateProfile", ctx, profile)}
func (m *mergedNotifier) NewString(ctx context.Context, s *models.String) { m.fanout("NewString", ctx, s)}
func (m *mergedNotifier) EditString(ctx context.Context, s *models.String) { m.fanout("EditString", ctx, s)}
func (m *mergedNotifier) DeleteString(ctx context.Context, did, rkey string) { m.fanout("DeleteString", ctx, did, rkey)}