Skip to content

Commit 0f21fe9

Browse files
brandonchinn178ysangkok
authored andcommitted
Move + rename emailText => describeDependencyUpdate
1 parent 58a1973 commit 0f21fe9

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/Distribution/Server/Features/UserNotify.hs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -703,44 +703,14 @@ userNotifyFeature ServerEnv{serverBaseURI, serverCron}
703703
genEmails =
704704
dependencyReleaseEmails (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref
705705
dependencyEmailMap <- Map.unionsWith (++) <$> traverse (genEmails . pkgInfoToPkgId) revisionsAndUploads
706-
let
707-
emailText :: MonadIO m => (UserId, PackageId) -> [PackageId] -> m [String]
708-
emailText (uId, dep) revDeps = do
709-
mPrefs <- queryGetUserNotifyPref uId
710-
pure $
711-
case mPrefs of
712-
Nothing -> []
713-
Just NotifyPref{notifyDependencyTriggerBounds} ->
714-
[ "The dependency " <> display dep <> " has been updated."
715-
] ++
716-
case notifyDependencyTriggerBounds of
717-
Always ->
718-
[ "You have requested to be notified for each upload/revision of a dependency. \
719-
\These are your packages that depend on " <> display dep <> ":"
720-
]
721-
outOfRangeOption ->
722-
[ "You have requested to be notified when a dependency isn't accepted by any of \
723-
\your maintained packages."
724-
] ++
725-
case outOfRangeOption of
726-
NewIncompatibility ->
727-
[ "The following packages did accept the second highest version of "
728-
<> display (packageName dep) <> "."
729-
]
730-
_ ->
731-
[]
732-
++
733-
[ "These are your packages that require " <> display (packageName dep) <> " but don't accept " <> display (packageVersion dep) <> ":"
734-
]
735-
++ map display revDeps
736-
dependencyEmailTextMaps <- Map.mapKeys fst <$> Map.traverseWithKey emailText dependencyEmailMap
706+
dependencyEmails <- Map.mapKeys fst <$> Map.traverseWithKey describeDependencyUpdate dependencyEmailMap
737707

738708
-- Concat the constituent email parts such that only one email is sent per user
739709
mapM_ (sendNotifyEmailAndDelay users) . Map.toList $ foldr1 (Map.unionWith (++)) $ [revisionUploadEmails, groupActionEmails, docReportEmails, tagProposalEmails]
740710

741711
-- Dependency email notifications consist of multiple paragraphs, so it would be confusing if concatenated.
742712
-- So they're sent independently.
743-
mapM_ (sendNotifyEmailAndDelay users) . Map.toList $ dependencyEmailTextMaps
713+
mapM_ (sendNotifyEmailAndDelay users) . Map.toList $ dependencyEmails
744714

745715
updateState notifyState (SetNotifyTime now)
746716

@@ -864,6 +834,35 @@ userNotifyFeature ServerEnv{serverBaseURI, serverCron}
864834
where
865835
showTags = intercalate ", " . map display . Set.toList
866836

837+
describeDependencyUpdate (uId, dep) revDeps = do
838+
mPrefs <- queryGetUserNotifyPref uId
839+
pure $
840+
case mPrefs of
841+
Nothing -> []
842+
Just NotifyPref{notifyDependencyTriggerBounds} ->
843+
[ "The dependency " <> display dep <> " has been updated."
844+
] ++
845+
case notifyDependencyTriggerBounds of
846+
Always ->
847+
[ "You have requested to be notified for each upload/revision of a dependency. \
848+
\These are your packages that depend on " <> display dep <> ":"
849+
]
850+
outOfRangeOption ->
851+
[ "You have requested to be notified when a dependency isn't accepted by any of \
852+
\your maintained packages."
853+
] ++
854+
case outOfRangeOption of
855+
NewIncompatibility ->
856+
[ "The following packages did accept the second highest version of "
857+
<> display (packageName dep) <> "."
858+
]
859+
_ ->
860+
[]
861+
++
862+
[ "These are your packages that require " <> display (packageName dep) <> " but don't accept " <> display (packageVersion dep) <> ":"
863+
]
864+
++ map display revDeps
865+
867866
sendNotifyEmailAndDelay :: Users.Users -> (UserId, [String]) -> IO ()
868867
sendNotifyEmailAndDelay users (uid, ebody) = do
869868
mudetails <- queryUserDetails uid

0 commit comments

Comments
 (0)