Fix notification triggering (#898)

This commit is contained in:
InfiniteStash
2025-01-08 21:38:36 +01:00
committed by GitHub
parent 6dbce6108c
commit c8e7714a12
5 changed files with 37 additions and 18 deletions

View File

@@ -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"
)
@@ -34,6 +35,7 @@ func main() {
user.CreateSystemUsers(txnMgr.Repo(context.Background()))
api.Start(txnMgr, ui)
cron.Init(txnMgr)
notifications.Init(txnMgr)
image.InitResizer()

View File

@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

View File

@@ -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"
)
@@ -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

View File

@@ -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
@@ -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

View File

@@ -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() {
@@ -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)
@@ -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)
}