Write support for sending state key

pull/1/head
Bram van den Heuvel 2023-02-09 19:09:50 +01:00
parent 1fcb754e55
commit e8c0345290
32 changed files with 70 additions and 504 deletions

View File

@ -31,7 +31,7 @@ sendMessageEvent =
{-| Send a state event into a Matrix room. {-| Send a state event into a Matrix room.
-} -}
sendStateEvent : List String -> SendStateKey.SendStateKeyInput -> SendStateKey.SendStateKeyOutput sendStateEvent : List String -> Maybe (SendStateKey.SendStateKeyInput -> SendStateKey.SendStateKeyOutput)
sendStateEvent = sendStateEvent =
SendStateKey.sendStateKey SendStateKey.sendStateKey

View File

@ -13,6 +13,7 @@ sendMessageEvent versions =
|> VC.sameForVersion "r0.1.0" |> VC.sameForVersion "r0.1.0"
|> VC.sameForVersion "r0.2.0" |> VC.sameForVersion "r0.2.0"
|> VC.sameForVersion "r0.3.0" |> VC.sameForVersion "r0.3.0"
|> VC.sameForVersion "r0.4.0"
|> VC.sameForVersion "r0.5.0" |> VC.sameForVersion "r0.5.0"
|> VC.sameForVersion "r0.6.0" |> VC.sameForVersion "r0.6.0"
|> VC.sameForVersion "r0.6.1" |> VC.sameForVersion "r0.6.1"

View File

@ -1,6 +1,7 @@
module Internal.Api.SendStateKey.Api exposing (..) module Internal.Api.SendStateKey.Api exposing (..)
import Internal.Api.Request as R import Internal.Api.Request as R
import Internal.Api.SendStateKey.V1.SpecObjects as SO1
import Internal.Tools.Exceptions as X import Internal.Tools.Exceptions as X
import Json.Decode as D import Json.Decode as D
import Task exposing (Task) import Task exposing (Task)
@ -15,9 +16,31 @@ type alias SendStateKeyInputV1 =
, stateKey : String , stateKey : String
} }
type alias SendStateKeyOutputV1 =
Task X.Error SO1.EventResponse
sendStateKeyV1 : D.Decoder a -> (a -> b) -> SendStateKeyInputV1 -> Task X.Error b
sendStateKeyV1 decoder mapping data = sendStateKeyV1 : SendStateKeyInputV1 -> SendStateKeyOutputV1
sendStateKeyV1 data =
R.rawApiCall
{ headers = R.WithAccessToken data.accessToken
, method = "PUT"
, baseUrl = data.baseUrl
, path = "/_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}"
, pathParams =
[ ( "eventType", data.eventType )
, ( "roomId", data.roomId )
, ( "stateKey", data.stateKey )
]
, queryParams = []
, bodyParams = [ R.RequiredValue "*" data.content ]
, timeout = Nothing
, decoder = \_ -> SO1.eventResponseDecoder
}
sendStateKeyV2 : SendStateKeyInputV1 -> SendStateKeyOutputV1
sendStateKeyV2 data =
R.rawApiCall R.rawApiCall
{ headers = R.WithAccessToken data.accessToken { headers = R.WithAccessToken data.accessToken
, method = "PUT" , method = "PUT"
@ -31,5 +54,5 @@ sendStateKeyV1 decoder mapping data =
, queryParams = [] , queryParams = []
, bodyParams = [ R.RequiredValue "*" data.content ] , bodyParams = [ R.RequiredValue "*" data.content ]
, timeout = Nothing , timeout = Nothing
, decoder = \_ -> D.map mapping decoder , decoder = \_ -> SO1.eventResponseDecoder
} }

View File

@ -1,23 +1,34 @@
module Internal.Api.SendStateKey.Main exposing (..) module Internal.Api.SendStateKey.Main exposing (..)
import Internal.Api.SendStateKey.Api as Api import Internal.Api.SendStateKey.Api as Api
import Internal.Api.SendStateKey.V1_2.Api as V1_2 import Internal.Tools.VersionControl as VC
import Internal.Api.SendStateKey.V1_3.Api as V1_3
import Internal.Api.SendStateKey.V1_4.Api as V1_4
import Internal.Api.SendStateKey.V1_5.Api as V1_5
import Internal.Api.SendStateKey.V1_5.Objects as O
import Internal.Api.VersionControl as V
import Internal.Tools.Exceptions as X
import Task exposing (Task)
sendStateKey : List String -> SendStateKeyInput -> SendStateKeyOutput sendStateKey : List String -> Maybe (SendStateKeyInput -> SendStateKeyOutput)
sendStateKey = sendStateKey versions =
V.firstVersion V1_2.packet VC.withBottomLayer
|> V.updateWith V1_3.packet { current = Api.sendStateKeyV1
|> V.updateWith V1_4.packet , version = "r0.0.0"
|> V.updateWith V1_5.packet }
|> V.toFunction |> VC.sameForVersion "r0.0.1"
|> VC.sameForVersion "r0.1.0"
|> VC.sameForVersion "r0.2.0"
|> VC.sameForVersion "r0.3.0"
|> VC.sameForVersion "r0.4.0"
|> VC.sameForVersion "r0.5.0"
|> VC.sameForVersion "r0.6.0"
|> VC.sameForVersion "r0.6.1"
|> VC.addMiddleLayer
{ downcast = identity
, current = Api.sendStateKeyV2
, upcast = identity
, version = "v1.1"
}
|> VC.sameForVersion "v1.2"
|> VC.sameForVersion "v1.3"
|> VC.sameForVersion "v1.4"
|> VC.sameForVersion "v1.5"
|> VC.mostRecentFromVersionList versions
type alias SendStateKeyInput = type alias SendStateKeyInput =
@ -25,4 +36,4 @@ type alias SendStateKeyInput =
type alias SendStateKeyOutput = type alias SendStateKeyOutput =
Task X.Error O.EventResponse Api.SendStateKeyOutputV1

View File

@ -1,38 +1,37 @@
module Internal.Api.SendStateKey.V1_3.Objects exposing module Internal.Api.SendStateKey.V1.SpecObjects exposing (
( EventResponse EventResponse
, encodeEventResponse , encodeEventResponse
, eventResponseDecoder , eventResponseDecoder
) )
{-| Automatically generated 'SpecObjects' {-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712 Last generated at Unix time 1675965633
-} -}
import Internal.Tools.EncodeExtra exposing (maybeObject) import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D import Json.Decode as D
import Json.Encode as E import Json.Encode as E
{-| A response confirming that an event has been sent. {-| A response confirming that an event has been sent.
-} -}
type alias EventResponse = type alias EventResponse = {
{ eventId : String eventId : String
} }
encodeEventResponse : EventResponse -> E.Value encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data = encodeEventResponse data =
maybeObject maybeObject [
[ ( "event_id", Just <| E.string data.eventId ) ("event_id", Just <| E.string data.eventId)
] ]
eventResponseDecoder : D.Decoder EventResponse eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder = eventResponseDecoder =
D.map D.map
(\a -> (\a ->
{ eventId = a } { eventId=a})
) (D.field "event_id" D.string)
(D.field "event_id" D.string)

View File

@ -1,4 +1,4 @@
version: v1.2 version: v1
name: SpecObjects name: SpecObjects
objects: objects:
EventResponse: EventResponse:

View File

@ -1,16 +0,0 @@
module Internal.Api.SendStateKey.V1_2.Api exposing (..)
import Internal.Api.SendStateKey.Api as Api
import Internal.Api.SendStateKey.V1_2.Convert as C
import Internal.Api.SendStateKey.V1_2.Objects as O
import Internal.Api.SendStateKey.V1_2.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion () () Api.SendStateKeyInputV1 O.EventResponse
packet =
{ version = "v1.2"
, downcast = \_ -> ()
, current = Api.sendStateKeyV1 O.eventResponseDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_2.Convert exposing (..)
import Internal.Api.SendStateKey.V1_2.Objects as O
import Internal.Api.SendStateKey.V1_2.SpecObjects as SO
convert : SO.EventResponse -> O.EventResponse
convert =
identity

View File

@ -1,38 +0,0 @@
module Internal.Api.SendStateKey.V1_2.Objects exposing
( EventResponse
, encodeEventResponse
, eventResponseDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| A response confirming that an event has been sent.
-}
type alias EventResponse =
{ eventId : String
}
encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data =
maybeObject
[ ( "event_id", Just <| E.string data.eventId )
]
eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder =
D.map
(\a ->
{ eventId = a }
)
(D.field "event_id" D.string)

View File

@ -1,9 +0,0 @@
version: v1.2
name: SpecObjects
objects:
EventResponse:
description: A response confirming that an event has been sent.
fields:
event_id:
type: string
required: true

View File

@ -1,38 +0,0 @@
module Internal.Api.SendStateKey.V1_2.SpecObjects exposing
( EventResponse
, encodeEventResponse
, eventResponseDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| A response confirming that an event has been sent.
-}
type alias EventResponse =
{ eventId : String
}
encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data =
maybeObject
[ ( "event_id", Just <| E.string data.eventId )
]
eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder =
D.map
(\a ->
{ eventId = a }
)
(D.field "event_id" D.string)

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_2.Upcast exposing (..)
import Internal.Api.SendStateKey.V1_2.Objects as O
import Internal.Config.Leaking as L
upcast : () -> O.EventResponse
upcast _ =
{ eventId = L.eventId }

View File

@ -1,17 +0,0 @@
module Internal.Api.SendStateKey.V1_3.Api exposing (..)
import Internal.Api.SendStateKey.Api as Api
import Internal.Api.SendStateKey.V1_2.Objects as PO
import Internal.Api.SendStateKey.V1_3.Convert as C
import Internal.Api.SendStateKey.V1_3.Objects as O
import Internal.Api.SendStateKey.V1_3.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion Api.SendStateKeyInputV1 PO.EventResponse Api.SendStateKeyInputV1 O.EventResponse
packet =
{ version = "v1.3"
, downcast = identity
, current = Api.sendStateKeyV1 O.eventResponseDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_3.Convert exposing (..)
import Internal.Api.SendStateKey.V1_3.Objects as O
import Internal.Api.SendStateKey.V1_3.SpecObjects as SO
convert : SO.EventResponse -> O.EventResponse
convert =
identity

View File

@ -1,9 +0,0 @@
version: v1.3
name: SpecObjects
objects:
EventResponse:
description: A response confirming that an event has been sent.
fields:
event_id:
type: string
required: true

View File

@ -1,38 +0,0 @@
module Internal.Api.SendStateKey.V1_3.SpecObjects exposing
( EventResponse
, encodeEventResponse
, eventResponseDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| A response confirming that an event has been sent.
-}
type alias EventResponse =
{ eventId : String
}
encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data =
maybeObject
[ ( "event_id", Just <| E.string data.eventId )
]
eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder =
D.map
(\a ->
{ eventId = a }
)
(D.field "event_id" D.string)

View File

@ -1,9 +0,0 @@
version: v1.3
name: SpecObjects
objects:
EventResponse:
description: A response confirming that an event has been sent.
fields:
event_id:
type: string
required: true

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_3.Upcast exposing (..)
import Internal.Api.SendStateKey.V1_2.Objects as PO
import Internal.Api.SendStateKey.V1_3.Objects as O
upcast : PO.EventResponse -> O.EventResponse
upcast =
identity

View File

@ -1,17 +0,0 @@
module Internal.Api.SendStateKey.V1_4.Api exposing (..)
import Internal.Api.SendStateKey.Api as Api
import Internal.Api.SendStateKey.V1_3.Objects as PO
import Internal.Api.SendStateKey.V1_4.Convert as C
import Internal.Api.SendStateKey.V1_4.Objects as O
import Internal.Api.SendStateKey.V1_4.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion Api.SendStateKeyInputV1 PO.EventResponse Api.SendStateKeyInputV1 O.EventResponse
packet =
{ version = "v1.4"
, downcast = identity
, current = Api.sendStateKeyV1 O.eventResponseDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_4.Convert exposing (..)
import Internal.Api.SendStateKey.V1_4.Objects as O
import Internal.Api.SendStateKey.V1_4.SpecObjects as SO
convert : SO.EventResponse -> O.EventResponse
convert =
identity

View File

@ -1,38 +0,0 @@
module Internal.Api.SendStateKey.V1_4.Objects exposing
( EventResponse
, encodeEventResponse
, eventResponseDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| A response confirming that an event has been sent.
-}
type alias EventResponse =
{ eventId : String
}
encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data =
maybeObject
[ ( "event_id", Just <| E.string data.eventId )
]
eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder =
D.map
(\a ->
{ eventId = a }
)
(D.field "event_id" D.string)

View File

@ -1,9 +0,0 @@
version: v1.4
name: SpecObjects
objects:
EventResponse:
description: A response confirming that an event has been sent.
fields:
event_id:
type: string
required: true

View File

@ -1,38 +0,0 @@
module Internal.Api.SendStateKey.V1_4.SpecObjects exposing
( EventResponse
, encodeEventResponse
, eventResponseDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| A response confirming that an event has been sent.
-}
type alias EventResponse =
{ eventId : String
}
encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data =
maybeObject
[ ( "event_id", Just <| E.string data.eventId )
]
eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder =
D.map
(\a ->
{ eventId = a }
)
(D.field "event_id" D.string)

View File

@ -1,9 +0,0 @@
version: v1.4
name: SpecObjects
objects:
EventResponse:
description: A response confirming that an event has been sent.
fields:
event_id:
type: string
required: true

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_4.Upcast exposing (..)
import Internal.Api.SendStateKey.V1_3.Objects as PO
import Internal.Api.SendStateKey.V1_4.Objects as O
upcast : PO.EventResponse -> O.EventResponse
upcast =
identity

View File

@ -1,17 +0,0 @@
module Internal.Api.SendStateKey.V1_5.Api exposing (..)
import Internal.Api.SendStateKey.Api as Api
import Internal.Api.SendStateKey.V1_4.Objects as PO
import Internal.Api.SendStateKey.V1_5.Convert as C
import Internal.Api.SendStateKey.V1_5.Objects as O
import Internal.Api.SendStateKey.V1_5.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion Api.SendStateKeyInputV1 PO.EventResponse Api.SendStateKeyInputV1 O.EventResponse
packet =
{ version = "v1.5"
, downcast = identity
, current = Api.sendStateKeyV1 O.eventResponseDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_5.Convert exposing (..)
import Internal.Api.SendStateKey.V1_5.Objects as O
import Internal.Api.SendStateKey.V1_5.SpecObjects as SO
convert : SO.EventResponse -> O.EventResponse
convert =
identity

View File

@ -1,38 +0,0 @@
module Internal.Api.SendStateKey.V1_5.Objects exposing
( EventResponse
, encodeEventResponse
, eventResponseDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| A response confirming that an event has been sent.
-}
type alias EventResponse =
{ eventId : String
}
encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data =
maybeObject
[ ( "event_id", Just <| E.string data.eventId )
]
eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder =
D.map
(\a ->
{ eventId = a }
)
(D.field "event_id" D.string)

View File

@ -1,9 +0,0 @@
version: v1.5
name: SpecObjects
objects:
EventResponse:
description: A response confirming that an event has been sent.
fields:
event_id:
type: string
required: true

View File

@ -1,38 +0,0 @@
module Internal.Api.SendStateKey.V1_5.SpecObjects exposing
( EventResponse
, encodeEventResponse
, eventResponseDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| A response confirming that an event has been sent.
-}
type alias EventResponse =
{ eventId : String
}
encodeEventResponse : EventResponse -> E.Value
encodeEventResponse data =
maybeObject
[ ( "event_id", Just <| E.string data.eventId )
]
eventResponseDecoder : D.Decoder EventResponse
eventResponseDecoder =
D.map
(\a ->
{ eventId = a }
)
(D.field "event_id" D.string)

View File

@ -1,9 +0,0 @@
version: v1.5
name: SpecObjects
objects:
EventResponse:
description: A response confirming that an event has been sent.
fields:
event_id:
type: string
required: true

View File

@ -1,9 +0,0 @@
module Internal.Api.SendStateKey.V1_5.Upcast exposing (..)
import Internal.Api.SendStateKey.V1_4.Objects as PO
import Internal.Api.SendStateKey.V1_5.Objects as O
upcast : PO.EventResponse -> O.EventResponse
upcast =
identity