@@ -580,7 +580,7 @@ userNotifyFeature :: ServerEnv
580
580
-> StateComponent AcidState NotifyData
581
581
-> Templates
582
582
-> UserNotifyFeature
583
- userNotifyFeature serverEnv@ ServerEnv {serverBaseURI, serverCron}
583
+ userNotifyFeature serverEnv@ ServerEnv {serverCron}
584
584
UserFeature {.. }
585
585
CoreFeature {.. }
586
586
UploadFeature {.. }
@@ -703,32 +703,25 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
703
703
704
704
idx <- queryGetPackageIndex
705
705
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
708
707
709
708
emails <-
710
- getNotificationEmails serverEnv userDetailsFeature users
709
+ getNotificationEmails serverEnv userDetailsFeature queryGetUserNotifyPref users
711
710
( foldr1 (Map. unionWith (<>) )
712
711
[ docReportEmails
713
712
]
714
- , dependencyEmails
713
+ , mempty
715
714
) $
716
715
concat
717
716
[ revisionUploadNotifications
718
717
, groupActionNotifications
719
718
, tagProposalNotifications
719
+ , dependencyUpdateNotifications
720
720
]
721
721
mapM_ sendNotifyEmailAndDelay emails
722
722
723
723
updateState notifyState (SetNotifyTime now)
724
724
725
- renderPkgLink pkg =
726
- EmailContentLink
727
- (T. pack $ display pkg)
728
- serverBaseURI
729
- { uriPath = " /package/" <> display (packageName pkg) <> " -" <> display (packageVersion pkg)
730
- }
731
-
732
725
collectRevisionsAndUploads earlier now = do
733
726
pkgIndex <- queryGetPackageIndex
734
727
let isRecent pkgInfo =
@@ -847,9 +840,14 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
847
840
, notifyDeletedTags = deletedTags
848
841
}
849
842
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
853
851
854
852
describeDocReport (pkg, success) =
855
853
EmailContentParagraph $
@@ -858,37 +856,6 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
858
856
then " Build successful."
859
857
else " Build failed."
860
858
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
-
892
859
sendNotifyEmailAndDelay :: Mail -> IO ()
893
860
sendNotifyEmailAndDelay email = do
894
861
-- TODO: if we need any configuration of sendmail stuff, has to go here
@@ -918,6 +885,12 @@ data Notification
918
885
, notifyAddedTags :: Set Tag
919
886
, notifyDeletedTags :: Set Tag
920
887
}
888
+ | NotifyDependencyUpdate
889
+ { notifyPackageId :: PackageId
890
+ -- ^ Dependency that was updated
891
+ , notifyWatchedPackages :: [PackageId ]
892
+ -- ^ Packages maintained by user that depend on updated dep
893
+ }
921
894
922
895
data NotifyMaintainerUpdateType = MaintainerAdded | MaintainerRemoved
923
896
@@ -934,19 +907,22 @@ data NotificationGroup
934
907
getNotificationEmails
935
908
:: ServerEnv
936
909
-> UserDetailsFeature
910
+ -> (UserId -> IO (Maybe NotifyPref ))
937
911
-> Users. Users
938
912
-> (Map UserId EmailContent , Map (UserId , PackageId ) EmailContent )
939
913
-> [(UserId , Notification )]
940
914
-> IO [Mail ]
941
915
getNotificationEmails
942
916
ServerEnv {serverBaseURI}
943
917
UserDetailsFeature {queryUserDetails}
918
+ queryGetUserNotifyPref
944
919
allUsers
945
920
(generalEmails, dependencyUpdateEmails)
946
921
notifications = do
947
922
let userIds = Set. fromList $ map fst notifications
948
923
let userIds' = Set. fromList . Map. keys $ generalEmails <> Map. mapKeys fst dependencyUpdateEmails
949
924
userIdToDetails <- Map. mapMaybe id <$> fromSetM queryUserDetails (userIds <> userIds')
925
+ userIdToNotifyPref <- Map. mapMaybe id <$> fromSetM queryGetUserNotifyPref userIds
950
926
951
927
pure $
952
928
let emails =
@@ -959,7 +935,7 @@ getNotificationEmails
959
935
. Map. mapWithKey (\ (_, pkg) emailContent -> (emailContent, DependencyNotification pkg))
960
936
$ dependencyUpdateEmails
961
937
, flip mapMaybe notifications $ \ (uid, notif) ->
962
- fmap (uid,) $ renderNotification notif
938
+ fmap (uid,) $ renderNotification userIdToNotifyPref uid notif
963
939
]
964
940
in flip mapMaybe (Map. toList emails) $ \ ((uid, group), emailContent) ->
965
941
case uid `Map.lookup` userIdToDetails of
@@ -1016,8 +992,8 @@ getNotificationEmails
1016
992
1017
993
{- ---- Render notifications -----}
1018
994
1019
- renderNotification :: Notification -> Maybe (EmailContent , NotificationGroup )
1020
- renderNotification = \ case
995
+ renderNotification :: Map UserId NotifyPref -> UserId -> Notification -> Maybe (EmailContent , NotificationGroup )
996
+ renderNotification userIdToNotifyPref uid = \ case
1021
997
NotifyNewVersion {.. } ->
1022
998
generalNotification $
1023
999
renderNotifyNewVersion
@@ -1042,6 +1018,17 @@ getNotificationEmails
1042
1018
notifyPackageName
1043
1019
notifyAddedTags
1044
1020
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
+ )
1045
1032
where
1046
1033
generalNotification emailContent = Just (emailContent, GeneralNotification )
1047
1034
@@ -1074,6 +1061,32 @@ getNotificationEmails
1074
1061
where
1075
1062
showTags = emailContentIntercalate " , " . map emailContentDisplay . Set. toList
1076
1063
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
+
1077
1090
{- ---- Rendering helpers -----}
1078
1091
1079
1092
renderPackageName = emailContentStr . unPackageName
0 commit comments