From 849499740b9e4ed022e8f162c3ecb50cd4814bb9 Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Mon, 17 Jun 2024 00:33:10 +0200 Subject: [PATCH] feat(messages): update messages to handle multiple recipients --- messages/main.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/messages/main.go b/messages/main.go index 1ac790d..e947c54 100644 --- a/messages/main.go +++ b/messages/main.go @@ -90,12 +90,12 @@ func InitMessages(app *pocketbase.PocketBase, e *core.ServeEvent) error { } // expand the createdMessageRecord to get recipient user and send email notification if recipient is set - if errs := app.Dao().ExpandRecord(createdMessageRecord, []string{"recipient", "eventList"}, nil); len(errs) > 0 { + if errs := app.Dao().ExpandRecord(createdMessageRecord, []string{"recipients", "eventList"}, nil); len(errs) > 0 { // return new error with all errors return fmt.Errorf("error expanding created message record: %v", errs) } - recipient := createdMessageRecord.ExpandedOne("recipient") - if recipient != nil { + recipients := createdMessageRecord.ExpandedAll("recipients") + for _, recipient := range recipients { go sendEmailNotification(app, registry, recipient, createdMessageRecord) } @@ -114,25 +114,24 @@ func InitMessages(app *pocketbase.PocketBase, e *core.ServeEvent) error { if err != nil { logger.LogErrorF("Error getting eventListSlotEntries for EmailNotifier: %v", err) - return err } // send messages to all eventListSlotEntries for _, record := range listEntryRecords { // expand the createdMessageRecord to get the user if errs := app.Dao().ExpandRecord(record, []string{"user"}, nil); len(errs) > 0 { - return errs["user"] + logger.LogErrorF("Error expanding user for EmailNotifier: %v", errs) } go sendEmailNotification(app, registry, record.ExpandedOne("user"), createdMessageRecord) } // get event and eventAdmins if errs := app.Dao().ExpandRecord(eventList, []string{"event"}, nil); len(errs) > 0 { - return errs["event"] + logger.LogErrorF("Error expanding event for EmailNotifier: %v", errs) } event := eventList.ExpandedOne("event") if errs := app.Dao().ExpandRecord(event, []string{"eventAdmins"}, nil); len(errs) > 0 { - return errs["eventAdmins"] + logger.LogErrorF("Error expanding eventAdmins for EmailNotifier: %v", errs) } eventAdmins := event.ExpandedAll("eventAdmins")