Skip to content

Commit 41493dd

Browse files
fix: event emit on envelope drop
1 parent 98b990a commit 41493dd

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

internal/app/app.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,16 @@ func (a App) EnvelopeList(ctx context.Context, page pagination.Page, req models.
214214
}
215215

216216
func (a App) EnvelopeDrop(ctx context.Context) error {
217-
return repo.EnvelopeDrop(ctx, a.db)
217+
count, err := repo.EnvelopeDrop(ctx, a.db)
218+
if err != nil {
219+
return err
220+
}
221+
222+
if count > 0 {
223+
a.bus.EnvelopeDeleted(ctx)
224+
}
225+
226+
return nil
218227
}
219228

220229
func (a App) MessageHTMLGet(ctx context.Context, id int64) (string, error) {
@@ -322,7 +331,7 @@ func (a App) EndpointTest(ctx context.Context, id int64) error {
322331
}
323332
defer file.Close()
324333

325-
datt, err := envelope.NewDataAttachment("apple-touch-icon.png", file)
334+
datt, err := envelope.NewDataAttachment("Test Attachment", file)
326335
if err != nil {
327336
return err
328337
}

internal/repo/envelope.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,16 @@ func EnvelopeDelete(ctx context.Context, db database.Querier, id int64) error {
189189
return oneRowAffected(res)
190190
}
191191

192-
func EnvelopeDrop(ctx context.Context, db database.Querier) error {
193-
_, err := Messages.
192+
func EnvelopeDrop(ctx context.Context, db database.Querier) (int64, error) {
193+
res, err := Messages.
194194
DELETE().
195195
WHERE(RawBool("1=1")).
196196
ExecContext(ctx, db)
197-
return err
197+
if err != nil {
198+
return 0, err
199+
}
200+
201+
return res.RowsAffected()
198202
}
199203

200204
func EnvelopeTrim(ctx context.Context, db database.Querier, age time.Time, keep int) (int64, error) {

0 commit comments

Comments
 (0)