feat(messages): update messages to handle multiple recipients
This commit is contained in:
parent
28af26843a
commit
849499740b
|
@ -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
|
// 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 new error with all errors
|
||||||
return fmt.Errorf("error expanding created message record: %v", errs)
|
return fmt.Errorf("error expanding created message record: %v", errs)
|
||||||
}
|
}
|
||||||
recipient := createdMessageRecord.ExpandedOne("recipient")
|
recipients := createdMessageRecord.ExpandedAll("recipients")
|
||||||
if recipient != nil {
|
for _, recipient := range recipients {
|
||||||
go sendEmailNotification(app, registry, recipient, createdMessageRecord)
|
go sendEmailNotification(app, registry, recipient, createdMessageRecord)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,25 +114,24 @@ func InitMessages(app *pocketbase.PocketBase, e *core.ServeEvent) error {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.LogErrorF("Error getting eventListSlotEntries for EmailNotifier: %v", err)
|
logger.LogErrorF("Error getting eventListSlotEntries for EmailNotifier: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send messages to all eventListSlotEntries
|
// send messages to all eventListSlotEntries
|
||||||
for _, record := range listEntryRecords {
|
for _, record := range listEntryRecords {
|
||||||
// expand the createdMessageRecord to get the user
|
// expand the createdMessageRecord to get the user
|
||||||
if errs := app.Dao().ExpandRecord(record, []string{"user"}, nil); len(errs) > 0 {
|
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)
|
go sendEmailNotification(app, registry, record.ExpandedOne("user"), createdMessageRecord)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get event and eventAdmins
|
// get event and eventAdmins
|
||||||
if errs := app.Dao().ExpandRecord(eventList, []string{"event"}, nil); len(errs) > 0 {
|
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")
|
event := eventList.ExpandedOne("event")
|
||||||
if errs := app.Dao().ExpandRecord(event, []string{"eventAdmins"}, nil); len(errs) > 0 {
|
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")
|
eventAdmins := event.ExpandedAll("eventAdmins")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue