Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cassandra-schema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ CREATE TABLE galley_test.meta (
CREATE TABLE galley_test.team_conv (
team uuid,
conv uuid,
managed boolean,
PRIMARY KEY (team, conv)
) WITH CLUSTERING ORDER BY (conv ASC)
AND bloom_filter_fp_chance = 0.1
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1-api-changes/drop-managed-conv-json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Conversation endpoints no longer support the `managed` flag in their JSON form
1 change: 1 addition & 0 deletions changelog.d/5-internal/drop-managed-db-schema
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop the `managed` column from `team_conv` table in Galley
1 change: 0 additions & 1 deletion docs/src/developer/reference/conversation.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export WIRE_CONV='{
"users": [],
"name": "'${WIRE_CONV_NAME}'",
"team": {
"managed": false,
"teamid": "'${WIRE_TEAMID}'"
},
"receipt_mode": 0,
Expand Down
4 changes: 2 additions & 2 deletions libs/wire-api/src/Wire/API/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ newtype ConvTeamInfo = ConvTeamInfo
}
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform ConvTeamInfo)
deriving (FromJSON, ToJSON, S.ToSchema) via Schema ConvTeamInfo
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema ConvTeamInfo)

instance ToSchema ConvTeamInfo where
schema =
Expand All @@ -746,7 +746,7 @@ modelTeamInfo = Doc.defineModel "TeamInfo" $ do
Doc.property "teamid" Doc.bytes' $
Doc.description "Team ID"
Doc.property "managed" Doc.bool' $
Doc.description "Is this a managed team conversation?"
Doc.description "(Not parsed any more) Is this a managed team conversation?"
Comment thread
mdimjasevic marked this conversation as resolved.
Outdated

--------------------------------------------------------------------------------
-- invite
Expand Down
32 changes: 30 additions & 2 deletions libs/wire-api/src/Wire/API/Routes/Public/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -873,20 +873,48 @@ type TeamConversationAPI =
:> "roles"
:> Get '[Servant.JSON] ConversationRolesList
)
:<|> Named
"get-team-conversations-v1"
( Summary "Get team conversations"
:> Until 'V2
:> CanThrow OperationDenied
:> CanThrow 'NotATeamMember
:> ZUser
:> "teams"
:> Capture "tid" TeamId
:> "conversations"
:> Get '[Servant.JSON] (TeamConversationList (Until 'V2))
)
:<|> Named
"get-team-conversations"
( Summary "Get team conversations"
:> From 'V2
:> CanThrow OperationDenied
:> CanThrow 'NotATeamMember
:> ZUser
:> "teams"
:> Capture "tid" TeamId
:> "conversations"
:> Get '[Servant.JSON] (TeamConversationList (From 'V2))
)
:<|> Named
"get-team-conversation-v1"
( Summary "Get one team conversation"
:> Until 'V2
:> CanThrow 'ConvNotFound
:> CanThrow OperationDenied
:> CanThrow 'NotATeamMember
:> ZUser
:> "teams"
:> Capture "tid" TeamId
:> "conversations"
:> Get '[Servant.JSON] TeamConversationList
:> Capture "cid" ConvId
:> Get '[Servant.JSON] (TeamConversation (Until 'V2))
)
:<|> Named
"get-team-conversation"
( Summary "Get one team conversation"
:> From 'V2
:> CanThrow 'ConvNotFound
:> CanThrow OperationDenied
:> CanThrow 'NotATeamMember
Expand All @@ -895,7 +923,7 @@ type TeamConversationAPI =
:> Capture "tid" TeamId
:> "conversations"
:> Capture "cid" ConvId
:> Get '[Servant.JSON] TeamConversation
:> Get '[Servant.JSON] (TeamConversation (From 'V2))
)
:<|> Named
"delete-team-conversation"
Expand Down
160 changes: 110 additions & 50 deletions libs/wire-api/src/Wire/API/Team/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,76 +36,143 @@ module Wire.API.Team.Conversation
)
where

import Control.Lens (At (at), makeLenses, over, (?~))
import Data.Aeson hiding (fieldLabelModifier)
import Control.Lens (makeLenses, (?~))
import qualified Data.Aeson as A
import Data.Id (ConvId)
import Data.Proxy
import Data.Swagger
import Data.Schema
import qualified Data.Swagger as S
import qualified Data.Swagger.Build.Api as Doc
import Imports
import Wire.API.Routes.Version
import Wire.Arbitrary (Arbitrary, GenericUniform (..))

--------------------------------------------------------------------------------
-- TeamConversation

newtype TeamConversation = TeamConversation
-- FUTUREWORK: The version tag type argument can be dropped as soon as versions
-- below V2 are not supported any more.
newtype TeamConversation (v :: *) = TeamConversation
Comment thread
mdimjasevic marked this conversation as resolved.
Outdated
{ _conversationId :: ConvId
}
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform TeamConversation)

instance ToSchema TeamConversation where
declareNamedSchema _ = do
idSchema <- declareSchemaRef (Proxy @ConvId)
pure $
NamedSchema (Just "TeamConversation") $
mempty
& description ?~ "team conversation data"
& over
properties
(at "conversation" ?~ idSchema)

newTeamConversation :: ConvId -> TeamConversation
deriving (Arbitrary) via (GenericUniform (TeamConversation v))

instance ToSchema (TeamConversation (Until 'V2)) where
schema =
objectWithDocModifier
"TeamConversation"
(description ?~ "Team conversation data")
$ TeamConversation
<$> _conversationId .= field "conversation" schema
<* const ()
.= fieldWithDocModifier
"managed"
(description ?~ "(Not parsed any more) Whether this is a managed team conversation")
(c (False :: Bool))
where
c :: A.ToJSON a => a -> ValueSchema SwaggerDoc ()
c val = mkSchema mempty (const (pure ())) (const (pure (A.toJSON val)))

instance ToSchema (TeamConversation (From 'V2)) where
schema =
objectWithDocModifier
"TeamConversation"
(description ?~ "Team conversation data")
$ TeamConversation
<$> _conversationId .= field "conversation" schema

deriving via
Schema (TeamConversation (Until 'V2))
instance
A.FromJSON (TeamConversation (Until 'V2))

deriving via
Schema (TeamConversation (Until 'V2))
instance
A.ToJSON (TeamConversation (Until 'V2))

deriving via
Schema (TeamConversation (From 'V2))
instance
A.FromJSON (TeamConversation (From 'V2))

deriving via
Schema (TeamConversation (From 'V2))
instance
A.ToJSON (TeamConversation (From 'V2))

deriving via
Schema (TeamConversation (Until 'V2))
instance
S.ToSchema (TeamConversation (Until 'V2))

deriving via
Schema (TeamConversation (From 'V2))
instance
S.ToSchema (TeamConversation (From 'V2))

newTeamConversation :: ConvId -> TeamConversation v
newTeamConversation = TeamConversation

modelTeamConversation :: Doc.Model
modelTeamConversation = Doc.defineModel "TeamConversation" $ do
Doc.description "team conversation data"
Doc.property "conversation" Doc.bytes' $
Doc.description "conversation ID"

instance ToJSON TeamConversation where
toJSON t =
object
[ "conversation" .= _conversationId t,
-- FUTUREWORK: get rid of the "managed" field in the next version of the API
"managed" .= False
]

instance FromJSON TeamConversation where
parseJSON = withObject "team conversation" $ \o ->
TeamConversation <$> o .: "conversation"
Doc.property "managed" Doc.bytes' $
Doc.description "Whether the conversation is managed (deprecated)"

--------------------------------------------------------------------------------
-- TeamConversationList

newtype TeamConversationList = TeamConversationList
{ _teamConversations :: [TeamConversation]
-- FUTUREWORK: The version tag type argument can be dropped as soon as versions
-- below V2 are not supported any more.
newtype TeamConversationList (v :: *) = TeamConversationList
{ _teamConversations :: [TeamConversation v]
}
deriving (Generic)
deriving stock (Eq, Show)
deriving newtype (Arbitrary)

instance ToSchema TeamConversationList where
declareNamedSchema _ = do
convs <- declareSchema (Proxy @[TeamConversation])
pure $
NamedSchema (Just "TeamConversationList") $
mempty
& description ?~ "team conversation list"
& properties . at "conversations" ?~ Inline convs

newTeamConversationList :: [TeamConversation] -> TeamConversationList
instance ToSchema (TeamConversation v) => ToSchema (TeamConversationList v) where
schema =
objectWithDocModifier
"TeamConversationList"
(description ?~ "Team conversation list")
$ TeamConversationList
<$> _teamConversations .= field "conversations" (array schema)

deriving via
Schema (TeamConversationList (Until 'V2))
instance
A.FromJSON (TeamConversationList (Until 'V2))

deriving via
Schema (TeamConversationList (Until 'V2))
instance
A.ToJSON (TeamConversationList (Until 'V2))

deriving via
Schema (TeamConversationList (From 'V2))
instance
A.FromJSON (TeamConversationList (From 'V2))

deriving via
Schema (TeamConversationList (From 'V2))
instance
A.ToJSON (TeamConversationList (From 'V2))

deriving via
Schema (TeamConversationList (Until 'V2))
instance
S.ToSchema (TeamConversationList (Until 'V2))

deriving via
Schema (TeamConversationList (From 'V2))
instance
S.ToSchema (TeamConversationList (From 'V2))

newTeamConversationList :: [TeamConversation v] -> TeamConversationList v
newTeamConversationList = TeamConversationList

modelTeamConversationList :: Doc.Model
Expand All @@ -114,12 +181,5 @@ modelTeamConversationList = Doc.defineModel "TeamConversationListList" $ do
Doc.property "conversations" (Doc.unique $ Doc.array (Doc.ref modelTeamConversation)) $
Doc.description "the array of team conversations"

instance ToJSON TeamConversationList where
toJSON t = object ["conversations" .= _teamConversations t]

instance FromJSON TeamConversationList where
parseJSON = withObject "team conversation list" $ \o -> do
TeamConversationList <$> o .: "conversations"

makeLenses ''TeamConversation
makeLenses ''TeamConversationList
Loading