diff --git a/src/Jobs/Handler/SendNotification.hs b/src/Jobs/Handler/SendNotification.hs index 4b31fcafa..80574a065 100644 --- a/src/Jobs/Handler/SendNotification.hs +++ b/src/Jobs/Handler/SendNotification.hs @@ -24,5 +24,11 @@ import Jobs.Handler.SendNotification.Qualification dispatchJobSendNotification :: UserId -> Notification -> JobHandler UniWorX -dispatchJobSendNotification jRecipient jNotification = JobHandlerException $ - $(dispatchTH ''Notification) jNotification jRecipient +dispatchJobSendNotification jRecipient jNotification = JobHandlerException $ do + -- TODO: this is a bad idea, since all notifications use jRecipient to generate the message body, + -- thus supervisors would receive all notifications with their own name inside! + superVs <- runDB $ selectList [UserSupervisorUser ==. jRecipient, UserSupervisorRerouteNotifications ==. True] [] + if null superVs + then $(dispatchTH ''Notification) jNotification jRecipient + else forM_ superVs $ \Entity { entityVal = UserSupervisor { userSupervisorSupervisor = svr } } -> + $(dispatchTH ''Notification) jNotification svr