appview: wrap posthog under unified notifier #333

merged
opened by boltless.me targeting master from boltless.me/core: push-pslnqmxvulmp
  • Make db.New*() methods to accept complete model object instead of individual fields
  • Remove posthog field from most Service structs. Oauth still has one as an edge-case
  • Add more notifier methods to replace posthog logics

Signed-off-by: Seongmin Lee boltlessengineer@proton.me

+2 -2
appview/db/follow.go
···
Rkey string
}
-
func AddFollow(e Execer, userDid, subjectDid, rkey string) error {
+
func AddFollow(e Execer, follow *Follow) error {
query := `insert or ignore into follows (user_did, subject_did, rkey) values (?, ?, ?)`
-
_, err := e.Exec(query, userDid, subjectDid, rkey)
+
_, err := e.Exec(query, follow.UserDid, follow.SubjectDid, follow.Rkey)
return err
}
+7 -2
appview/db/star.go
···
return nil
}
-
func AddStar(e Execer, starredByDid string, repoAt syntax.ATURI, rkey string) error {
+
func AddStar(e Execer, star *Star) error {
query := `insert or ignore into stars (starred_by_did, repo_at, rkey) values (?, ?, ?)`
-
_, err := e.Exec(query, starredByDid, repoAt, rkey)
+
_, err := e.Exec(
+
query,
+
star.StarredByDid,
+
star.RepoAt.String(),
+
star.Rkey,
+
)
return err
}
+10 -3
appview/ingester.go
···
l.Error("invalid record", "err", err)
return err
}
-
err = db.AddStar(i.Db, did, subjectUri, e.Commit.RKey)
+
err = db.AddStar(i.Db, &db.Star{
+
StarredByDid: did,
+
RepoAt: subjectUri,
+
Rkey: e.Commit.RKey,
+
})
case models.CommitOperationDelete:
err = db.DeleteStarByRkey(i.Db, did, e.Commit.RKey)
}
···
return err
}
-
subjectDid := record.Subject
-
err = db.AddFollow(i.Db, did, subjectDid, e.Commit.RKey)
+
err = db.AddFollow(i.Db, &db.Follow{
+
UserDid: did,
+
SubjectDid: record.Subject,
+
Rkey: e.Commit.RKey,
+
})
case models.CommitOperationDelete:
err = db.DeleteFollowByRkey(i.Db, did, e.Commit.RKey)
}
+5 -14
appview/issues/issues.go
···
"github.com/bluesky-social/indigo/atproto/syntax"
lexutil "github.com/bluesky-social/indigo/lex/util"
"github.com/go-chi/chi/v5"
-
"github.com/posthog/posthog-go"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview"
"tangled.sh/tangled.sh/core/appview/config"
"tangled.sh/tangled.sh/core/appview/db"
"tangled.sh/tangled.sh/core/appview/idresolver"
+
"tangled.sh/tangled.sh/core/appview/notify"
"tangled.sh/tangled.sh/core/appview/oauth"
"tangled.sh/tangled.sh/core/appview/pages"
"tangled.sh/tangled.sh/core/appview/pagination"
···
idResolver *idresolver.Resolver
db *db.DB
config *config.Config
-
posthog posthog.Client
+
notifier notify.Notifier
}
func New(
···
idResolver *idresolver.Resolver,
db *db.DB,
config *config.Config,
-
posthog posthog.Client,
+
notifier notify.Notifier,
) *Issues {
return &Issues{
oauth: oauth,
···
idResolver: idResolver,
db: db,
config: config,
-
posthog: posthog,
+
notifier: notifier,
}
}
···
return
}
-
if !rp.config.Core.Dev {
-
err = rp.posthog.Enqueue(posthog.Capture{
-
DistinctId: user.Did,
-
Event: "new_issue",
-
Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issue.IssueId},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
+
rp.notifier.NewIssue(r.Context(), issue)
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId))
return
+37 -6
appview/notify/merged_notifier.go
···
}
func NewMergedNotifier(notifiers ...Notifier) Notifier {
-
return &mergedNotifier{
-
notifiers,
-
}
+
return &mergedNotifier{notifiers}
}
var _ Notifier = &mergedNotifier{}
+
func (m *mergedNotifier) NewRepo(ctx context.Context, repo *db.Repo) {
+
for _, notifier := range m.notifiers {
+
notifier.NewRepo(ctx, repo)
+
}
+
}
+
+
func (m *mergedNotifier) NewStar(ctx context.Context, star *db.Star) {
+
for _, notifier := range m.notifiers {
+
notifier.NewStar(ctx, star)
+
}
+
}
+
func (m *mergedNotifier) DeleteStar(ctx context.Context, star *db.Star) {
+
for _, notifier := range m.notifiers {
+
notifier.DeleteStar(ctx, star)
+
}
+
}
+
func (m *mergedNotifier) NewIssue(ctx context.Context, issue *db.Issue) {
for _, notifier := range m.notifiers {
notifier.NewIssue(ctx, issue)
}
}
-
func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment db.Comment) {
+
func (m *mergedNotifier) NewFollow(ctx context.Context, follow *db.Follow) {
+
for _, notifier := range m.notifiers {
+
notifier.NewFollow(ctx, follow)
+
}
+
}
+
func (m *mergedNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {
for _, notifier := range m.notifiers {
-
notifier.NewIssueComment(ctx, comment)
+
notifier.DeleteFollow(ctx, follow)
}
}
-
func (m *mergedNotifier) NewPullComment(ctx context.Context, comment db.PullComment) {
+
func (m *mergedNotifier) NewPull(ctx context.Context, pull *db.Pull) {
+
for _, notifier := range m.notifiers {
+
notifier.NewPull(ctx, pull)
+
}
+
}
+
func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {
for _, notifier := range m.notifiers {
notifier.NewPullComment(ctx, comment)
}
}
+
+
func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {
+
for _, notifier := range m.notifiers {
+
notifier.UpdateProfile(ctx, profile)
+
}
+
}
+32 -2
appview/notify/notifier.go
···
)
type Notifier interface {
+
NewRepo(ctx context.Context, repo *db.Repo)
+
+
NewStar(ctx context.Context, star *db.Star)
+
DeleteStar(ctx context.Context, star *db.Star)
+
NewIssue(ctx context.Context, issue *db.Issue)
-
NewIssueComment(ctx context.Context, comment db.Comment)
-
NewPullComment(ctx context.Context, comment db.PullComment)
+
NewFollow(ctx context.Context, follow *db.Follow)
+
DeleteFollow(ctx context.Context, follow *db.Follow)
+
+
NewPull(ctx context.Context, pull *db.Pull)
+
NewPullComment(ctx context.Context, comment *db.PullComment)
+
+
UpdateProfile(ctx context.Context, profile *db.Profile)
}
+
+
// BaseNotifier is a listener that does nothing
+
type BaseNotifier struct{}
+
+
var _ Notifier = &BaseNotifier{}
+
+
func (m *BaseNotifier) NewRepo(ctx context.Context, repo *db.Repo) {}
+
+
func (m *BaseNotifier) NewStar(ctx context.Context, star *db.Star) {}
+
func (m *BaseNotifier) DeleteStar(ctx context.Context, star *db.Star) {}
+
+
func (m *BaseNotifier) NewIssue(ctx context.Context, issue *db.Issue) {}
+
+
func (m *BaseNotifier) NewFollow(ctx context.Context, follow *db.Follow) {}
+
func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {}
+
+
func (m *BaseNotifier) NewPull(ctx context.Context, pull *db.Pull) {}
+
func (m *BaseNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {}
+
+
func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {}
-4
appview/pipelines/pipelines.go
···
"github.com/go-chi/chi/v5"
"github.com/gorilla/websocket"
-
"github.com/posthog/posthog-go"
)
type Pipelines struct {
···
spindlestream *eventconsumer.Consumer
db *db.DB
enforcer *rbac.Enforcer
-
posthog posthog.Client
logger *slog.Logger
}
···
idResolver *idresolver.Resolver,
db *db.DB,
config *config.Config,
-
posthog posthog.Client,
enforcer *rbac.Enforcer,
) *Pipelines {
logger := log.New("pipelines")
···
config: config,
spindlestream: spindlestream,
db: db,
-
posthog: posthog,
enforcer: enforcer,
logger: logger,
}
+131
appview/posthog/notifier.go
···
+
package posthog_service
+
+
import (
+
"context"
+
"log"
+
+
"github.com/posthog/posthog-go"
+
"tangled.sh/tangled.sh/core/appview/db"
+
"tangled.sh/tangled.sh/core/appview/notify"
+
)
+
+
type posthogNotifier struct {
+
client posthog.Client
+
notify.BaseNotifier
+
}
+
+
func NewPosthogNotifier(client posthog.Client) notify.Notifier {
+
return &posthogNotifier{
+
client,
+
notify.BaseNotifier{},
+
}
+
}
+
+
var _ notify.Notifier = &posthogNotifier{}
+
+
func (n *posthogNotifier) NewRepo(ctx context.Context, repo *db.Repo) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: repo.Did,
+
Event: "new_repo",
+
Properties: posthog.Properties{"repo": repo.Name, "repo_at": repo.RepoAt()},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewStar(ctx context.Context, star *db.Star) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: star.StarredByDid,
+
Event: "star",
+
Properties: posthog.Properties{"repo_at": star.RepoAt.String()},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) DeleteStar(ctx context.Context, star *db.Star) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: star.StarredByDid,
+
Event: "unstar",
+
Properties: posthog.Properties{"repo_at": star.RepoAt.String()},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewIssue(ctx context.Context, issue *db.Issue) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: issue.OwnerDid,
+
Event: "new_issue",
+
Properties: posthog.Properties{
+
"repo_at": issue.RepoAt.String(),
+
"issue_id": issue.IssueId,
+
},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewPull(ctx context.Context, pull *db.Pull) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: pull.OwnerDid,
+
Event: "new_pull",
+
Properties: posthog.Properties{
+
"repo_at": pull.RepoAt,
+
"pull_id": pull.PullId,
+
},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: comment.OwnerDid,
+
Event: "new_pull_comment",
+
Properties: posthog.Properties{
+
"repo_at": comment.RepoAt,
+
"pull_id": comment.PullId,
+
},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewFollow(ctx context.Context, follow *db.Follow) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: follow.UserDid,
+
Event: "follow",
+
Properties: posthog.Properties{"subject": follow.SubjectDid},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: follow.UserDid,
+
Event: "unfollow",
+
Properties: posthog.Properties{"subject": follow.SubjectDid},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: profile.Did,
+
Event: "edit_profile",
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+14 -29
appview/pulls/pulls.go
···
"tangled.sh/tangled.sh/core/appview/config"
"tangled.sh/tangled.sh/core/appview/db"
"tangled.sh/tangled.sh/core/appview/idresolver"
+
"tangled.sh/tangled.sh/core/appview/notify"
"tangled.sh/tangled.sh/core/appview/oauth"
"tangled.sh/tangled.sh/core/appview/pages"
"tangled.sh/tangled.sh/core/appview/reporesolver"
···
lexutil "github.com/bluesky-social/indigo/lex/util"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
-
"github.com/posthog/posthog-go"
)
type Pulls struct {
···
idResolver *idresolver.Resolver
db *db.DB
config *config.Config
-
posthog posthog.Client
+
notifier notify.Notifier
}
func New(
···
resolver *idresolver.Resolver,
db *db.DB,
config *config.Config,
-
posthog posthog.Client,
+
notifier notify.Notifier,
) *Pulls {
return &Pulls{
oauth: oauth,
···
idResolver: resolver,
db: db,
config: config,
-
posthog: posthog,
+
notifier: notifier,
}
}
···
return
}
-
// Create the pull comment in the database with the commentAt field
-
commentId, err := db.NewPullComment(tx, &db.PullComment{
+
comment := &db.PullComment{
OwnerDid: user.Did,
RepoAt: f.RepoAt.String(),
PullId: pull.PullId,
Body: body,
CommentAt: atResp.Uri,
SubmissionId: pull.Submissions[roundNumber].ID,
-
})
+
}
+
+
// Create the pull comment in the database with the commentAt field
+
commentId, err := db.NewPullComment(tx, comment)
if err != nil {
log.Println("failed to create pull comment", err)
s.pages.Notice(w, "pull-comment", "Failed to create comment.")
···
return
}
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: user.Did,
-
Event: "new_pull_comment",
-
Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "pull_id": pull.PullId},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
+
s.notifier.NewPullComment(r.Context(), comment)
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", f.OwnerSlashRepo(), pull.PullId, commentId))
return
···
Patch: patch,
SourceRev: sourceRev,
-
err = db.NewPull(tx, &db.Pull{
+
pull := &db.Pull{
Title: title,
Body: body,
TargetBranch: targetBranch,
···
&initialSubmission,
},
PullSource: pullSource,
-
})
+
}
+
err = db.NewPull(tx, pull)
if err != nil {
log.Println("failed to create pull request", err)
s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.")
···
return
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: user.Did,
-
Event: "new_pull",
-
Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "pull_id": pullId},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
+
s.notifier.NewPull(r.Context(), pull)
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId))
+4 -4
appview/repo/repo.go
···
"tangled.sh/tangled.sh/core/appview/config"
"tangled.sh/tangled.sh/core/appview/db"
"tangled.sh/tangled.sh/core/appview/idresolver"
+
"tangled.sh/tangled.sh/core/appview/notify"
"tangled.sh/tangled.sh/core/appview/oauth"
"tangled.sh/tangled.sh/core/appview/pages"
"tangled.sh/tangled.sh/core/appview/pages/markup"
···
securejoin "github.com/cyphar/filepath-securejoin"
"github.com/go-chi/chi/v5"
"github.com/go-git/go-git/v5/plumbing"
-
"github.com/posthog/posthog-go"
comatproto "github.com/bluesky-social/indigo/api/atproto"
lexutil "github.com/bluesky-social/indigo/lex/util"
···
spindlestream *eventconsumer.Consumer
db *db.DB
enforcer *rbac.Enforcer
-
posthog posthog.Client
+
notifier notify.Notifier
}
func New(
···
idResolver *idresolver.Resolver,
db *db.DB,
config *config.Config,
-
posthog posthog.Client,
+
notifier notify.Notifier,
enforcer *rbac.Enforcer,
) *Repo {
return &Repo{oauth: oauth,
···
config: config,
spindlestream: spindlestream,
db: db,
-
posthog: posthog,
+
notifier: notifier,
enforcer: enforcer,
}
}
+11 -24
appview/state/follow.go
···
comatproto "github.com/bluesky-social/indigo/api/atproto"
lexutil "github.com/bluesky-social/indigo/lex/util"
-
"github.com/posthog/posthog-go"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview"
"tangled.sh/tangled.sh/core/appview/db"
···
return
}
-
err = db.AddFollow(s.db, currentUser.Did, subjectIdent.DID.String(), rkey)
+
log.Println("created atproto record: ", resp.Uri)
+
+
follow := &db.Follow{
+
UserDid: currentUser.Did,
+
SubjectDid: subjectIdent.DID.String(),
+
Rkey: rkey,
+
}
+
+
err = db.AddFollow(s.db, follow)
if err != nil {
log.Println("failed to follow", err)
return
}
-
log.Println("created atproto record: ", resp.Uri)
+
s.notifier.NewFollow(r.Context(), follow)
s.pages.FollowFragment(w, pages.FollowFragmentParams{
UserDid: subjectIdent.DID.String(),
FollowStatus: db.IsFollowing,
})
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: currentUser.Did,
-
Event: "follow",
-
Properties: posthog.Properties{"subject": subjectIdent.DID.String()},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
return
case http.MethodDelete:
// find the record in the db
···
FollowStatus: db.IsNotFollowing,
})
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: currentUser.Did,
-
Event: "unfollow",
-
Properties: posthog.Properties{"subject": subjectIdent.DID.String()},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
+
s.notifier.DeleteFollow(r.Context(), follow)
return
}
+1 -10
appview/state/profile.go
···
"github.com/bluesky-social/indigo/atproto/syntax"
lexutil "github.com/bluesky-social/indigo/lex/util"
"github.com/go-chi/chi/v5"
-
"github.com/posthog/posthog-go"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview/db"
"tangled.sh/tangled.sh/core/appview/pages"
···
return
}
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: user.Did,
-
Event: "edit_profile",
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
+
s.notifier.UpdateProfile(r.Context(), profile)
s.pages.HxRedirect(w, "/"+user.Did)
return
+4 -4
appview/state/router.go
···
}
func (s *State) IssuesRouter(mw *middleware.Middleware) http.Handler {
-
issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog)
+
issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.notifier)
return issues.Router(mw)
}
func (s *State) PullsRouter(mw *middleware.Middleware) http.Handler {
-
pulls := pulls.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog)
+
pulls := pulls.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.notifier)
return pulls.Router(mw)
}
func (s *State) RepoRouter(mw *middleware.Middleware) http.Handler {
-
repo := repo.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.posthog, s.enforcer)
+
repo := repo.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.notifier, s.enforcer)
return repo.Router(mw)
}
func (s *State) PipelinesRouter(mw *middleware.Middleware) http.Handler {
-
pipes := pipelines.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.posthog, s.enforcer)
+
pipes := pipelines.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.enforcer)
return pipes.Router(mw)
}
+11 -25
appview/state/star.go
···
comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/atproto/syntax"
lexutil "github.com/bluesky-social/indigo/lex/util"
-
"github.com/posthog/posthog-go"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview"
"tangled.sh/tangled.sh/core/appview/db"
···
log.Println("failed to create atproto record", err)
return
}
+
log.Println("created atproto record: ", resp.Uri)
+
+
star := &db.Star{
+
StarredByDid: currentUser.Did,
+
RepoAt: subjectUri,
+
Rkey: rkey,
+
}
-
err = db.AddStar(s.db, currentUser.Did, subjectUri, rkey)
+
err = db.AddStar(s.db, star)
if err != nil {
log.Println("failed to star", err)
return
···
log.Println("failed to get star count for ", subjectUri)
}
-
log.Println("created atproto record: ", resp.Uri)
+
s.notifier.NewStar(r.Context(), star)
s.pages.RepoActionsFragment(w, pages.RepoActionsFragmentParams{
IsStarred: true,
···
},
})
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: currentUser.Did,
-
Event: "star",
-
Properties: posthog.Properties{"repo_at": subjectUri.String()},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
return
case http.MethodDelete:
// find the record in the db
···
return
}
+
s.notifier.DeleteStar(r.Context(), star)
+
s.pages.RepoActionsFragment(w, pages.RepoActionsFragmentParams{
IsStarred: false,
RepoAt: subjectUri,
···
},
})
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: currentUser.Did,
-
Event: "unstar",
-
Properties: posthog.Properties{"repo_at": subjectUri.String()},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
return
}
+3 -10
appview/state/state.go
···
"tangled.sh/tangled.sh/core/appview/notify"
"tangled.sh/tangled.sh/core/appview/oauth"
"tangled.sh/tangled.sh/core/appview/pages"
+
posthog_service "tangled.sh/tangled.sh/core/appview/posthog"
"tangled.sh/tangled.sh/core/appview/reporesolver"
"tangled.sh/tangled.sh/core/eventconsumer"
"tangled.sh/tangled.sh/core/jetstream"
···
spindlestream.Start(ctx)
notifier := notify.NewMergedNotifier(
+
posthog_service.NewPosthogNotifier(posthog),
)
state := &State{
···
return
}
-
if !s.config.Core.Dev {
-
err = s.posthog.Enqueue(posthog.Capture{
-
DistinctId: user.Did,
-
Event: "new_repo",
-
Properties: posthog.Properties{"repo": repoName, "repo_at": repo.AtUri},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
+
s.notifier.NewRepo(r.Context(), repo)
s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s", user.Handle, repoName))
return