flagCommentDB
    :: CommentId
    -> Text
    -> UserId
    -> [FlagReason]
    -> Maybe Markdown
    -> SYDB Bool
flagCommentDB comment_id permalink_route flagger_id reasons message = do
    poster_id <- lift (commentUser <$> get404 comment_id)
    now <- liftIO getCurrentTime
    mFlaggingId <-
        lift (insertUnique (CommentFlagging now flagger_id comment_id message))
    flip (maybe (return False)) mFlaggingId $ \flagging_id -> do
        lift $ void $
            insertMany (map (CommentFlaggingReason flagging_id) reasons)

        sendPreferredUserNotificationDB
            (Just $ NotificationSender flagger_id)
            (NotificationReceiver poster_id)
            NotifFlag
            Nothing
            notif_text
        return True
  where
    notif_text = Markdown $
       "Another user flagged your comment as not meeting the standards "
       <> "of the Code of Conduct. We *want* your involvement as long as "
       <> "it remains respectful and friendly, so please don’t feel "
       <> "discouraged."
       <> "\n"
       <> "Please follow the link below for clarification and "
       <> "suggestions the flagger may have offered, and take this "
       <> "chance to improve your tone and clarify any misunderstanding. "
       <> "Your newly edited comment will then be publicly visible "
       <> "again."
       <> "\n"
       <> "Please alert a moderator if you believe that this flagging "
       <> "is inappropriate, if the flagger violated the Code of "
       <> "Conduct in their feedback, or if you want other "
       <> "assistance."
       <> "\n"
       <> "[link to flagged comment](" <> permalink_route <> ")"

-- | Post an new (approved) Comment.
p
flagCommentDB
    :: CommentId
    -> Text
    -> UserId
    -> [FlagReason]
    -> Maybe Markdown
    -> SYDB Bool
flagCommentDB comment_id permalink_route flagger_id reasons message = do
    poster_id <- lift (commentUser <$> get404 comment_id)
    now <- liftIO getCurrentTime
    mFlaggingId <-
        lift (insertUnique (CommentFlagging now flagger_id comment_id message))
    flip (maybe (return False)) mFlaggingId $ \flagging_id -> do
        lift $ void $
            insertMany (map (CommentFlaggingReason flagging_id) reasons)

        sendPreferredUserNotificationDB
            (Just $ NotificationSender flagger_id)
            (NotificationReceiver poster_id)
            NotifFlag
            Nothing
            notif_text
        return True
  where
    notif_text = Markdown $
       "Another user flagged your comment as not meeting the standards "
       <> "of the Code of Conduct. We *want* your involvement as long as "
       <> "it remains respectful and friendly, so please don’t feel "
       <> "discouraged."
       <> "\n"
       <> "Please follow the link below for clarification and "
       <> "suggestions the flagger may have offered, and take this "
       <> "chance to improve your tone and clarify any misunderstanding. "
       <> "Your newly edited comment will then be publicly visible "
       <> "again."
       <> "\n"
       <> "Please alert a moderator if you believe that this flagging "
       <> "is inappropriate, if the flagger violated the Code of "
       <> "Conduct in their feedback, or if you want other "
       <> "assistance."
       <> "\n"
       <> "[link to flagged comment](" <> permalink_route <> ")"

-- | Post an new (approved) Comment.
flagCommentDB comment_id permalink_route flagger_id reasons message = do
    poster_id <- lift (commentUser <$> get404 comment_id)
    now <- liftIO getCurrentTime
    mFlaggingId <-
        lift (insertUnique (CommentFlagging now flagger_id comment_id message))
    flip (maybe (return False)) mFlaggingId $ \flagging_id -> do
        lift $ void $
            insertMany (map (CommentFlaggingReason flagging_id) reasons)

        sendPreferredUserNotificationDB
            (Just $ NotificationSender flagger_id)
            (NotificationReceiver poster_id)
            NotifFlag
            Nothing
            notif_text
        return True
  where
    notif_text = Markdown $
       "Another user flagged your comment as not meeting the standards "
       <> "of the Code of Conduct. We *want* your involvement as long as "
       <> "it remains respectful and friendly, so please don’t feel "
       <> "discouraged."
       <> "\n"
       <> "Please follow the link below for clarification and "
       <> "suggestions the flagger may have offered, and take this "
       <> "chance to improve your tone and clarify any misunderstanding. "
       <> "Your newly edited comment will then be publicly visible "
       <> "again."
       <> "\n"
       <> "Please alert a moderator if you believe that this flagging "
       <> "is inappropriate, if the flagger violated the Code of "
       <> "Conduct in their feedback, or if you want other "
       <> "assistance."
       <> "\n"
       <> "[link to flagged comment](" <> permalink_route <> ")"

-- | Post an new (approved) Comment.