Skip to content

Commit

Permalink
iterateConversations.
Browse files Browse the repository at this point in the history
(Copied from #1507, which
has meanwhile been reverted in
#1549.)
  • Loading branch information
fisx authored and smatting committed May 30, 2021
1 parent 5db8b0c commit 886bb46
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions services/galley/src/Galley/API/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Galley.API.Query
getConversationRoles,
getConversationIds,
getConversations,
iterateConversations,
getSelfH,
internalGetMemberH,
getConversationMetaH,
Expand Down Expand Up @@ -117,6 +118,21 @@ getConversations user mids mstart msize = do
| Data.isConvDeleted c = Data.deleteConversation (Data.convId c) >> pure False
| otherwise = pure True

iterateConversations :: forall a. UserId -> Range 1 500 Int32 -> ([Public.Conversation] -> Galley a) -> Galley [a]
iterateConversations uid pageSize handleConvs = catMaybes <$> go Nothing
where
go :: Maybe ConvId -> Galley [Maybe a]
go mbConv = do
convResult <- getConversations uid Nothing mbConv (Just pageSize)
resultHead <- Just <$> handleConvs (convList convResult)
resultTail <- case convList convResult of
(conv : rest) ->
if convHasMore convResult
then go (Just (maximum (cnvId <$> (conv : rest))))
else pure []
_ -> pure []
pure $ resultHead : resultTail

getSelfH :: UserId ::: ConvId -> Galley Response
getSelfH (zusr ::: cnv) = do
json <$> getSelf zusr cnv
Expand Down

0 comments on commit 886bb46

Please sign in to comment.