-
Notifications
You must be signed in to change notification settings - Fork 333
Servantify POST /connections endpoint; remove deprecated 'message' field #1726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
87b58a3
WIP servantify existing connections endpoints
jschaul a823aa5
make golden tests compile.
jschaul 3aac5e8
re-generate golden test files
jschaul f7585f6
fix compilations for Message/Range changes
jschaul 8d5dd58
WIP: MultiVerb
jschaul 2905948
better type
jschaul 341e781
make use of multiverb responses in Brig
jschaul 6cd4ab8
ErrorDescription
jschaul c91f17a
add FUTUREWORK
jschaul aa03aeb
Merge branch 'develop' into servantify-connections-endpoint
jschaul 8f35026
changelog
jschaul 66052fa
Fix galley compilation
jschaul 18b84dd
add futurework
jschaul 29d2278
PR review comments
jschaul 7d20f8b
Existed200 -> Existed; Created201 -> Created
jschaul 43fb201
add helper type
jschaul 32eab4b
Merge remote-tracking branch 'origin/develop' into servantify-connect…
jschaul 19692d2
Hi CI
jschaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE StrictData #-} | ||
|
||
-- This file is part of the Wire Server implementation. | ||
|
@@ -26,7 +25,6 @@ module Wire.API.Connection | |
( -- * UserConnection | ||
UserConnection (..), | ||
UserConnectionList (..), | ||
Message (..), | ||
Relation (..), | ||
RelationWithHistory (..), | ||
relationDropHistory, | ||
|
@@ -38,24 +36,23 @@ module Wire.API.Connection | |
-- * Swagger | ||
modelConnectionList, | ||
modelConnection, | ||
modelConnectionRequest, | ||
modelConnectionUpdate, | ||
) | ||
where | ||
|
||
import Data.Aeson | ||
import Data.Aeson.Types (Parser) | ||
import Control.Lens ((?~)) | ||
import Data.Aeson as Aeson | ||
import Data.Attoparsec.ByteString (takeByteString) | ||
import Data.ByteString.Conversion | ||
import Data.Id | ||
import Data.Json.Util (UTCTimeMillis) | ||
import Data.Range | ||
import qualified Data.Schema as P | ||
import qualified Data.Swagger.Build.Api as Doc | ||
import Data.Swagger.Schema | ||
import Data.Swagger.Schema as S | ||
import Data.Text as Text | ||
import Deriving.Swagger (CamelToKebab, ConstructorTagModifier, CustomSwagger) | ||
import Imports | ||
import Wire.API.Arbitrary (Arbitrary (arbitrary), GenericUniform (..)) | ||
import Wire.API.Arbitrary (Arbitrary (..), GenericUniform (..)) | ||
|
||
-------------------------------------------------------------------------------- | ||
-- UserConnectionList | ||
|
@@ -68,6 +65,14 @@ data UserConnectionList = UserConnectionList | |
} | ||
deriving stock (Eq, Show, Generic) | ||
deriving (Arbitrary) via (GenericUniform UserConnectionList) | ||
deriving (FromJSON, ToJSON, S.ToSchema) via (P.Schema UserConnectionList) | ||
|
||
instance P.ToSchema UserConnectionList where | ||
schema = | ||
P.object "UserConnectionList" $ | ||
UserConnectionList | ||
<$> clConnections P..= P.field "connections" (P.array P.schema) | ||
<*> clHasMore P..= P.fieldWithDocModifier "has_more" (P.description ?~ "Indicator that the server has more connections than returned.") P.schema | ||
|
||
modelConnectionList :: Doc.Model | ||
modelConnectionList = Doc.defineModel "UserConnectionList" $ do | ||
|
@@ -76,19 +81,6 @@ modelConnectionList = Doc.defineModel "UserConnectionList" $ do | |
Doc.property "has_more" Doc.bool' $ | ||
Doc.description "Indicator that the server has more connections than returned." | ||
|
||
instance ToJSON UserConnectionList where | ||
toJSON (UserConnectionList l m) = | ||
object | ||
[ "connections" .= l, | ||
"has_more" .= m | ||
] | ||
|
||
instance FromJSON UserConnectionList where | ||
parseJSON = withObject "UserConnectionList" $ \o -> | ||
UserConnectionList | ||
<$> o .: "connections" | ||
<*> o .: "has_more" | ||
|
||
-------------------------------------------------------------------------------- | ||
-- UserConnection | ||
|
||
|
@@ -103,11 +95,21 @@ data UserConnection = UserConnection | |
ucStatus :: Relation, | ||
-- | When 'ucStatus' was last changed | ||
ucLastUpdate :: UTCTimeMillis, | ||
ucMessage :: Maybe Message, | ||
ucConvId :: Maybe ConvId | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
deriving (Arbitrary) via (GenericUniform UserConnection) | ||
deriving (FromJSON, ToJSON, S.ToSchema) via (P.Schema UserConnection) | ||
|
||
instance P.ToSchema UserConnection where | ||
schema = | ||
P.object "UserConnection" $ | ||
UserConnection | ||
<$> ucFrom P..= P.field "from" P.schema | ||
<*> ucTo P..= P.field "to" P.schema | ||
<*> ucStatus P..= P.field "status" P.schema | ||
<*> ucLastUpdate P..= P.field "last_update" P.schema | ||
<*> ucConvId P..= P.optField "conversation" Nothing P.schema | ||
|
||
modelConnection :: Doc.Model | ||
modelConnection = Doc.defineModel "Connection" $ do | ||
|
@@ -127,27 +129,6 @@ modelConnection = Doc.defineModel "Connection" $ do | |
Doc.description "Conversation ID" | ||
Doc.optional | ||
|
||
instance ToJSON UserConnection where | ||
toJSON uc = | ||
object | ||
[ "from" .= ucFrom uc, | ||
"to" .= ucTo uc, | ||
"status" .= ucStatus uc, | ||
"last_update" .= ucLastUpdate uc, | ||
"message" .= ucMessage uc, | ||
"conversation" .= ucConvId uc | ||
] | ||
|
||
instance FromJSON UserConnection where | ||
parseJSON = withObject "user-connection" $ \o -> | ||
UserConnection | ||
<$> o .: "from" | ||
<*> o .: "to" | ||
<*> o .: "status" | ||
<*> o .: "last_update" | ||
<*> o .:? "message" | ||
<*> o .:? "conversation" | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Relation | ||
|
||
|
@@ -165,7 +146,7 @@ data Relation | |
MissingLegalholdConsent | ||
deriving stock (Eq, Ord, Show, Generic) | ||
deriving (Arbitrary) via (GenericUniform Relation) | ||
deriving (ToSchema) via (CustomSwagger '[ConstructorTagModifier CamelToKebab] Relation) | ||
deriving (FromJSON, ToJSON, S.ToSchema) via (P.Schema Relation) | ||
|
||
-- | 'updateConnectionInternal', requires knowledge of the previous state (before | ||
-- 'MissingLegalholdConsent'), but the clients don't need that information. To avoid having | ||
|
@@ -215,29 +196,22 @@ typeRelation = | |
"missing-legalhold-consent" | ||
] | ||
|
||
instance ToJSON Relation where | ||
toJSON = \case | ||
Accepted -> "accepted" | ||
Blocked -> "blocked" | ||
Pending -> "pending" | ||
Ignored -> "ignored" | ||
Sent -> "sent" | ||
Cancelled -> "cancelled" | ||
MissingLegalholdConsent -> "missing-legalhold-consent" | ||
|
||
instance FromJSON Relation where | ||
parseJSON (String "accepted") = return Accepted | ||
parseJSON (String "blocked") = return Blocked | ||
parseJSON (String "pending") = return Pending | ||
parseJSON (String "ignored") = return Ignored | ||
parseJSON (String "sent") = return Sent | ||
parseJSON (String "cancelled") = return Cancelled | ||
parseJSON (String "missing-legalhold-consent") = return MissingLegalholdConsent | ||
parseJSON _ = mzero | ||
instance P.ToSchema Relation where | ||
schema = | ||
P.enum @Text "Relation" $ | ||
mconcat | ||
[ P.element "accepted" Accepted, | ||
P.element "blocked" Blocked, | ||
P.element "pending" Pending, | ||
P.element "ignored" Ignored, | ||
P.element "sent" Sent, | ||
P.element "cancelled" Cancelled, | ||
P.element "missing-legalhold-consent" MissingLegalholdConsent | ||
] | ||
|
||
instance FromByteString Relation where | ||
parser = | ||
takeByteString >>= \b -> case b of | ||
takeByteString >>= \case | ||
"accepted" -> return Accepted | ||
"blocked" -> return Blocked | ||
"pending" -> return Pending | ||
|
@@ -257,21 +231,6 @@ instance ToByteString Relation where | |
Cancelled -> "cancelled" | ||
MissingLegalholdConsent -> "missing-legalhold-consent" | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Message | ||
|
||
-- | Initial message sent along with a connection request. 1-256 characters. | ||
-- | ||
-- /Note 2019-03-28:/ some clients send it, but we have hidden it anyway in the UI since it | ||
-- works as a nice source of spam. TODO deprecate and remove. | ||
newtype Message = Message {messageText :: Text} | ||
deriving stock (Eq, Ord, Show, Generic) | ||
deriving newtype (ToJSON) | ||
deriving (Arbitrary) via (Ranged 1 256 Text) | ||
|
||
instance FromJSON Message where | ||
parseJSON x = Message . fromRange <$> (parseJSON x :: Parser (Range 1 256 Text)) | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Requests | ||
|
||
|
@@ -280,61 +239,36 @@ data ConnectionRequest = ConnectionRequest | |
{ -- | Connection recipient | ||
crUser :: UserId, | ||
-- | Name of the conversation to be created | ||
crName :: Text, | ||
-- | Initial message | ||
crMessage :: Message | ||
-- FUTUREWORK investigate: shouldn't this name be optional? Do we use this name actually anywhere? | ||
crName :: Range 1 256 Text | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
deriving (Arbitrary) via (GenericUniform ConnectionRequest) | ||
deriving (FromJSON, ToJSON, S.ToSchema) via (P.Schema ConnectionRequest) | ||
|
||
modelConnectionRequest :: Doc.Model | ||
modelConnectionRequest = Doc.defineModel "ConnectionRequest" $ do | ||
Doc.description "Connection request from one user to another" | ||
Doc.property "user" Doc.bytes' $ | ||
Doc.description "User ID of the user to request a connection with" | ||
Doc.property "name" Doc.string' $ | ||
Doc.description "Name of the (pending) conversation being initiated (1 - 256 characters)." | ||
Doc.property "message" Doc.string' $ | ||
Doc.description "The initial message in the request (1 - 256 characters)." | ||
|
||
instance ToJSON ConnectionRequest where | ||
toJSON c = | ||
object | ||
[ "user" .= crUser c, | ||
"name" .= crName c, | ||
"message" .= crMessage c | ||
] | ||
|
||
instance FromJSON ConnectionRequest where | ||
parseJSON = withObject "connection-request" $ \o -> | ||
ConnectionRequest | ||
<$> o .: "user" | ||
<*> (fromRange <$> ((o .: "name") :: Parser (Range 1 256 Text))) | ||
<*> o .: "message" | ||
|
||
-- | TODO: make 'crName :: Range 1 256 Text' and derive this instance. | ||
instance Arbitrary ConnectionRequest where | ||
arbitrary = | ||
ConnectionRequest | ||
<$> arbitrary | ||
<*> (fromRange <$> arbitrary @(Range 1 256 Text)) | ||
<*> arbitrary | ||
instance P.ToSchema ConnectionRequest where | ||
schema = | ||
P.object "ConnectionRequest" $ | ||
ConnectionRequest | ||
<$> crUser P..= P.fieldWithDocModifier "user" (P.description ?~ "user ID of the user to request a connection with") P.schema | ||
<*> crName P..= P.fieldWithDocModifier "name" (P.description ?~ "Name of the (pending) conversation being initiated (1 - 256) characters)") P.schema | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not too familiar with connection names and conversation names/titles, but see my previous comment if a connection name is really promoted to a one-to-one conversation title. |
||
|
||
-- | Payload type for "please change the status of this connection". | ||
data ConnectionUpdate = ConnectionUpdate | ||
newtype ConnectionUpdate = ConnectionUpdate | ||
{ cuStatus :: Relation | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
deriving (Arbitrary) via (GenericUniform ConnectionUpdate) | ||
deriving (FromJSON, ToJSON, S.ToSchema) via (P.Schema ConnectionUpdate) | ||
|
||
instance P.ToSchema ConnectionUpdate where | ||
schema = | ||
P.object "ConnectionUpdate" $ | ||
ConnectionUpdate | ||
<$> cuStatus P..= P.fieldWithDocModifier "status" (P.description ?~ "New relation status") P.schema | ||
|
||
modelConnectionUpdate :: Doc.Model | ||
modelConnectionUpdate = Doc.defineModel "ConnectionUpdate" $ do | ||
Doc.description "Connection update" | ||
Doc.property "status" typeRelation $ | ||
Doc.description "New relation status" | ||
|
||
instance ToJSON ConnectionUpdate where | ||
toJSON c = object ["status" .= cuStatus c] | ||
|
||
instance FromJSON ConnectionUpdate where | ||
parseJSON = withObject "connection-update" $ \o -> | ||
ConnectionUpdate <$> o .: "status" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just guessing now, but does a connection name ever make it to a one-to-one conversation title?
Clients have a logic related to conversation titles (e.g., in checking if a group conversation in a team is logically one-to-one conversation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I didn't take the time to look more deeply into how this is used and what clients send and receive and what they do with it. That's why there is a FUTUREWORK here. A potential refactor that removes this can be done in a subsequent PR.