-
Notifications
You must be signed in to change notification settings - Fork 332
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
Changes from 13 commits
87b58a3
a823aa5
3aac5e8
f7585f6
8d5dd58
2905948
341e781
6cd4ab8
c91f17a
aa03aeb
8f35026
66052fa
18b84dd
29d2278
7d20f8b
43fb201
32eab4b
19692d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,27 +65,23 @@ 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 | ||
|
|
||
| -- TODO remove | ||
| modelConnectionList :: Doc.Model | ||
| modelConnectionList = Doc.defineModel "UserConnectionList" $ do | ||
| Doc.description "A list of user connections." | ||
| Doc.property "connections" (Doc.unique $ Doc.array (Doc.ref modelConnection)) Doc.end | ||
| 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,12 +96,23 @@ 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.opt (P.field "conversation" P.schema) | ||
|
jschaul marked this conversation as resolved.
Outdated
|
||
|
|
||
| -- TODO remove | ||
|
jschaul marked this conversation as resolved.
Outdated
|
||
| modelConnection :: Doc.Model | ||
| modelConnection = Doc.defineModel "Connection" $ do | ||
| Doc.description "Directed connection between two users" | ||
|
|
@@ -127,27 +131,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 +148,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 +198,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 +233,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 +241,37 @@ 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? | ||
|
Contributor
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 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).
Member
Author
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 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. |
||
| 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 | ||
|
Contributor
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 | ||
|
|
||
| -- TODO remove | ||
|
jschaul marked this conversation as resolved.
Outdated
|
||
| 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" | ||
Uh oh!
There was an error while loading. Please reload this page.