fetchCommentReplies :: MonadIO m => Options -> Comment -> CommentProducer m
fetchCommentReplies opts Comment{..} = do
  let Listing _ after commentRefs = replies
  if null commentRefs && isNothing after then return $ Right ()
  else do
    logFmt Trace "Looking up replies to comment #{} from /r/{}" (cid, subr)

    -- TODO: follow the possible "after" in the Listing below;
    -- it's not very necessary for the purpose this whole function is used yet
    let Listing _ _ commentReplies = replies
    resolveCommentRefs opts commentReplies
  where
  CommentID cid = commentID
  R subr = subreddit

  resolveCommentRefs :: MonadIO m
                     => Options -> [CommentReference]
                     -> CommentProducer m
  resolveCommentRefs opts commentRefs = do
    -- CommentReference may hide multiple unresolved CommentIDs;
    -- gather them all in a single list
    let justSingularRefs = concatMap treeSubComments commentRefs
        unresolved = [ cid | Reference _ [CommentID cid] <- justSingularRefs ]

    -- Resolve those references, getting a HashMap from IDs to Comments
    result <- runReddit opts $ do
      let chunked = chunksOf singleCommentGetLimit unresolved
      resolved <- (concat <$>) . forM chunked $ \cids -> do
        -- TODO: handle the possible (but unlikely) `after` in the response
        Listing _ _ comments <- getCommentsInfo (map CommentID cids)
        return comments
      return $ HM.fromList (zip unresolved resolved)

    -- Use it to translate all CommentReferences to Comments
    case result of
      Left err -> return $ Left err
      Right refMap -> do
        let resolveRef = \case
              Actual c -> Just c
              Reference _ [CommentID cid] -> HM.lookup cid refMap
              _ -> Nothing
        forM_ (mapMaybe resolveRef justSingularRefs) $
          yield
        return $ Right ()
    where
    singleCommentGetLimit = 100 -- enforced by Reddit API
fetchCommentReplies :: MonadIO m => Options -> Comment -> CommentProducer m
fetchCommentReplies opts Comment{..} = do
  let Listing _ after commentRefs = replies
  if null commentRefs && isNothing after then return $ Right ()
  else do
    logFmt Trace "Looking up replies to comment #{} from /r/{}" (cid, subr)

    -- TODO: follow the possible "after" in the Listing below;
    -- it's not very necessary for the purpose this whole function is used yet
    let Listing _ _ commentReplies = replies
    resolveCommentRefs opts commentReplies
  where
  CommentID cid = commentID
  R subr = subreddit

  resolveCommentRefs :: MonadIO m
                     => Options -> [CommentReference]
                     -> CommentProducer m
  resolveCommentRefs opts commentRefs = do
    -- CommentReference may hide multiple unresolved CommentIDs;
    -- gather them all in a single list
    let justSingularRefs = concatMap treeSubComments commentRefs
        unresolved = [ cid | Reference _ [CommentID cid] <- justSingularRefs ]

    -- Resolve those references, getting a HashMap from IDs to Comments
    result <- runReddit opts $ do
      let chunked = chunksOf singleCommentGetLimit unresolved
      resolved <- (concat <$>) . forM chunked $ \cids -> do
        -- TODO: handle the possible (but unlikely) `after` in the response
        Listing _ _ comments <- getCommentsInfo (map CommentID cids)
        return comments
      return $ HM.fromList (zip unresolved resolved)

    -- Use it to translate all CommentReferences to Comments
    case result of
      Left err -> return $ Left err
      Right refMap -> do
        let resolveRef = \case
              Actual c -> Just c
              Reference _ [CommentID cid] -> HM.lookup cid refMap
              _ -> Nothing
        forM_ (mapMaybe resolveRef justSingularRefs) $
          yield
        return $ Right ()
    where
    singleCommentGetLimit = 100 -- enforced by Reddit API
fetchCommentReplies opts Comment{..} = do
  let Listing _ after commentRefs = replies
  if null commentRefs && isNothing after then return $ Right ()
  else do
    logFmt Trace "Looking up replies to comment #{} from /r/{}" (cid, subr)

    -- TODO: follow the possible "after" in the Listing below;
    -- it's not very necessary for the purpose this whole function is used yet
    let Listing _ _ commentReplies = replies
    resolveCommentRefs opts commentReplies
  where
  CommentID cid = commentID
  R subr = subreddit

  resolveCommentRefs :: MonadIO m
                     => Options -> [CommentReference]
                     -> CommentProducer m
  resolveCommentRefs opts commentRefs = do
    -- CommentReference may hide multiple unresolved CommentIDs;
    -- gather them all in a single list
    let justSingularRefs = concatMap treeSubComments commentRefs
        unresolved = [ cid | Reference _ [CommentID cid] <- justSingularRefs ]

    -- Resolve those references, getting a HashMap from IDs to Comments
    result <- runReddit opts $ do
      let chunked = chunksOf singleCommentGetLimit unresolved
      resolved <- (concat <$>) . forM chunked $ \cids -> do
        -- TODO: handle the possible (but unlikely) `after` in the response
        Listing _ _ comments <- getCommentsInfo (map CommentID cids)
        return comments
      return $ HM.fromList (zip unresolved resolved)

    -- Use it to translate all CommentReferences to Comments
    case result of
      Left err -> return $ Left err
      Right refMap -> do
        let resolveRef = \case
              Actual c -> Just c
              Reference _ [CommentID cid] -> HM.lookup cid refMap
              _ -> Nothing
        forM_ (mapMaybe resolveRef justSingularRefs) $
          yield
        return $ Right ()
    where
    singleCommentGetLimit = 100 -- enforced by Reddit API