@@ -580,7 +580,7 @@ userNotifyFeature :: ServerEnv
580580 -> StateComponent AcidState NotifyData
581581 -> Templates
582582 -> UserNotifyFeature
583- userNotifyFeature serverEnv@ ServerEnv {serverBaseURI, serverCron}
583+ userNotifyFeature serverEnv@ ServerEnv {serverCron}
584584 UserFeature {.. }
585585 CoreFeature {.. }
586586 UploadFeature {.. }
@@ -703,32 +703,25 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
703703
704704 idx <- queryGetPackageIndex
705705 revIdx <- liftIO queryReverseIndex
706- dependencyUpdateNotifications <- Map. unionsWith (++) <$> traverse (genDependencyUpdateList idx revIdx . pkgInfoToPkgId) revisionsAndUploads
707- dependencyEmails <- Map. traverseWithKey describeDependencyUpdate dependencyUpdateNotifications
706+ dependencyUpdateNotifications <- concatMapM (genDependencyUpdateList idx revIdx . pkgInfoToPkgId) revisionsAndUploads
708707
709708 emails <-
710- getNotificationEmails serverEnv userDetailsFeature users
709+ getNotificationEmails serverEnv userDetailsFeature queryGetUserNotifyPref users
711710 ( foldr1 (Map. unionWith (<>) )
712711 [ docReportEmails
713712 ]
714- , dependencyEmails
713+ , mempty
715714 ) $
716715 concat
717716 [ revisionUploadNotifications
718717 , groupActionNotifications
719718 , tagProposalNotifications
719+ , dependencyUpdateNotifications
720720 ]
721721 mapM_ sendNotifyEmailAndDelay emails
722722
723723 updateState notifyState (SetNotifyTime now)
724724
725- renderPkgLink pkg =
726- EmailContentLink
727- (T. pack $ display pkg)
728- serverBaseURI
729- { uriPath = " /package/" <> display (packageName pkg) <> " -" <> display (packageVersion pkg)
730- }
731-
732725 collectRevisionsAndUploads earlier now = do
733726 pkgIndex <- queryGetPackageIndex
734727 let isRecent pkgInfo =
@@ -847,9 +840,14 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
847840 , notifyDeletedTags = deletedTags
848841 }
849842
850- genDependencyUpdateList idx revIdx pid =
851- Map. mapKeys (, pid) <$>
852- getUserNotificationsOnRelease (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref pid
843+ genDependencyUpdateList idx revIdx pkg = do
844+ let toNotif watchedPkgs =
845+ NotifyDependencyUpdate
846+ { notifyPackageId = pkg
847+ , notifyWatchedPackages = watchedPkgs
848+ }
849+ Map. toList . fmap toNotif
850+ <$> getUserNotificationsOnRelease (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref pkg
853851
854852 describeDocReport (pkg, success) =
855853 EmailContentParagraph $
@@ -858,37 +856,6 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
858856 then " Build successful."
859857 else " Build failed."
860858
861- describeDependencyUpdate (uId, dep) revDeps = do
862- mPrefs <- queryGetUserNotifyPref uId
863- pure $
864- case mPrefs of
865- Nothing -> mempty
866- Just NotifyPref {notifyDependencyTriggerBounds} ->
867- let depName = emailContentDisplay (packageName dep)
868- depVersion = emailContentDisplay (packageVersion dep)
869- in
870- foldMap EmailContentParagraph
871- [ " The dependency " <> renderPkgLink dep <> " has been uploaded or revised."
872- , case notifyDependencyTriggerBounds of
873- Always ->
874- " You have requested to be notified for each upload or revision \
875- \of a dependency."
876- _ ->
877- " You have requested to be notified when a dependency isn't \
878- \accepted by any of your maintained packages."
879- , case notifyDependencyTriggerBounds of
880- Always ->
881- " These are your packages that depend on " <> depName <> " :"
882- BoundsOutOfRange ->
883- " These are your packages that require " <> depName
884- <> " but don't accept " <> depVersion <> " :"
885- NewIncompatibility ->
886- " The following packages require " <> depName
887- <> " but don't accept " <> depVersion
888- <> " (they do accept the second-highest version):"
889- ]
890- <> EmailContentList (map renderPkgLink revDeps)
891-
892859 sendNotifyEmailAndDelay :: Mail -> IO ()
893860 sendNotifyEmailAndDelay email = do
894861 -- TODO: if we need any configuration of sendmail stuff, has to go here
@@ -918,6 +885,12 @@ data Notification
918885 , notifyAddedTags :: Set Tag
919886 , notifyDeletedTags :: Set Tag
920887 }
888+ | NotifyDependencyUpdate
889+ { notifyPackageId :: PackageId
890+ -- ^ Dependency that was updated
891+ , notifyWatchedPackages :: [PackageId ]
892+ -- ^ Packages maintained by user that depend on updated dep
893+ }
921894
922895data NotifyMaintainerUpdateType = MaintainerAdded | MaintainerRemoved
923896
@@ -934,19 +907,22 @@ data NotificationGroup
934907getNotificationEmails
935908 :: ServerEnv
936909 -> UserDetailsFeature
910+ -> (UserId -> IO (Maybe NotifyPref ))
937911 -> Users. Users
938912 -> (Map UserId EmailContent , Map (UserId , PackageId ) EmailContent )
939913 -> [(UserId , Notification )]
940914 -> IO [Mail ]
941915getNotificationEmails
942916 ServerEnv {serverBaseURI}
943917 UserDetailsFeature {queryUserDetails}
918+ queryGetUserNotifyPref
944919 allUsers
945920 (generalEmails, dependencyUpdateEmails)
946921 notifications = do
947922 let userIds = Set. fromList $ map fst notifications
948923 let userIds' = Set. fromList . Map. keys $ generalEmails <> Map. mapKeys fst dependencyUpdateEmails
949924 userIdToDetails <- Map. mapMaybe id <$> fromSetM queryUserDetails (userIds <> userIds')
925+ userIdToNotifyPref <- Map. mapMaybe id <$> fromSetM queryGetUserNotifyPref userIds
950926
951927 pure $
952928 let emails =
@@ -959,7 +935,7 @@ getNotificationEmails
959935 . Map. mapWithKey (\ (_, pkg) emailContent -> (emailContent, DependencyNotification pkg))
960936 $ dependencyUpdateEmails
961937 , flip mapMaybe notifications $ \ (uid, notif) ->
962- fmap (uid,) $ renderNotification notif
938+ fmap (uid,) $ renderNotification userIdToNotifyPref uid notif
963939 ]
964940 in flip mapMaybe (Map. toList emails) $ \ ((uid, group), emailContent) ->
965941 case uid `Map.lookup` userIdToDetails of
@@ -1016,8 +992,8 @@ getNotificationEmails
1016992
1017993 {- ---- Render notifications -----}
1018994
1019- renderNotification :: Notification -> Maybe (EmailContent , NotificationGroup )
1020- renderNotification = \ case
995+ renderNotification :: Map UserId NotifyPref -> UserId -> Notification -> Maybe (EmailContent , NotificationGroup )
996+ renderNotification userIdToNotifyPref uid = \ case
1021997 NotifyNewVersion {.. } ->
1022998 generalNotification $
1023999 renderNotifyNewVersion
@@ -1042,6 +1018,17 @@ getNotificationEmails
10421018 notifyPackageName
10431019 notifyAddedTags
10441020 notifyDeletedTags
1021+ NotifyDependencyUpdate {.. } ->
1022+ case uid `Map.lookup` userIdToNotifyPref of
1023+ Nothing -> Nothing
1024+ Just notifyPref ->
1025+ Just
1026+ ( renderNotifyDependencyUpdate
1027+ notifyPref
1028+ notifyPackageId
1029+ notifyWatchedPackages
1030+ , DependencyNotification notifyPackageId
1031+ )
10451032 where
10461033 generalNotification emailContent = Just (emailContent, GeneralNotification )
10471034
@@ -1074,6 +1061,32 @@ getNotificationEmails
10741061 where
10751062 showTags = emailContentIntercalate " , " . map emailContentDisplay . Set. toList
10761063
1064+ renderNotifyDependencyUpdate NotifyPref {.. } dep revDeps =
1065+ let depName = emailContentDisplay (packageName dep)
1066+ depVersion = emailContentDisplay (packageVersion dep)
1067+ in
1068+ foldMap EmailContentParagraph
1069+ [ " The dependency " <> renderPkgLink dep <> " has been uploaded or revised."
1070+ , case notifyDependencyTriggerBounds of
1071+ Always ->
1072+ " You have requested to be notified for each upload or revision \
1073+ \of a dependency."
1074+ _ ->
1075+ " You have requested to be notified when a dependency isn't \
1076+ \accepted by any of your maintained packages."
1077+ , case notifyDependencyTriggerBounds of
1078+ Always ->
1079+ " These are your packages that depend on " <> depName <> " :"
1080+ BoundsOutOfRange ->
1081+ " These are your packages that require " <> depName
1082+ <> " but don't accept " <> depVersion <> " :"
1083+ NewIncompatibility ->
1084+ " The following packages require " <> depName
1085+ <> " but don't accept " <> depVersion
1086+ <> " (they do accept the second-highest version):"
1087+ ]
1088+ <> EmailContentList (map renderPkgLink revDeps)
1089+
10771090 {- ---- Rendering helpers -----}
10781091
10791092 renderPackageName = emailContentStr . unPackageName
0 commit comments