Skip to content

Commit 8f7c98e

Browse files
brandonchinn178ysangkok
authored andcommitted
Move describeTagProposal into getNotificationEmails
1 parent d6d0d94 commit 8f7c98e

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

src/Distribution/Server/Features/UserNotify.hs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,7 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
699699
let docReportEmails = foldMap describeDocReport <$> docReportNotifications
700700

701701
tagProposals <- collectTagProposals
702-
tagProposalNotifications <- foldM (genTagProposalList notifyPrefs) Map.empty tagProposals
703-
let tagProposalEmails = foldMap describeTagProposal <$> tagProposalNotifications
702+
tagProposalNotifications <- concatMapM (genTagProposalList notifyPrefs) tagProposals
704703

705704
idx <- queryGetPackageIndex
706705
revIdx <- liftIO queryReverseIndex
@@ -711,13 +710,13 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
711710
getNotificationEmails serverEnv userDetailsFeature users
712711
( foldr1 (Map.unionWith (<>))
713712
[ docReportEmails
714-
, tagProposalEmails
715713
]
716714
, dependencyEmails
717715
) $
718716
concat
719717
[ revisionUploadNotifications
720718
, groupActionNotifications
719+
, tagProposalNotifications
721720
]
722721
mapM_ sendNotifyEmailAndDelay emails
723722

@@ -834,14 +833,19 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
834833
maintainers <- queryUserGroup $ maintainersGroup (packageName . pkgInfoId . fst $ pkgDoc)
835834
return $ foldr addNotification mp (toList maintainers)
836835

837-
genTagProposalList notifyPrefs mp pkgTags = do
838-
let addNotification uid m =
839-
if not (notifyOptOut npref) && notifyPendingTags npref
840-
then Map.insertWith (++) uid [pkgTags] m
841-
else m
842-
where npref = fromMaybe defaultNotifyPrefs (Map.lookup uid notifyPrefs)
843-
maintainers <- queryUserGroup $ maintainersGroup (fst pkgTags)
844-
return $ foldr addNotification mp (toList maintainers)
836+
genTagProposalList notifyPrefs (pkg, (addedTags, deletedTags)) = do
837+
maintainers <- queryUserGroup $ maintainersGroup pkg
838+
pure . flip mapMaybe (toList maintainers) $ \uid ->
839+
fmap (uid,) $ do
840+
let NotifyPref{..} = fromMaybe defaultNotifyPrefs (Map.lookup uid notifyPrefs)
841+
guard $ not notifyOptOut
842+
guard notifyPendingTags
843+
Just
844+
NotifyUpdateTags
845+
{ notifyPackageName = pkg
846+
, notifyAddedTags = addedTags
847+
, notifyDeletedTags = deletedTags
848+
}
845849

846850
genDependencyUpdateList idx revIdx pid =
847851
Map.mapKeys (, pid) <$>
@@ -854,15 +858,6 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
854858
then "Build successful."
855859
else "Build failed."
856860

857-
describeTagProposal (pkgName, (addTags, delTags)) =
858-
EmailContentParagraph ("Pending tag proposal for " <> emailContentDisplay pkgName <> ":")
859-
<> EmailContentList
860-
[ "Additions: " <> showTags addTags
861-
, "Deletions: " <> showTags delTags
862-
]
863-
where
864-
showTags = emailContentIntercalate ", " . map emailContentDisplay . Set.toList
865-
866861
describeDependencyUpdate (uId, dep) revDeps = do
867862
mPrefs <- queryGetUserNotifyPref uId
868863
pure $
@@ -918,6 +913,11 @@ data Notification
918913
, notifyReason :: Text
919914
, notifyUpdatedAt :: UTCTime
920915
}
916+
| NotifyUpdateTags
917+
{ notifyPackageName :: PackageName
918+
, notifyAddedTags :: Set Tag
919+
, notifyDeletedTags :: Set Tag
920+
}
921921

922922
data NotifyMaintainerUpdateType = MaintainerAdded | MaintainerRemoved
923923

@@ -1036,6 +1036,12 @@ getNotificationEmails
10361036
notifyPackageName
10371037
notifyReason
10381038
notifyUpdatedAt
1039+
NotifyUpdateTags{..} ->
1040+
generalNotification $
1041+
renderNotifyUpdateTags
1042+
notifyPackageName
1043+
notifyAddedTags
1044+
notifyDeletedTags
10391045
where
10401046
generalNotification emailContent = Just (emailContent, GeneralNotification)
10411047

@@ -1059,6 +1065,14 @@ getNotificationEmails
10591065
, "Reason: " <> EmailContentText reason
10601066
]
10611067

1068+
renderNotifyUpdateTags pkg addedTags deletedTags =
1069+
EmailContentParagraph ("Pending tag proposal for " <> emailContentDisplay pkg <> ":")
1070+
<> EmailContentList
1071+
[ "Additions: " <> showTags addedTags
1072+
, "Deletions: " <> showTags deletedTags
1073+
]
1074+
where
1075+
showTags = emailContentIntercalate ", " . map emailContentDisplay . Set.toList
10621076

10631077
{----- Rendering helpers -----}
10641078

0 commit comments

Comments
 (0)