"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "services/galley/src/Galley/API/Query.hs" between
wire-server-2020-06-10.tar.gz and wire-server-2020-06-19.tar.gz

About: Wire (server) offers end-to-end encrypted messaging, file-sharing, video and voice calls, and guest rooms for external communication (back-end server).

Query.hs  (wire-server-2020-06-10):Query.hs  (wire-server-2020-06-19)
skipping to change at line 31 skipping to change at line 31
getConversationRolesH, getConversationRolesH,
getConversationIdsH, getConversationIdsH,
getConversationsH, getConversationsH,
getSelfH, getSelfH,
internalGetMemberH, internalGetMemberH,
getConversationMetaH, getConversationMetaH,
) )
where where
import Data.ByteString.Conversion import Data.ByteString.Conversion
import Data.Id import Data.Id as Id
import Data.IdMapping (MappedOrLocalId (Local), partitionMappedOrLocalIds) import Data.IdMapping (MappedOrLocalId (Local), opaqueIdFromMappedOrLocal, parti
tionMappedOrLocalIds)
import Data.Range import Data.Range
import Galley.API.Error import Galley.API.Error
import Galley.API.Mapping import qualified Galley.API.Mapping as Mapping
import Galley.API.Util import Galley.API.Util
import Galley.App import Galley.App
import qualified Galley.Data as Data import qualified Galley.Data as Data
import qualified Galley.Data.Types as Data import qualified Galley.Data.Types as Data
import Galley.Types import Galley.Types
import Galley.Types.Conversations.Roles import Galley.Types.Conversations.Roles
import Imports import Imports
import Network.HTTP.Types import Network.HTTP.Types
import Network.Wai import Network.Wai
import Network.Wai.Predicate hiding (result, setStatus) import Network.Wai.Predicate hiding (result, setStatus)
skipping to change at line 62 skipping to change at line 62
getBotConversationH (zbot ::: zcnv ::: _) = do getBotConversationH (zbot ::: zcnv ::: _) = do
json <$> getBotConversation zbot zcnv json <$> getBotConversation zbot zcnv
getBotConversation :: BotId -> ConvId -> Galley Public.BotConvView getBotConversation :: BotId -> ConvId -> Galley Public.BotConvView
getBotConversation zbot zcnv = do getBotConversation zbot zcnv = do
c <- getConversationAndCheckMembershipWithError convNotFound (botUserId zbot) (Local zcnv) c <- getConversationAndCheckMembershipWithError convNotFound (botUserId zbot) (Local zcnv)
let cmems = mapMaybe mkMember (toList (Data.convMembers c)) let cmems = mapMaybe mkMember (toList (Data.convMembers c))
pure $ Public.botConvView zcnv (Data.convName c) cmems pure $ Public.botConvView zcnv (Data.convName c) cmems
where where
mkMember m mkMember m
| memId m /= botUserId zbot = Just (OtherMember (memId m) (memService m) ( | memId m == Local (botUserId zbot) =
memConvRoleName m)) Nothing -- no need to list the bot itself
| otherwise = Nothing | otherwise =
Just (OtherMember (opaqueIdFromMappedOrLocal (memId m)) (memService m) (
memConvRoleName m))
getConversationH :: UserId ::: OpaqueConvId ::: JSON -> Galley Response getConversationH :: UserId ::: OpaqueConvId ::: JSON -> Galley Response
getConversationH (zusr ::: cnv ::: _) = do getConversationH (zusr ::: cnv ::: _) = do
json <$> getConversation zusr cnv json <$> getConversation zusr cnv
getConversation :: UserId -> OpaqueConvId -> Galley Public.Conversation getConversation :: UserId -> OpaqueConvId -> Galley Public.Conversation
getConversation zusr opaqueCnv = do getConversation zusr opaqueCnv = do
cnv <- resolveOpaqueConvId opaqueCnv cnv <- resolveOpaqueConvId opaqueCnv
c <- getConversationAndCheckMembership zusr cnv c <- getConversationAndCheckMembership zusr cnv
conversationView zusr c Mapping.conversationView (Local zusr) c
getConversationRolesH :: UserId ::: OpaqueConvId ::: JSON -> Galley Response getConversationRolesH :: UserId ::: OpaqueConvId ::: JSON -> Galley Response
getConversationRolesH (zusr ::: cnv ::: _) = do getConversationRolesH (zusr ::: cnv ::: _) = do
json <$> getConversationRoles zusr cnv json <$> getConversationRoles zusr cnv
getConversationRoles :: UserId -> OpaqueConvId -> Galley Public.ConversationRole sList getConversationRoles :: UserId -> OpaqueConvId -> Galley Public.ConversationRole sList
getConversationRoles zusr opaqueCnv = do getConversationRoles zusr opaqueCnv = do
cnv <- resolveOpaqueConvId opaqueCnv cnv <- resolveOpaqueConvId opaqueCnv
void $ getConversationAndCheckMembership zusr cnv void $ getConversationAndCheckMembership zusr cnv
-- NOTE: If/when custom roles are added, these roles should -- NOTE: If/when custom roles are added, these roles should
-- be merged with the team roles (if they exist) -- be merged with the team roles (if they exist)
pure $ Public.ConversationRolesList wireConvRoles pure $ Public.ConversationRolesList wireConvRoles
getConversationIdsH :: UserId ::: Maybe OpaqueConvId ::: Range 1 1000 Int32 ::: JSON -> Galley Response getConversationIdsH :: UserId ::: Maybe OpaqueConvId ::: Range 1 1000 Int32 ::: JSON -> Galley Response
getConversationIdsH (zusr ::: start ::: size ::: _) = do getConversationIdsH (zusr ::: start ::: size ::: _) = do
json <$> getConversationIds zusr start size json <$> getConversationIds zusr start size
getConversationIds :: UserId -> Maybe OpaqueConvId -> Range 1 1000 Int32 -> Gall ey (Public.ConversationList OpaqueConvId) getConversationIds :: UserId -> Maybe OpaqueConvId -> Range 1 1000 Int32 -> Gall ey (Public.ConversationList OpaqueConvId)
getConversationIds zusr start size = do getConversationIds zusr start size = do
ids <- Data.conversationIdsFrom zusr start size ids <- Data.conversationIdRowsFrom zusr start size
pure $ pure $
Public.ConversationList Public.ConversationList
(Data.resultSetResult ids) ((\(i, _, _) -> i) <$> Data.resultSetResult ids)
(Data.resultSetType ids == Data.ResultSetTruncated) (Data.resultSetType ids == Data.ResultSetTruncated)
getConversationsH :: UserId ::: Maybe (Either (Range 1 32 (List OpaqueConvId)) O paqueConvId) ::: Range 1 500 Int32 ::: JSON -> Galley Response getConversationsH :: UserId ::: Maybe (Either (Range 1 32 (List OpaqueConvId)) O paqueConvId) ::: Range 1 500 Int32 ::: JSON -> Galley Response
getConversationsH (zusr ::: range ::: size ::: _) = getConversationsH (zusr ::: range ::: size ::: _) =
json <$> getConversations zusr range size json <$> getConversations zusr range size
getConversations :: UserId -> Maybe (Either (Range 1 32 (List OpaqueConvId)) Opa queConvId) -> Range 1 500 Int32 -> Galley (Public.ConversationList Public.Conver sation) getConversations :: UserId -> Maybe (Either (Range 1 32 (List OpaqueConvId)) Opa queConvId) -> Range 1 500 Int32 -> Galley (Public.ConversationList Public.Conver sation)
getConversations zusr range size = getConversations zusr range size =
withConvIds zusr range size $ \more ids -> do withConvIds zusr range size $ \more ids -> do
(localConvIds, _qualifiedConvIds) <- partitionMappedOrLocalIds <$> traverse resolveOpaqueConvId ids let (localConvIds, _qualifiedConvIds) = partitionMappedOrLocalIds ids
-- FUTUREWORK(federation, #1273): fetch remote conversations from other back end -- FUTUREWORK(federation, #1273): fetch remote conversations from other back end
cs <- cs <-
Data.conversations localConvIds Data.conversations localConvIds
>>= filterM removeDeleted >>= filterM removeDeleted
>>= filterM (pure . isMember (makeIdOpaque zusr) . Data.convMembers) >>= filterM (pure . isMember (Local zusr) . Data.convMembers)
flip Public.ConversationList more <$> mapM (conversationView zusr) cs flip Public.ConversationList more <$> mapM (Mapping.conversationView (Local
zusr)) cs
where where
removeDeleted c removeDeleted c
| Data.isConvDeleted c = Data.deleteConversation (Data.convId c) >> pure F alse | Data.isConvDeleted c = Data.deleteConversation (Data.convId c) >> pure F alse
| otherwise = pure True | otherwise = pure True
getSelfH :: UserId ::: ConvId -> Galley Response getSelfH :: UserId ::: ConvId -> Galley Response
getSelfH (zusr ::: cnv) = do getSelfH (zusr ::: cnv) = do
json <$> getSelf zusr cnv json <$> getSelf zusr cnv
getSelf :: UserId -> ConvId -> Galley (Maybe Public.Member) getSelf :: UserId -> ConvId -> Galley (Maybe Public.Member)
getSelf zusr cnv = getSelf zusr cnv =
internalGetMember cnv zusr internalGetMember cnv zusr
internalGetMemberH :: ConvId ::: UserId -> Galley Response internalGetMemberH :: ConvId ::: UserId -> Galley Response
internalGetMemberH (cnv ::: usr) = do internalGetMemberH (cnv ::: usr) = do
json <$> internalGetMember cnv usr json <$> internalGetMember cnv usr
internalGetMember :: ConvId -> UserId -> Galley (Maybe Member) internalGetMember :: ConvId -> UserId -> Galley (Maybe Public.Member)
internalGetMember cnv usr = do internalGetMember cnv usr = do
alive <- Data.isConvAlive cnv alive <- Data.isConvAlive cnv
if alive if alive
then Data.member cnv usr then do
fmap Mapping.toMember <$> Data.member cnv usr
else do else do
Data.deleteConversation cnv Data.deleteConversation cnv
pure Nothing pure Nothing
getConversationMetaH :: ConvId -> Galley Response getConversationMetaH :: ConvId -> Galley Response
getConversationMetaH cnv = do getConversationMetaH cnv = do
getConversationMeta cnv <&> \case getConversationMeta cnv <&> \case
Nothing -> setStatus status404 empty Nothing -> setStatus status404 empty
Just meta -> json meta Just meta -> json meta
skipping to change at line 171 skipping to change at line 174
-- * an (exclusive) starting point (conversation ID) and size -- * an (exclusive) starting point (conversation ID) and size
-- * a list of conversation IDs -- * a list of conversation IDs
-- --
-- The last case returns those conversation IDs which have an associated -- The last case returns those conversation IDs which have an associated
-- user. Additionally 'k' is passed in a 'hasMore' indication (which is -- user. Additionally 'k' is passed in a 'hasMore' indication (which is
-- always false if the third lookup-case is used). -- always false if the third lookup-case is used).
withConvIds :: withConvIds ::
UserId -> UserId ->
Maybe (Either (Range 1 32 (List OpaqueConvId)) OpaqueConvId) -> Maybe (Either (Range 1 32 (List OpaqueConvId)) OpaqueConvId) ->
Range 1 500 Int32 -> Range 1 500 Int32 ->
(Bool -> [OpaqueConvId] -> Galley a) -> (Bool -> [MappedOrLocalId Id.C] -> Galley a) ->
Galley a Galley a
withConvIds usr range size k = case range of withConvIds usr range size k = case range of
Nothing -> do Nothing -> do
r <- Data.conversationIdsFrom usr Nothing (rcast size) r <- Data.conversationIdsFrom usr Nothing (rcast size)
k (Data.resultSetType r == Data.ResultSetTruncated) (Data.resultSetResult r) k (Data.resultSetType r == Data.ResultSetTruncated) (Data.resultSetResult r)
Just (Right c) -> do Just (Right c) -> do
r <- Data.conversationIdsFrom usr (Just c) (rcast size) r <- Data.conversationIdsFrom usr (Just c) (rcast size)
k (Data.resultSetType r == Data.ResultSetTruncated) (Data.resultSetResult r) k (Data.resultSetType r == Data.ResultSetTruncated) (Data.resultSetResult r)
Just (Left cc) -> do Just (Left cc) -> do
ids <- Data.conversationIdsOf usr cc ids <- Data.conversationIdsOf usr cc
 End of changes. 11 change blocks. 
15 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)