@@ -707,10 +707,10 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
707707
708708 idx <- queryGetPackageIndex
709709 revIdx <- liftIO queryReverseIndex
710- dependencyUpdateNotifications <- concatMapM (genDependencyUpdateList idx revIdx . pkgInfoToPkgId) revisionsAndUploads
710+ dependencyUpdateNotifications <- concatMapM (genDependencyUpdateList notifyPrefs idx revIdx . pkgInfoToPkgId) revisionsAndUploads
711711
712712 emails <-
713- getNotificationEmails serverEnv userDetailsFeature queryGetUserNotifyPref users $
713+ getNotificationEmails serverEnv userDetailsFeature users $
714714 concat
715715 [ revisionUploadNotifications
716716 , groupActionNotifications
@@ -844,13 +844,16 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
844844 , notifyDeletedTags = deletedTags
845845 }
846846
847- genDependencyUpdateList idx revIdx pkg = do
848- let toNotif watchedPkgs =
847+ genDependencyUpdateList notifyPrefs idx revIdx pkg = do
848+ let toNotif uid watchedPkgs =
849849 NotifyDependencyUpdate
850850 { notifyPackageId = pkg
851851 , notifyWatchedPackages = watchedPkgs
852+ , notifyTriggerBounds =
853+ notifyDependencyTriggerBounds $
854+ fromMaybe defaultNotifyPrefs (Map. lookup uid notifyPrefs)
852855 }
853- Map. toList . fmap toNotif
856+ Map. toList . Map. mapWithKey toNotif
854857 <$> getUserNotificationsOnRelease (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref pkg
855858
856859 sendNotifyEmailAndDelay :: Mail -> IO ()
@@ -892,6 +895,7 @@ data Notification
892895 -- ^ Dependency that was updated
893896 , notifyWatchedPackages :: [PackageId ]
894897 -- ^ Packages maintained by user that depend on updated dep
898+ , notifyTriggerBounds :: NotifyTriggerBounds
895899 }
896900 deriving (Show )
897901
@@ -911,24 +915,19 @@ data NotificationGroup
911915getNotificationEmails
912916 :: ServerEnv
913917 -> UserDetailsFeature
914- -> (UserId -> IO (Maybe NotifyPref ))
915918 -> Users. Users
916919 -> [(UserId , Notification )]
917920 -> IO [Mail ]
918921getNotificationEmails
919922 ServerEnv {serverBaseURI}
920923 UserDetailsFeature {queryUserDetails}
921- queryGetUserNotifyPref
922924 allUsers
923925 notifications = do
924926 let userIds = Set. fromList $ map fst notifications
925927 userIdToDetails <- Map. mapMaybe id <$> fromSetM queryUserDetails userIds
926- userIdToNotifyPref <- Map. mapMaybe id <$> fromSetM queryGetUserNotifyPref userIds
927928
928929 pure $
929- let emails =
930- groupNotifications . flip mapMaybe notifications $ \ (uid, notif) ->
931- fmap (uid,) $ renderNotification userIdToNotifyPref uid notif
930+ let emails = groupNotifications $ map (fmap renderNotification) notifications
932931 in flip mapMaybe (Map. toList emails) $ \ ((uid, group), emailContent) ->
933932 case uid `Map.lookup` userIdToDetails of
934933 Nothing -> Nothing
@@ -984,8 +983,8 @@ getNotificationEmails
984983
985984 {- ---- Render notifications -----}
986985
987- renderNotification :: Map UserId NotifyPref -> UserId -> Notification -> Maybe (EmailContent , NotificationGroup )
988- renderNotification userIdToNotifyPref uid = \ case
986+ renderNotification :: Notification -> (EmailContent , NotificationGroup )
987+ renderNotification = \ case
989988 NotifyNewVersion {.. } ->
990989 generalNotification $
991990 renderNotifyNewVersion
@@ -1016,18 +1015,14 @@ getNotificationEmails
10161015 notifyAddedTags
10171016 notifyDeletedTags
10181017 NotifyDependencyUpdate {.. } ->
1019- case uid `Map.lookup` userIdToNotifyPref of
1020- Nothing -> Nothing
1021- Just notifyPref ->
1022- Just
1023- ( renderNotifyDependencyUpdate
1024- notifyPref
1025- notifyPackageId
1026- notifyWatchedPackages
1027- , DependencyNotification notifyPackageId
1028- )
1018+ ( renderNotifyDependencyUpdate
1019+ notifyTriggerBounds
1020+ notifyPackageId
1021+ notifyWatchedPackages
1022+ , DependencyNotification notifyPackageId
1023+ )
10291024 where
1030- generalNotification emailContent = Just (emailContent , GeneralNotification )
1025+ generalNotification = ( , GeneralNotification )
10311026
10321027 renderNotifyNewVersion pkg =
10331028 EmailContentParagraph $
@@ -1065,20 +1060,20 @@ getNotificationEmails
10651060 where
10661061 showTags = emailContentIntercalate " , " . map emailContentDisplay . Set. toList
10671062
1068- renderNotifyDependencyUpdate NotifyPref { .. } dep revDeps =
1063+ renderNotifyDependencyUpdate triggerBounds dep revDeps =
10691064 let depName = emailContentDisplay (packageName dep)
10701065 depVersion = emailContentDisplay (packageVersion dep)
10711066 in
10721067 foldMap EmailContentParagraph
10731068 [ " The dependency " <> renderPkgLink dep <> " has been uploaded or revised."
1074- , case notifyDependencyTriggerBounds of
1069+ , case triggerBounds of
10751070 Always ->
10761071 " You have requested to be notified for each upload or revision \
10771072 \of a dependency."
10781073 _ ->
10791074 " You have requested to be notified when a dependency isn't \
10801075 \accepted by any of your maintained packages."
1081- , case notifyDependencyTriggerBounds of
1076+ , case triggerBounds of
10821077 Always ->
10831078 " These are your packages that depend on " <> depName <> " :"
10841079 BoundsOutOfRange ->
0 commit comments