Skip to content

Commit

Permalink
Fix notification triggering (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash authored Jan 8, 2025
1 parent 6dbce61 commit c8e7714
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stashapp/stash-box/pkg/manager"
"github.com/stashapp/stash-box/pkg/manager/config"
"github.com/stashapp/stash-box/pkg/manager/cron"
"github.com/stashapp/stash-box/pkg/manager/notifications"
"github.com/stashapp/stash-box/pkg/sqlx"
"github.com/stashapp/stash-box/pkg/user"
)
Expand All @@ -34,6 +35,7 @@ func main() {
user.CreateSystemUsers(txnMgr.Repo(context.Background()))
api.Start(txnMgr, ui)
cron.Init(txnMgr)
notifications.Init(txnMgr)

image.InitResizer()

Expand Down
20 changes: 10 additions & 10 deletions pkg/api/resolver_mutation_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *mutationResolver) SceneEdit(ctx context.Context, input models.SceneEdit
})

if err == nil {
go notifications.OnCreateEdit(fac, newEdit)
go notifications.OnCreateEdit(newEdit)
}

return newEdit, err
Expand Down Expand Up @@ -108,7 +108,7 @@ func (r *mutationResolver) SceneEditUpdate(ctx context.Context, id uuid.UUID, in
})

if err == nil {
go notifications.OnUpdateEdit(fac, existingEdit)
go notifications.OnUpdateEdit(existingEdit)
}

return existingEdit, err
Expand Down Expand Up @@ -149,7 +149,7 @@ func (r *mutationResolver) StudioEdit(ctx context.Context, input models.StudioEd
})

if err == nil {
go notifications.OnCreateEdit(fac, newEdit)
go notifications.OnCreateEdit(newEdit)
}

return newEdit, err
Expand Down Expand Up @@ -185,7 +185,7 @@ func (r *mutationResolver) StudioEditUpdate(ctx context.Context, id uuid.UUID, i
})

if err == nil {
go notifications.OnUpdateEdit(fac, existingEdit)
go notifications.OnUpdateEdit(existingEdit)
}

return existingEdit, err
Expand Down Expand Up @@ -226,7 +226,7 @@ func (r *mutationResolver) TagEdit(ctx context.Context, input models.TagEditInpu
})

if err == nil {
go notifications.OnCreateEdit(fac, newEdit)
go notifications.OnCreateEdit(newEdit)
}

return newEdit, err
Expand Down Expand Up @@ -262,7 +262,7 @@ func (r *mutationResolver) TagEditUpdate(ctx context.Context, id uuid.UUID, inpu
})

if err == nil {
go notifications.OnUpdateEdit(fac, existingEdit)
go notifications.OnUpdateEdit(existingEdit)
}

return existingEdit, err
Expand Down Expand Up @@ -309,7 +309,7 @@ func (r *mutationResolver) PerformerEdit(ctx context.Context, input models.Perfo
})

if err == nil {
go notifications.OnCreateEdit(fac, newEdit)
go notifications.OnCreateEdit(newEdit)
}

return newEdit, err
Expand Down Expand Up @@ -345,7 +345,7 @@ func (r *mutationResolver) PerformerEditUpdate(ctx context.Context, id uuid.UUID
})

if err == nil {
go notifications.OnUpdateEdit(fac, existingEdit)
go notifications.OnUpdateEdit(existingEdit)
}

return existingEdit, err
Expand Down Expand Up @@ -395,7 +395,7 @@ func (r *mutationResolver) EditVote(ctx context.Context, input models.EditVoteIn
})

if err == nil && input.Vote == models.VoteTypeEnumReject {
go notifications.OnEditDownvote(fac, voteEdit)
go notifications.OnEditDownvote(voteEdit)
}

return voteEdit, err
Expand All @@ -421,7 +421,7 @@ func (r *mutationResolver) EditComment(ctx context.Context, input models.EditCom
})

if err == nil {
go notifications.OnEditComment(fac, comment)
go notifications.OnEditComment(comment)
}

return edit, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/database/databasetest/database_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jmoiron/sqlx"

"github.com/stashapp/stash-box/pkg/database"
"github.com/stashapp/stash-box/pkg/manager/notifications"
"github.com/stashapp/stash-box/pkg/models"
sqlxx "github.com/stashapp/stash-box/pkg/sqlx"
)
Expand Down Expand Up @@ -60,6 +61,7 @@ func initPostgres(connString string) func() {

db = database.Initialize(databaseType, connString)
txnMgr := sqlxx.NewTxnMgr(db)
notifications.Init(txnMgr)
repo = txnMgr.Repo(context.TODO())

return teardownPostgres
Expand Down
4 changes: 2 additions & 2 deletions pkg/manager/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func ApplyEdit(fac models.Repo, editID uuid.UUID, immediate bool) (*models.Edit,
})

if err == nil {
go notifications.OnApplyEdit(fac, updatedEdit)
go notifications.OnApplyEdit(updatedEdit)
}

return updatedEdit, err
Expand Down Expand Up @@ -197,7 +197,7 @@ func CloseEdit(fac models.Repo, editID uuid.UUID, status models.VoteStatusEnum)
})

if err == nil && status != models.VoteStatusEnumCanceled {
go notifications.OnCancelEdit(fac, updatedEdit)
go notifications.OnCancelEdit(updatedEdit)
}

return updatedEdit, err
Expand Down
27 changes: 21 additions & 6 deletions pkg/manager/notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
package notifications

import (
"context"

"github.com/stashapp/stash-box/pkg/models"
"github.com/stashapp/stash-box/pkg/sqlx"
)

func OnApplyEdit(fac models.Repo, edit *models.Edit) {
var rfp *sqlx.TxnMgr

func Init(txnMgr *sqlx.TxnMgr) {
rfp = txnMgr
}

func OnApplyEdit(edit *models.Edit) {
fac := rfp.Repo(context.Background())
nqb := fac.Notification()
eqb := fac.Edit()
if (edit.Status == models.VoteStatusEnumAccepted.String() || edit.Status == models.VoteStatusEnumImmediateAccepted.String()) && edit.Operation == models.OperationEnumCreate.String() {
Expand All @@ -22,11 +32,13 @@ func OnApplyEdit(fac models.Repo, edit *models.Edit) {
}
}

func OnCancelEdit(fac models.Repo, edit *models.Edit) {
func OnCancelEdit(edit *models.Edit) {
fac := rfp.Repo(context.Background())
fac.Notification().TriggerFailedEditNotifications(edit.ID)
}

func OnCreateEdit(fac models.Repo, edit *models.Edit) {
func OnCreateEdit(edit *models.Edit) {
fac := rfp.Repo(context.Background())
switch edit.TargetType {
case models.TargetTypeEnumPerformer.String():
fac.Notification().TriggerPerformerEditNotifications(edit.ID)
Expand All @@ -37,15 +49,18 @@ func OnCreateEdit(fac models.Repo, edit *models.Edit) {
}
}

func OnUpdateEdit(fac models.Repo, edit *models.Edit) {
func OnUpdateEdit(edit *models.Edit) {
fac := rfp.Repo(context.Background())
fac.Notification().TriggerUpdatedEditNotifications(edit.ID)
}

func OnEditDownvote(fac models.Repo, edit *models.Edit) {
func OnEditDownvote(edit *models.Edit) {
fac := rfp.Repo(context.Background())
fac.Notification().TriggerDownvoteEditNotifications(edit.ID)
}

func OnEditComment(fac models.Repo, comment *models.EditComment) {
func OnEditComment(comment *models.EditComment) {
fac := rfp.Repo(context.Background())
fac.Notification().TriggerEditCommentNotifications(comment.ID)
}

Expand Down

0 comments on commit c8e7714

Please sign in to comment.