@@ -707,10 +707,10 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
707
707
708
708
idx <- queryGetPackageIndex
709
709
revIdx <- liftIO queryReverseIndex
710
- dependencyUpdateNotifications <- concatMapM (genDependencyUpdateList idx revIdx . pkgInfoToPkgId) revisionsAndUploads
710
+ dependencyUpdateNotifications <- concatMapM (genDependencyUpdateList notifyPrefs idx revIdx . pkgInfoToPkgId) revisionsAndUploads
711
711
712
712
emails <-
713
- getNotificationEmails serverEnv userDetailsFeature queryGetUserNotifyPref users $
713
+ getNotificationEmails serverEnv userDetailsFeature users $
714
714
concat
715
715
[ revisionUploadNotifications
716
716
, groupActionNotifications
@@ -844,13 +844,16 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
844
844
, notifyDeletedTags = deletedTags
845
845
}
846
846
847
- genDependencyUpdateList idx revIdx pkg = do
848
- let toNotif watchedPkgs =
847
+ genDependencyUpdateList notifyPrefs idx revIdx pkg = do
848
+ let toNotif uid watchedPkgs =
849
849
NotifyDependencyUpdate
850
850
{ notifyPackageId = pkg
851
851
, notifyWatchedPackages = watchedPkgs
852
+ , notifyTriggerBounds =
853
+ notifyDependencyTriggerBounds $
854
+ fromMaybe defaultNotifyPrefs (Map. lookup uid notifyPrefs)
852
855
}
853
- Map. toList . fmap toNotif
856
+ Map. toList . Map. mapWithKey toNotif
854
857
<$> getUserNotificationsOnRelease (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref pkg
855
858
856
859
sendNotifyEmailAndDelay :: Mail -> IO ()
@@ -892,6 +895,7 @@ data Notification
892
895
-- ^ Dependency that was updated
893
896
, notifyWatchedPackages :: [PackageId ]
894
897
-- ^ Packages maintained by user that depend on updated dep
898
+ , notifyTriggerBounds :: NotifyTriggerBounds
895
899
}
896
900
deriving (Show )
897
901
@@ -911,24 +915,19 @@ data NotificationGroup
911
915
getNotificationEmails
912
916
:: ServerEnv
913
917
-> UserDetailsFeature
914
- -> (UserId -> IO (Maybe NotifyPref ))
915
918
-> Users. Users
916
919
-> [(UserId , Notification )]
917
920
-> IO [Mail ]
918
921
getNotificationEmails
919
922
ServerEnv {serverBaseURI}
920
923
UserDetailsFeature {queryUserDetails}
921
- queryGetUserNotifyPref
922
924
allUsers
923
925
notifications = do
924
926
let userIds = Set. fromList $ map fst notifications
925
927
userIdToDetails <- Map. mapMaybe id <$> fromSetM queryUserDetails userIds
926
- userIdToNotifyPref <- Map. mapMaybe id <$> fromSetM queryGetUserNotifyPref userIds
927
928
928
929
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
932
931
in flip mapMaybe (Map. toList emails) $ \ ((uid, group), emailContent) ->
933
932
case uid `Map.lookup` userIdToDetails of
934
933
Nothing -> Nothing
@@ -984,8 +983,8 @@ getNotificationEmails
984
983
985
984
{- ---- Render notifications -----}
986
985
987
- renderNotification :: Map UserId NotifyPref -> UserId -> Notification -> Maybe (EmailContent , NotificationGroup )
988
- renderNotification userIdToNotifyPref uid = \ case
986
+ renderNotification :: Notification -> (EmailContent , NotificationGroup )
987
+ renderNotification = \ case
989
988
NotifyNewVersion {.. } ->
990
989
generalNotification $
991
990
renderNotifyNewVersion
@@ -1016,18 +1015,14 @@ getNotificationEmails
1016
1015
notifyAddedTags
1017
1016
notifyDeletedTags
1018
1017
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
+ )
1029
1024
where
1030
- generalNotification emailContent = Just (emailContent , GeneralNotification )
1025
+ generalNotification = ( , GeneralNotification )
1031
1026
1032
1027
renderNotifyNewVersion pkg =
1033
1028
EmailContentParagraph $
@@ -1065,20 +1060,20 @@ getNotificationEmails
1065
1060
where
1066
1061
showTags = emailContentIntercalate " , " . map emailContentDisplay . Set. toList
1067
1062
1068
- renderNotifyDependencyUpdate NotifyPref { .. } dep revDeps =
1063
+ renderNotifyDependencyUpdate triggerBounds dep revDeps =
1069
1064
let depName = emailContentDisplay (packageName dep)
1070
1065
depVersion = emailContentDisplay (packageVersion dep)
1071
1066
in
1072
1067
foldMap EmailContentParagraph
1073
1068
[ " The dependency " <> renderPkgLink dep <> " has been uploaded or revised."
1074
- , case notifyDependencyTriggerBounds of
1069
+ , case triggerBounds of
1075
1070
Always ->
1076
1071
" You have requested to be notified for each upload or revision \
1077
1072
\of a dependency."
1078
1073
_ ->
1079
1074
" You have requested to be notified when a dependency isn't \
1080
1075
\accepted by any of your maintained packages."
1081
- , case notifyDependencyTriggerBounds of
1076
+ , case triggerBounds of
1082
1077
Always ->
1083
1078
" These are your packages that depend on " <> depName <> " :"
1084
1079
BoundsOutOfRange ->
0 commit comments