Skip to content

Commit

Permalink
Version conversation listing endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti committed Nov 17, 2022
1 parent 43e40b0 commit e16e7bb
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 21 deletions.
28 changes: 18 additions & 10 deletions libs/wire-api/src/Wire/API/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,25 @@ data ConversationsResponse = ConversationsResponse
deriving stock (Eq, Show)
deriving (FromJSON, ToJSON, S.ToSchema) via Schema ConversationsResponse

conversationsResponseSchema ::
ObjectSchema SwaggerDoc (Set AccessRole) ->
ValueSchema NamedSwaggerDoc ConversationsResponse
conversationsResponseSchema sch =
let notFoundDoc = description ?~ "These conversations either don't exist or are deleted."
failedDoc = description ?~ "The server failed to fetch these conversations, most likely due to network issues while contacting a remote server"
in objectWithDocModifier
"ConversationsResponse"
(description ?~ "Response object for getting metadata of a list of conversations")
$ ConversationsResponse
<$> crFound .= field "found" (array (conversationSchema sch))
<*> crNotFound .= fieldWithDocModifier "not_found" notFoundDoc (array schema)
<*> crFailed .= fieldWithDocModifier "failed" failedDoc (array schema)

instance ToSchema ConversationsResponse where
schema =
let notFoundDoc = description ?~ "These conversations either don't exist or are deleted."
failedDoc = description ?~ "The server failed to fetch these conversations, most likely due to network issues while contacting a remote server"
in objectWithDocModifier
"ConversationsResponse"
(description ?~ "Response object for getting metadata of a list of conversations")
$ ConversationsResponse
<$> crFound .= field "found" (array (conversationSchema accessRolesSchemaV2))
<*> crNotFound .= fieldWithDocModifier "not_found" notFoundDoc (array schema)
<*> crFailed .= fieldWithDocModifier "failed" failedDoc (array schema)
schema = conversationsResponseSchema accessRolesSchema

instance ToSchema (Versioned 'V2 ConversationsResponse) where
schema = Versioned <$> unVersioned .= conversationsResponseSchema accessRolesSchemaV2

--------------------------------------------------------------------------------
-- Conversation properties
Expand Down
31 changes: 26 additions & 5 deletions libs/wire-api/src/Wire/API/Routes/Public/Galley/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type ConversationAPI =
:<|> Named
"list-conversation-ids-unqualified"
( Summary "[deprecated] Get all local conversation IDs."
:> Until 'V3
-- FUTUREWORK: add bounds to swagger schema for Range
:> ZLocalUser
:> "conversations"
Expand Down Expand Up @@ -201,6 +202,7 @@ type ConversationAPI =
:<|> Named
"get-conversations"
( Summary "Get all *local* conversations."
:> Until 'V3
:> Description
"Will not return remote conversations.\n\n\
\Use `POST /conversations/list-ids` followed by \
Expand Down Expand Up @@ -239,15 +241,34 @@ type ConversationAPI =
)
)
:<|> Named
"list-conversations-v1"
"list-conversations@v1"
( Summary "Get conversation metadata for a list of conversation ids"
:> Until 'V2
:> ZLocalUser
:> "conversations"
:> "list"
:> "v2"
:> ReqBody '[Servant.JSON] ListConversations
:> Post '[Servant.JSON] ConversationsResponse
:> ReqBody '[JSON] ListConversations
:> Post '[JSON] ConversationsResponse
)
:<|> Named
"list-conversations@v2"
( Summary "Get conversation metadata for a list of conversation ids"
:> From 'V2
:> Until 'V3
:> ZLocalUser
:> "conversations"
:> "list"
:> ReqBody '[JSON] ListConversations
:> MultiVerb1
'POST
'[JSON]
( VersionedRespond
'V2
200
"Conversation page"
ConversationsResponse
)
)
:<|> Named
"list-conversations"
Expand All @@ -256,8 +277,8 @@ type ConversationAPI =
:> ZLocalUser
:> "conversations"
:> "list"
:> ReqBody '[Servant.JSON] ListConversations
:> Post '[Servant.JSON] ConversationsResponse
:> ReqBody '[JSON] ListConversations
:> Post '[JSON] ConversationsResponse
)
-- This endpoint can lead to the following events being sent:
-- - ConvCreate event to members
Expand Down
3 changes: 2 additions & 1 deletion libs/wire-api/src/Wire/API/Routes/Versioned.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Servant.API.ContentTypes
import Servant.Swagger
import Servant.Swagger.Internal
import Wire.API.Routes.MultiVerb
import Wire.API.Routes.Version

--------------------------------------
-- Versioned requests
Expand Down Expand Up @@ -94,7 +95,7 @@ instance
-- Use this type to provide several JSON/swagger instances for a given type.
-- Use VersionedReqBody and VersionedRespond to select the instance to use in
-- Servant.
newtype Versioned v a = Versioned {unVersioned :: a}
newtype Versioned (v :: Version) a = Versioned {unVersioned :: a}
deriving (Eq, Show)

instance Functor (Versioned v) where
Expand Down
4 changes: 4 additions & 0 deletions libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import Test.Wire.API.Golden.Manual.Token
import Test.Wire.API.Golden.Manual.UserClientPrekeyMap
import Test.Wire.API.Golden.Manual.UserIdList
import Test.Wire.API.Golden.Runner
import Wire.API.Routes.Version
import Wire.API.Routes.Versioned

tests :: TestTree
tests =
Expand Down Expand Up @@ -105,6 +107,8 @@ tests =
testGroup "ListConversations" $
testObjects
[(testObject_ListConversations_1, "testObject_ListConversations_1.json")],
testGroup "ConversationsResponse V2" $
testObjects [(Versioned @'V2 testObject_ConversationsResponse_1, "testObject_ConversationsResponse_v2_1.json")],
testGroup "ConversationsResponse" $
testObjects [(testObject_ConversationsResponse_1, "testObject_ConversationsResponse_1.json")],
testGroup "CreateScimToken" $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"found": [
{
"access": [],
"access_role": "private",
"access_role_v2": [],
"access_role": [],
"creator": "00000001-0000-0001-0000-000200000001",
"id": "00000001-0000-0000-0000-000000000000",
"last_event": "0.0",
Expand Down Expand Up @@ -65,8 +64,7 @@
"private",
"invite"
],
"access_role": "non_activated",
"access_role_v2": [
"access_role": [
"team_member",
"guest",
"service"
Expand Down
124 changes: 124 additions & 0 deletions libs/wire-api/test/golden/testObject_ConversationsResponse_v2_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"failed": [
{
"domain": "golden.example.com",
"id": "00000018-4444-0020-0000-000e00000002"
},
{
"domain": "golden3.example.com",
"id": "99999999-0000-0020-0000-111111111112"
}
],
"found": [
{
"access": [],
"access_role": "private",
"access_role_v2": [],
"creator": "00000001-0000-0001-0000-000200000001",
"id": "00000001-0000-0000-0000-000000000000",
"last_event": "0.0",
"last_event_time": "1970-01-01T00:00:00.000Z",
"members": {
"others": [],
"self": {
"conversation_role": "rhhdzf0j0njilixx0g0vzrp06b_5us",
"hidden": false,
"hidden_ref": "",
"id": "00000001-0000-0001-0000-000100000000",
"otr_archived": false,
"otr_archived_ref": "",
"otr_muted_ref": null,
"otr_muted_status": null,
"qualified_id": {
"domain": "golden.example.com",
"id": "00000001-0000-0001-0000-000100000000"
},
"service": null,
"status": 0,
"status_ref": "0.0",
"status_time": "1970-01-01T00:00:00.000Z"
}
},
"message_timer": null,
"name": " 0",
"protocol": "proteus",
"qualified_id": {
"domain": "golden.example.com",
"id": "00000001-0000-0000-0000-000000000000"
},
"receipt_mode": -2,
"team": "00000001-0000-0001-0000-000100000002",
"type": 2
},
{
"access": [
"invite",
"invite",
"code",
"link",
"invite",
"private",
"link",
"code",
"code",
"link",
"private",
"invite"
],
"access_role": "non_activated",
"access_role_v2": [
"team_member",
"guest",
"service"
],
"cipher_suite": 1,
"creator": "00000000-0000-0000-0000-000200000001",
"epoch": 42,
"group_id": "dGVzdF9ncm91cA==",
"id": "00000000-0000-0000-0000-000000000002",
"last_event": "0.0",
"last_event_time": "1970-01-01T00:00:00.000Z",
"members": {
"others": [],
"self": {
"conversation_role": "9b2d3thyqh4ptkwtq2n2v9qsni_ln1ca66et_z8dlhfs9oamp328knl3rj9kcj",
"hidden": true,
"hidden_ref": "",
"id": "00000000-0000-0001-0000-000100000001",
"otr_archived": false,
"otr_archived_ref": null,
"otr_muted_ref": null,
"otr_muted_status": -1,
"qualified_id": {
"domain": "golden.example.com",
"id": "00000000-0000-0001-0000-000100000001"
},
"service": null,
"status": 0,
"status_ref": "0.0",
"status_time": "1970-01-01T00:00:00.000Z"
}
},
"message_timer": 1319272593797015,
"name": "",
"protocol": "mls",
"qualified_id": {
"domain": "golden.example.com",
"id": "00000000-0000-0000-0000-000000000002"
},
"receipt_mode": 2,
"team": "00000000-0000-0001-0000-000200000000",
"type": 1
}
],
"not_found": [
{
"domain": "golden.example.com",
"id": "00000018-0000-0020-0000-000e00000002"
},
{
"domain": "golden2.example.com",
"id": "00000018-0000-0020-0000-111111111112"
}
]
}
3 changes: 2 additions & 1 deletion services/galley/src/Galley/API/Public/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ conversationAPI =
<@> mkNamedAPI @"list-conversation-ids-unqualified" conversationIdsPageFromUnqualified
<@> mkNamedAPI @"list-conversation-ids" conversationIdsPageFrom
<@> mkNamedAPI @"get-conversations" getConversations
<@> mkNamedAPI @"list-conversations-v1" listConversations
<@> mkNamedAPI @"list-conversations@v1" listConversations
<@> mkNamedAPI @"list-conversations@v2" listConversations
<@> mkNamedAPI @"list-conversations" listConversations
<@> mkNamedAPI @"get-conversation-by-reusable-code" (getConversationByReusableCode @Cassandra)
<@> mkNamedAPI @"create-group-conversation@v2" createGroupConversation
Expand Down

0 comments on commit e16e7bb

Please sign in to comment.