Skip to content

Commit c8e7714

Browse files
Fix notification triggering (#898)
1 parent 6dbce61 commit c8e7714

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/stashapp/stash-box/pkg/manager"
1313
"github.com/stashapp/stash-box/pkg/manager/config"
1414
"github.com/stashapp/stash-box/pkg/manager/cron"
15+
"github.com/stashapp/stash-box/pkg/manager/notifications"
1516
"github.com/stashapp/stash-box/pkg/sqlx"
1617
"github.com/stashapp/stash-box/pkg/user"
1718
)
@@ -34,6 +35,7 @@ func main() {
3435
user.CreateSystemUsers(txnMgr.Repo(context.Background()))
3536
api.Start(txnMgr, ui)
3637
cron.Init(txnMgr)
38+
notifications.Init(txnMgr)
3739

3840
image.InitResizer()
3941

pkg/api/resolver_mutation_edit.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (r *mutationResolver) SceneEdit(ctx context.Context, input models.SceneEdit
7272
})
7373

7474
if err == nil {
75-
go notifications.OnCreateEdit(fac, newEdit)
75+
go notifications.OnCreateEdit(newEdit)
7676
}
7777

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

110110
if err == nil {
111-
go notifications.OnUpdateEdit(fac, existingEdit)
111+
go notifications.OnUpdateEdit(existingEdit)
112112
}
113113

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

151151
if err == nil {
152-
go notifications.OnCreateEdit(fac, newEdit)
152+
go notifications.OnCreateEdit(newEdit)
153153
}
154154

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

187187
if err == nil {
188-
go notifications.OnUpdateEdit(fac, existingEdit)
188+
go notifications.OnUpdateEdit(existingEdit)
189189
}
190190

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

228228
if err == nil {
229-
go notifications.OnCreateEdit(fac, newEdit)
229+
go notifications.OnCreateEdit(newEdit)
230230
}
231231

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

264264
if err == nil {
265-
go notifications.OnUpdateEdit(fac, existingEdit)
265+
go notifications.OnUpdateEdit(existingEdit)
266266
}
267267

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

311311
if err == nil {
312-
go notifications.OnCreateEdit(fac, newEdit)
312+
go notifications.OnCreateEdit(newEdit)
313313
}
314314

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

347347
if err == nil {
348-
go notifications.OnUpdateEdit(fac, existingEdit)
348+
go notifications.OnUpdateEdit(existingEdit)
349349
}
350350

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

397397
if err == nil && input.Vote == models.VoteTypeEnumReject {
398-
go notifications.OnEditDownvote(fac, voteEdit)
398+
go notifications.OnEditDownvote(voteEdit)
399399
}
400400

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

423423
if err == nil {
424-
go notifications.OnEditComment(fac, comment)
424+
go notifications.OnEditComment(comment)
425425
}
426426

427427
return edit, err

pkg/database/databasetest/database_test_utils.go

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/jmoiron/sqlx"
1212

1313
"github.com/stashapp/stash-box/pkg/database"
14+
"github.com/stashapp/stash-box/pkg/manager/notifications"
1415
"github.com/stashapp/stash-box/pkg/models"
1516
sqlxx "github.com/stashapp/stash-box/pkg/sqlx"
1617
)
@@ -60,6 +61,7 @@ func initPostgres(connString string) func() {
6061

6162
db = database.Initialize(databaseType, connString)
6263
txnMgr := sqlxx.NewTxnMgr(db)
64+
notifications.Init(txnMgr)
6365
repo = txnMgr.Repo(context.TODO())
6466

6567
return teardownPostgres

pkg/manager/edit/edit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func ApplyEdit(fac models.Repo, editID uuid.UUID, immediate bool) (*models.Edit,
157157
})
158158

159159
if err == nil {
160-
go notifications.OnApplyEdit(fac, updatedEdit)
160+
go notifications.OnApplyEdit(updatedEdit)
161161
}
162162

163163
return updatedEdit, err
@@ -197,7 +197,7 @@ func CloseEdit(fac models.Repo, editID uuid.UUID, status models.VoteStatusEnum)
197197
})
198198

199199
if err == nil && status != models.VoteStatusEnumCanceled {
200-
go notifications.OnCancelEdit(fac, updatedEdit)
200+
go notifications.OnCancelEdit(updatedEdit)
201201
}
202202

203203
return updatedEdit, err

pkg/manager/notifications/notifications.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
package notifications
33

44
import (
5+
"context"
6+
57
"github.com/stashapp/stash-box/pkg/models"
8+
"github.com/stashapp/stash-box/pkg/sqlx"
69
)
710

8-
func OnApplyEdit(fac models.Repo, edit *models.Edit) {
11+
var rfp *sqlx.TxnMgr
12+
13+
func Init(txnMgr *sqlx.TxnMgr) {
14+
rfp = txnMgr
15+
}
16+
17+
func OnApplyEdit(edit *models.Edit) {
18+
fac := rfp.Repo(context.Background())
919
nqb := fac.Notification()
1020
eqb := fac.Edit()
1121
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) {
2232
}
2333
}
2434

25-
func OnCancelEdit(fac models.Repo, edit *models.Edit) {
35+
func OnCancelEdit(edit *models.Edit) {
36+
fac := rfp.Repo(context.Background())
2637
fac.Notification().TriggerFailedEditNotifications(edit.ID)
2738
}
2839

29-
func OnCreateEdit(fac models.Repo, edit *models.Edit) {
40+
func OnCreateEdit(edit *models.Edit) {
41+
fac := rfp.Repo(context.Background())
3042
switch edit.TargetType {
3143
case models.TargetTypeEnumPerformer.String():
3244
fac.Notification().TriggerPerformerEditNotifications(edit.ID)
@@ -37,15 +49,18 @@ func OnCreateEdit(fac models.Repo, edit *models.Edit) {
3749
}
3850
}
3951

40-
func OnUpdateEdit(fac models.Repo, edit *models.Edit) {
52+
func OnUpdateEdit(edit *models.Edit) {
53+
fac := rfp.Repo(context.Background())
4154
fac.Notification().TriggerUpdatedEditNotifications(edit.ID)
4255
}
4356

44-
func OnEditDownvote(fac models.Repo, edit *models.Edit) {
57+
func OnEditDownvote(edit *models.Edit) {
58+
fac := rfp.Repo(context.Background())
4559
fac.Notification().TriggerDownvoteEditNotifications(edit.ID)
4660
}
4761

48-
func OnEditComment(fac models.Repo, comment *models.EditComment) {
62+
func OnEditComment(comment *models.EditComment) {
63+
fac := rfp.Repo(context.Background())
4964
fac.Notification().TriggerEditCommentNotifications(comment.ID)
5065
}
5166

0 commit comments

Comments
 (0)