Refactor GetEvent API endpoint
parent
a47d80af9e
commit
a0f19a3fdc
|
@ -10,7 +10,7 @@ import Internal.Api.Versions.Main as Versions
|
||||||
|
|
||||||
{-| Get a specific event from the Matrix API.
|
{-| Get a specific event from the Matrix API.
|
||||||
-}
|
-}
|
||||||
getEvent : List String -> GetEvent.EventInput -> GetEvent.EventOutput
|
getEvent : List String -> Maybe (GetEvent.EventInput -> GetEvent.EventOutput)
|
||||||
getEvent =
|
getEvent =
|
||||||
GetEvent.getEvent
|
GetEvent.getEvent
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
module Internal.Api.GetEvent.Api exposing (..)
|
module Internal.Api.GetEvent.Api exposing (..)
|
||||||
|
|
||||||
|
import Internal.Api.GetEvent.V1.SpecObjects as SO1
|
||||||
import Internal.Api.Request as R
|
import Internal.Api.Request as R
|
||||||
import Internal.Tools.Exceptions as X
|
import Internal.Tools.Exceptions as X
|
||||||
import Json.Decode as D
|
|
||||||
import Task exposing (Task)
|
import Task exposing (Task)
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,8 +14,12 @@ type alias GetEventInputV1 =
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getEventInputV1 : D.Decoder a -> (a -> b) -> GetEventInputV1 -> Task X.Error b
|
type alias GetEventOutputV1 =
|
||||||
getEventInputV1 decoder mapping data =
|
Task X.Error SO1.ClientEvent
|
||||||
|
|
||||||
|
|
||||||
|
getEventInputV1 : GetEventInputV1 -> GetEventOutputV1
|
||||||
|
getEventInputV1 data =
|
||||||
R.rawApiCall
|
R.rawApiCall
|
||||||
{ headers = R.WithAccessToken data.accessToken
|
{ headers = R.WithAccessToken data.accessToken
|
||||||
, method = "GET"
|
, method = "GET"
|
||||||
|
@ -28,5 +32,5 @@ getEventInputV1 decoder mapping data =
|
||||||
, queryParams = []
|
, queryParams = []
|
||||||
, bodyParams = []
|
, bodyParams = []
|
||||||
, timeout = Nothing
|
, timeout = Nothing
|
||||||
, decoder = \_ -> D.map mapping decoder
|
, decoder = \_ -> SO1.clientEventDecoder
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,23 @@
|
||||||
module Internal.Api.GetEvent.Main exposing (..)
|
module Internal.Api.GetEvent.Main exposing (..)
|
||||||
|
|
||||||
import Internal.Api.GetEvent.Api as Api
|
import Internal.Api.GetEvent.Api as Api
|
||||||
import Internal.Api.GetEvent.V1_2.Api as V1_2
|
import Internal.Tools.VersionControl as VC
|
||||||
import Internal.Api.GetEvent.V1_3.Api as V1_3
|
|
||||||
import Internal.Api.GetEvent.V1_4.Api as V1_4
|
|
||||||
import Internal.Api.GetEvent.V1_5.Api as V1_5
|
|
||||||
import Internal.Api.GetEvent.V1_5.Objects as O
|
|
||||||
import Internal.Api.VersionControl as V
|
|
||||||
import Internal.Tools.Exceptions as X
|
|
||||||
import Task exposing (Task)
|
|
||||||
|
|
||||||
|
|
||||||
getEvent : List String -> EventInput -> EventOutput
|
getEvent : List String -> Maybe (EventInput -> EventOutput)
|
||||||
getEvent =
|
getEvent versions =
|
||||||
V.firstVersion V1_2.packet
|
VC.withBottomLayer
|
||||||
|> V.updateWith V1_3.packet
|
{ current = Api.getEventInputV1
|
||||||
|> V.updateWith V1_4.packet
|
, version = "v1.2"
|
||||||
|> V.updateWith V1_5.packet
|
}
|
||||||
|> V.toFunction
|
|> VC.sameForVersion "v1.3"
|
||||||
|
|> VC.sameForVersion "v1.4"
|
||||||
|
|> VC.sameForVersion "v1.5"
|
||||||
|
|> VC.mostRecentFromVersionList versions
|
||||||
|
|
||||||
|
|
||||||
type alias EventOutput =
|
type alias EventOutput =
|
||||||
Task X.Error O.ClientEvent
|
Api.GetEventOutputV1
|
||||||
|
|
||||||
|
|
||||||
type alias EventInput =
|
type alias EventInput =
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module Internal.Api.GetEvent.V1_2.SpecObjects exposing
|
module Internal.Api.GetEvent.V1.SpecObjects exposing
|
||||||
( ClientEvent
|
( ClientEvent
|
||||||
, UnsignedData(..)
|
, UnsignedData(..)
|
||||||
, clientEventDecoder
|
, clientEventDecoder
|
||||||
|
@ -9,7 +9,7 @@ module Internal.Api.GetEvent.V1_2.SpecObjects exposing
|
||||||
|
|
||||||
{-| Automatically generated 'SpecObjects'
|
{-| Automatically generated 'SpecObjects'
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
Last generated at Unix time 1676311233
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
version: v1.2
|
version: v1
|
||||||
name: SpecObjects
|
name: SpecObjects
|
||||||
objects:
|
objects:
|
||||||
ClientEvent:
|
ClientEvent:
|
|
@ -1,17 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_2.Api exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.Api as Api
|
|
||||||
import Internal.Api.GetEvent.V1_2.Convert as C
|
|
||||||
import Internal.Api.GetEvent.V1_2.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_2.SpecObjects as SO
|
|
||||||
import Internal.Api.GetEvent.V1_2.Upcast as U
|
|
||||||
import Internal.Api.VersionControl as V
|
|
||||||
|
|
||||||
|
|
||||||
packet : V.SingleVersion () () Api.GetEventInputV1 O.ClientEvent
|
|
||||||
packet =
|
|
||||||
{ version = "v1.2"
|
|
||||||
, downcast = \_ -> ()
|
|
||||||
, current = Api.getEventInputV1 SO.clientEventDecoder C.convert
|
|
||||||
, upcast = U.upcast
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_2.Convert exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_2.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_2.SpecObjects as SO
|
|
||||||
|
|
||||||
|
|
||||||
convert : SO.ClientEvent -> O.ClientEvent
|
|
||||||
convert e =
|
|
||||||
{ content = e.content
|
|
||||||
, eventId = e.eventId
|
|
||||||
, originServerTs = e.originServerTs
|
|
||||||
, roomId = e.roomId
|
|
||||||
, sender = e.sender
|
|
||||||
, stateKey = e.stateKey
|
|
||||||
, contentType = e.contentType
|
|
||||||
, unsigned = Maybe.map convertUnsigned e.unsigned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
convertUnsigned : SO.UnsignedData -> O.UnsignedData
|
|
||||||
convertUnsigned (SO.UnsignedData u) =
|
|
||||||
O.UnsignedData
|
|
||||||
{ age = u.age
|
|
||||||
, prevContent = u.prevContent
|
|
||||||
, redactedBecause = Maybe.map convert u.redactedBecause
|
|
||||||
, transactionId = u.transactionId
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_2.Objects exposing
|
|
||||||
( ClientEvent
|
|
||||||
, UnsignedData(..)
|
|
||||||
, clientEventDecoder
|
|
||||||
, encodeClientEvent
|
|
||||||
, encodeUnsignedData
|
|
||||||
, unsignedDataDecoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Automatically generated 'Objects'
|
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Internal.Tools.DecodeExtra exposing (opField)
|
|
||||||
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
|
||||||
import Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
{-| Client Event containing all data on an event.
|
|
||||||
-}
|
|
||||||
type alias ClientEvent =
|
|
||||||
{ content : E.Value
|
|
||||||
, eventId : String
|
|
||||||
, originServerTs : Timestamp
|
|
||||||
, roomId : String
|
|
||||||
, sender : String
|
|
||||||
, stateKey : Maybe String
|
|
||||||
, contentType : String
|
|
||||||
, unsigned : Maybe UnsignedData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeClientEvent : ClientEvent -> E.Value
|
|
||||||
encodeClientEvent data =
|
|
||||||
maybeObject
|
|
||||||
[ ( "content", Just <| data.content )
|
|
||||||
, ( "event_id", Just <| E.string data.eventId )
|
|
||||||
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
|
|
||||||
, ( "room_id", Just <| E.string data.roomId )
|
|
||||||
, ( "sender", Just <| E.string data.sender )
|
|
||||||
, ( "state_key", Maybe.map E.string data.stateKey )
|
|
||||||
, ( "type", Just <| E.string data.contentType )
|
|
||||||
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
clientEventDecoder : D.Decoder ClientEvent
|
|
||||||
clientEventDecoder =
|
|
||||||
D.map8
|
|
||||||
(\a b c d e f g h ->
|
|
||||||
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, contentType = g, unsigned = h }
|
|
||||||
)
|
|
||||||
(D.field "content" D.value)
|
|
||||||
(D.field "event_id" D.string)
|
|
||||||
(D.field "origin_server_ts" timestampDecoder)
|
|
||||||
(D.field "room_id" D.string)
|
|
||||||
(D.field "sender" D.string)
|
|
||||||
(opField "state_key" D.string)
|
|
||||||
(D.field "type" D.string)
|
|
||||||
(opField "unsigned" (D.lazy (\_ -> unsignedDataDecoder)))
|
|
||||||
|
|
||||||
|
|
||||||
{-| Extra information about the event.
|
|
||||||
-}
|
|
||||||
type UnsignedData
|
|
||||||
= UnsignedData
|
|
||||||
{ age : Maybe Int
|
|
||||||
, prevContent : Maybe E.Value
|
|
||||||
, redactedBecause : Maybe ClientEvent
|
|
||||||
, transactionId : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeUnsignedData : UnsignedData -> E.Value
|
|
||||||
encodeUnsignedData (UnsignedData data) =
|
|
||||||
maybeObject
|
|
||||||
[ ( "age", Maybe.map E.int data.age )
|
|
||||||
, ( "prev_content", data.prevContent )
|
|
||||||
, ( "redacted_because", Maybe.map encodeClientEvent data.redactedBecause )
|
|
||||||
, ( "transaction_id", Maybe.map E.string data.transactionId )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
unsignedDataDecoder : D.Decoder UnsignedData
|
|
||||||
unsignedDataDecoder =
|
|
||||||
D.map4
|
|
||||||
(\a b c d ->
|
|
||||||
UnsignedData { age = a, prevContent = b, redactedBecause = c, transactionId = d }
|
|
||||||
)
|
|
||||||
(opField "age" D.int)
|
|
||||||
(opField "prev_content" D.value)
|
|
||||||
(opField "redacted_because" clientEventDecoder)
|
|
||||||
(opField "transaction_id" D.string)
|
|
|
@ -1,40 +0,0 @@
|
||||||
version: v1.2
|
|
||||||
name: Objects
|
|
||||||
objects:
|
|
||||||
ClientEvent:
|
|
||||||
description: Client Event containing all data on an event.
|
|
||||||
fields:
|
|
||||||
content:
|
|
||||||
type: value
|
|
||||||
required: true
|
|
||||||
event_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
origin_server_ts:
|
|
||||||
type: timestamp
|
|
||||||
required: true
|
|
||||||
room_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
sender:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
state_key:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
unsigned:
|
|
||||||
type: UnsignedData
|
|
||||||
UnsignedData:
|
|
||||||
anti_recursion: true
|
|
||||||
description: Extra information about the event.
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
type: int
|
|
||||||
prev_content:
|
|
||||||
type: value
|
|
||||||
redacted_because:
|
|
||||||
type: ClientEvent
|
|
||||||
transaction_id:
|
|
||||||
type: string
|
|
|
@ -1,18 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_2.Upcast exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_2.Objects as O
|
|
||||||
import Internal.Config.Leaking as L
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
upcast : () -> O.ClientEvent
|
|
||||||
upcast _ =
|
|
||||||
{ content = E.object []
|
|
||||||
, eventId = L.eventId
|
|
||||||
, originServerTs = L.originServerTs
|
|
||||||
, roomId = L.roomId
|
|
||||||
, sender = L.sender
|
|
||||||
, stateKey = Nothing
|
|
||||||
, contentType = L.eventType
|
|
||||||
, unsigned = Nothing
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_3.Api exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.Api as Api
|
|
||||||
import Internal.Api.GetEvent.V1_2.Objects as PO
|
|
||||||
import Internal.Api.GetEvent.V1_3.Convert as C
|
|
||||||
import Internal.Api.GetEvent.V1_3.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_3.SpecObjects as SO
|
|
||||||
import Internal.Api.GetEvent.V1_3.Upcast as U
|
|
||||||
import Internal.Api.VersionControl as V
|
|
||||||
|
|
||||||
|
|
||||||
packet : V.SingleVersion Api.GetEventInputV1 PO.ClientEvent Api.GetEventInputV1 O.ClientEvent
|
|
||||||
packet =
|
|
||||||
{ version = "v1.3"
|
|
||||||
, downcast = identity
|
|
||||||
, current = Api.getEventInputV1 SO.clientEventDecoder C.convert
|
|
||||||
, upcast = U.upcast
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_3.Convert exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_3.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_3.SpecObjects as SO
|
|
||||||
|
|
||||||
|
|
||||||
convert : SO.ClientEvent -> O.ClientEvent
|
|
||||||
convert e =
|
|
||||||
{ content = e.content
|
|
||||||
, eventId = e.eventId
|
|
||||||
, originServerTs = e.originServerTs
|
|
||||||
, roomId = e.roomId
|
|
||||||
, sender = e.sender
|
|
||||||
, stateKey = e.stateKey
|
|
||||||
, contentType = e.contentType
|
|
||||||
, unsigned = Maybe.map convertUnsigned e.unsigned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
convertUnsigned : SO.UnsignedData -> O.UnsignedData
|
|
||||||
convertUnsigned (SO.UnsignedData u) =
|
|
||||||
O.UnsignedData
|
|
||||||
{ age = u.age
|
|
||||||
, prevContent = u.prevContent
|
|
||||||
, redactedBecause = Maybe.map convert u.redactedBecause
|
|
||||||
, transactionId = u.transactionId
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_3.Objects exposing
|
|
||||||
( ClientEvent
|
|
||||||
, UnsignedData(..)
|
|
||||||
, clientEventDecoder
|
|
||||||
, encodeClientEvent
|
|
||||||
, encodeUnsignedData
|
|
||||||
, unsignedDataDecoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Automatically generated 'Objects'
|
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Internal.Tools.DecodeExtra exposing (opField)
|
|
||||||
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
|
||||||
import Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
{-| Client Event containing all data on an event.
|
|
||||||
-}
|
|
||||||
type alias ClientEvent =
|
|
||||||
{ content : E.Value
|
|
||||||
, eventId : String
|
|
||||||
, originServerTs : Timestamp
|
|
||||||
, roomId : String
|
|
||||||
, sender : String
|
|
||||||
, stateKey : Maybe String
|
|
||||||
, contentType : String
|
|
||||||
, unsigned : Maybe UnsignedData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeClientEvent : ClientEvent -> E.Value
|
|
||||||
encodeClientEvent data =
|
|
||||||
maybeObject
|
|
||||||
[ ( "content", Just <| data.content )
|
|
||||||
, ( "event_id", Just <| E.string data.eventId )
|
|
||||||
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
|
|
||||||
, ( "room_id", Just <| E.string data.roomId )
|
|
||||||
, ( "sender", Just <| E.string data.sender )
|
|
||||||
, ( "state_key", Maybe.map E.string data.stateKey )
|
|
||||||
, ( "type", Just <| E.string data.contentType )
|
|
||||||
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
clientEventDecoder : D.Decoder ClientEvent
|
|
||||||
clientEventDecoder =
|
|
||||||
D.map8
|
|
||||||
(\a b c d e f g h ->
|
|
||||||
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, contentType = g, unsigned = h }
|
|
||||||
)
|
|
||||||
(D.field "content" D.value)
|
|
||||||
(D.field "event_id" D.string)
|
|
||||||
(D.field "origin_server_ts" timestampDecoder)
|
|
||||||
(D.field "room_id" D.string)
|
|
||||||
(D.field "sender" D.string)
|
|
||||||
(opField "state_key" D.string)
|
|
||||||
(D.field "type" D.string)
|
|
||||||
(opField "unsigned" (D.lazy (\_ -> unsignedDataDecoder)))
|
|
||||||
|
|
||||||
|
|
||||||
{-| Extra information about the event.
|
|
||||||
-}
|
|
||||||
type UnsignedData
|
|
||||||
= UnsignedData
|
|
||||||
{ age : Maybe Int
|
|
||||||
, prevContent : Maybe E.Value
|
|
||||||
, redactedBecause : Maybe ClientEvent
|
|
||||||
, transactionId : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeUnsignedData : UnsignedData -> E.Value
|
|
||||||
encodeUnsignedData (UnsignedData data) =
|
|
||||||
maybeObject
|
|
||||||
[ ( "age", Maybe.map E.int data.age )
|
|
||||||
, ( "prev_content", data.prevContent )
|
|
||||||
, ( "redacted_because", Maybe.map encodeClientEvent data.redactedBecause )
|
|
||||||
, ( "transaction_id", Maybe.map E.string data.transactionId )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
unsignedDataDecoder : D.Decoder UnsignedData
|
|
||||||
unsignedDataDecoder =
|
|
||||||
D.map4
|
|
||||||
(\a b c d ->
|
|
||||||
UnsignedData { age = a, prevContent = b, redactedBecause = c, transactionId = d }
|
|
||||||
)
|
|
||||||
(opField "age" D.int)
|
|
||||||
(opField "prev_content" D.value)
|
|
||||||
(opField "redacted_because" clientEventDecoder)
|
|
||||||
(opField "transaction_id" D.string)
|
|
|
@ -1,40 +0,0 @@
|
||||||
version: v1.3
|
|
||||||
name: Objects
|
|
||||||
objects:
|
|
||||||
ClientEvent:
|
|
||||||
description: Client Event containing all data on an event.
|
|
||||||
fields:
|
|
||||||
content:
|
|
||||||
type: value
|
|
||||||
required: true
|
|
||||||
event_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
origin_server_ts:
|
|
||||||
type: timestamp
|
|
||||||
required: true
|
|
||||||
room_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
sender:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
state_key:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
unsigned:
|
|
||||||
type: UnsignedData
|
|
||||||
UnsignedData:
|
|
||||||
anti_recursion: true
|
|
||||||
description: Extra information about the event.
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
type: int
|
|
||||||
prev_content:
|
|
||||||
type: value
|
|
||||||
redacted_because:
|
|
||||||
type: ClientEvent
|
|
||||||
transaction_id:
|
|
||||||
type: string
|
|
|
@ -1,97 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_3.SpecObjects exposing
|
|
||||||
( ClientEvent
|
|
||||||
, UnsignedData(..)
|
|
||||||
, clientEventDecoder
|
|
||||||
, encodeClientEvent
|
|
||||||
, encodeUnsignedData
|
|
||||||
, unsignedDataDecoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Automatically generated 'SpecObjects'
|
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Internal.Tools.DecodeExtra exposing (opField)
|
|
||||||
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
|
||||||
import Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
{-| Client Event containing all data on an event.
|
|
||||||
-}
|
|
||||||
type alias ClientEvent =
|
|
||||||
{ content : E.Value
|
|
||||||
, eventId : String
|
|
||||||
, originServerTs : Timestamp
|
|
||||||
, roomId : String
|
|
||||||
, sender : String
|
|
||||||
, stateKey : Maybe String
|
|
||||||
, contentType : String
|
|
||||||
, unsigned : Maybe UnsignedData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeClientEvent : ClientEvent -> E.Value
|
|
||||||
encodeClientEvent data =
|
|
||||||
maybeObject
|
|
||||||
[ ( "content", Just <| data.content )
|
|
||||||
, ( "event_id", Just <| E.string data.eventId )
|
|
||||||
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
|
|
||||||
, ( "room_id", Just <| E.string data.roomId )
|
|
||||||
, ( "sender", Just <| E.string data.sender )
|
|
||||||
, ( "state_key", Maybe.map E.string data.stateKey )
|
|
||||||
, ( "type", Just <| E.string data.contentType )
|
|
||||||
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
clientEventDecoder : D.Decoder ClientEvent
|
|
||||||
clientEventDecoder =
|
|
||||||
D.map8
|
|
||||||
(\a b c d e f g h ->
|
|
||||||
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, contentType = g, unsigned = h }
|
|
||||||
)
|
|
||||||
(D.field "content" D.value)
|
|
||||||
(D.field "event_id" D.string)
|
|
||||||
(D.field "origin_server_ts" timestampDecoder)
|
|
||||||
(D.field "room_id" D.string)
|
|
||||||
(D.field "sender" D.string)
|
|
||||||
(opField "state_key" D.string)
|
|
||||||
(D.field "type" D.string)
|
|
||||||
(opField "unsigned" (D.lazy (\_ -> unsignedDataDecoder)))
|
|
||||||
|
|
||||||
|
|
||||||
{-| Extra information about the event.
|
|
||||||
-}
|
|
||||||
type UnsignedData
|
|
||||||
= UnsignedData
|
|
||||||
{ age : Maybe Int
|
|
||||||
, prevContent : Maybe E.Value
|
|
||||||
, redactedBecause : Maybe ClientEvent
|
|
||||||
, transactionId : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeUnsignedData : UnsignedData -> E.Value
|
|
||||||
encodeUnsignedData (UnsignedData data) =
|
|
||||||
maybeObject
|
|
||||||
[ ( "age", Maybe.map E.int data.age )
|
|
||||||
, ( "prev_content", data.prevContent )
|
|
||||||
, ( "redacted_because", Maybe.map encodeClientEvent data.redactedBecause )
|
|
||||||
, ( "transaction_id", Maybe.map E.string data.transactionId )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
unsignedDataDecoder : D.Decoder UnsignedData
|
|
||||||
unsignedDataDecoder =
|
|
||||||
D.map4
|
|
||||||
(\a b c d ->
|
|
||||||
UnsignedData { age = a, prevContent = b, redactedBecause = c, transactionId = d }
|
|
||||||
)
|
|
||||||
(opField "age" D.int)
|
|
||||||
(opField "prev_content" D.value)
|
|
||||||
(opField "redacted_because" clientEventDecoder)
|
|
||||||
(opField "transaction_id" D.string)
|
|
|
@ -1,40 +0,0 @@
|
||||||
version: v1.3
|
|
||||||
name: SpecObjects
|
|
||||||
objects:
|
|
||||||
ClientEvent:
|
|
||||||
description: Client Event containing all data on an event.
|
|
||||||
fields:
|
|
||||||
content:
|
|
||||||
type: value
|
|
||||||
required: true
|
|
||||||
event_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
origin_server_ts:
|
|
||||||
type: timestamp
|
|
||||||
required: true
|
|
||||||
room_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
sender:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
state_key:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
unsigned:
|
|
||||||
type: UnsignedData
|
|
||||||
UnsignedData:
|
|
||||||
anti_recursion: true
|
|
||||||
description: Extra information about the event.
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
type: int
|
|
||||||
prev_content:
|
|
||||||
type: value
|
|
||||||
redacted_because:
|
|
||||||
type: ClientEvent
|
|
||||||
transaction_id:
|
|
||||||
type: string
|
|
|
@ -1,27 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_3.Upcast exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_2.Objects as PO
|
|
||||||
import Internal.Api.GetEvent.V1_3.Objects as O
|
|
||||||
|
|
||||||
|
|
||||||
upcast : PO.ClientEvent -> O.ClientEvent
|
|
||||||
upcast e =
|
|
||||||
{ content = e.content
|
|
||||||
, eventId = e.eventId
|
|
||||||
, originServerTs = e.originServerTs
|
|
||||||
, roomId = e.roomId
|
|
||||||
, sender = e.sender
|
|
||||||
, stateKey = e.stateKey
|
|
||||||
, contentType = e.contentType
|
|
||||||
, unsigned = Maybe.map upcastUnsigned e.unsigned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
upcastUnsigned : PO.UnsignedData -> O.UnsignedData
|
|
||||||
upcastUnsigned (PO.UnsignedData u) =
|
|
||||||
O.UnsignedData
|
|
||||||
{ age = u.age
|
|
||||||
, prevContent = u.prevContent
|
|
||||||
, redactedBecause = Maybe.map upcast u.redactedBecause
|
|
||||||
, transactionId = u.transactionId
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_4.Api exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.Api as Api
|
|
||||||
import Internal.Api.GetEvent.V1_3.Objects as PO
|
|
||||||
import Internal.Api.GetEvent.V1_4.Convert as C
|
|
||||||
import Internal.Api.GetEvent.V1_4.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_4.SpecObjects as SO
|
|
||||||
import Internal.Api.GetEvent.V1_4.Upcast as U
|
|
||||||
import Internal.Api.VersionControl as V
|
|
||||||
|
|
||||||
|
|
||||||
packet : V.SingleVersion Api.GetEventInputV1 PO.ClientEvent Api.GetEventInputV1 O.ClientEvent
|
|
||||||
packet =
|
|
||||||
{ version = "v1.4"
|
|
||||||
, downcast = identity
|
|
||||||
, current = Api.getEventInputV1 SO.clientEventDecoder C.convert
|
|
||||||
, upcast = U.upcast
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_4.Convert exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_4.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_4.SpecObjects as SO
|
|
||||||
|
|
||||||
|
|
||||||
convert : SO.ClientEvent -> O.ClientEvent
|
|
||||||
convert e =
|
|
||||||
{ content = e.content
|
|
||||||
, eventId = e.eventId
|
|
||||||
, originServerTs = e.originServerTs
|
|
||||||
, roomId = e.roomId
|
|
||||||
, sender = e.sender
|
|
||||||
, stateKey = e.stateKey
|
|
||||||
, contentType = e.contentType
|
|
||||||
, unsigned = Maybe.map convertUnsigned e.unsigned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
convertUnsigned : SO.UnsignedData -> O.UnsignedData
|
|
||||||
convertUnsigned (SO.UnsignedData u) =
|
|
||||||
O.UnsignedData
|
|
||||||
{ age = u.age
|
|
||||||
, prevContent = u.prevContent
|
|
||||||
, redactedBecause = Maybe.map convert u.redactedBecause
|
|
||||||
, transactionId = u.transactionId
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_4.Objects exposing
|
|
||||||
( ClientEvent
|
|
||||||
, UnsignedData(..)
|
|
||||||
, clientEventDecoder
|
|
||||||
, encodeClientEvent
|
|
||||||
, encodeUnsignedData
|
|
||||||
, unsignedDataDecoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Automatically generated 'Objects'
|
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Internal.Tools.DecodeExtra exposing (opField)
|
|
||||||
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
|
||||||
import Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
{-| Client Event containing all data on an event.
|
|
||||||
-}
|
|
||||||
type alias ClientEvent =
|
|
||||||
{ content : E.Value
|
|
||||||
, eventId : String
|
|
||||||
, originServerTs : Timestamp
|
|
||||||
, roomId : String
|
|
||||||
, sender : String
|
|
||||||
, stateKey : Maybe String
|
|
||||||
, contentType : String
|
|
||||||
, unsigned : Maybe UnsignedData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeClientEvent : ClientEvent -> E.Value
|
|
||||||
encodeClientEvent data =
|
|
||||||
maybeObject
|
|
||||||
[ ( "content", Just <| data.content )
|
|
||||||
, ( "event_id", Just <| E.string data.eventId )
|
|
||||||
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
|
|
||||||
, ( "room_id", Just <| E.string data.roomId )
|
|
||||||
, ( "sender", Just <| E.string data.sender )
|
|
||||||
, ( "state_key", Maybe.map E.string data.stateKey )
|
|
||||||
, ( "type", Just <| E.string data.contentType )
|
|
||||||
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
clientEventDecoder : D.Decoder ClientEvent
|
|
||||||
clientEventDecoder =
|
|
||||||
D.map8
|
|
||||||
(\a b c d e f g h ->
|
|
||||||
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, contentType = g, unsigned = h }
|
|
||||||
)
|
|
||||||
(D.field "content" D.value)
|
|
||||||
(D.field "event_id" D.string)
|
|
||||||
(D.field "origin_server_ts" timestampDecoder)
|
|
||||||
(D.field "room_id" D.string)
|
|
||||||
(D.field "sender" D.string)
|
|
||||||
(opField "state_key" D.string)
|
|
||||||
(D.field "type" D.string)
|
|
||||||
(opField "unsigned" (D.lazy (\_ -> unsignedDataDecoder)))
|
|
||||||
|
|
||||||
|
|
||||||
{-| Extra information about the event.
|
|
||||||
-}
|
|
||||||
type UnsignedData
|
|
||||||
= UnsignedData
|
|
||||||
{ age : Maybe Int
|
|
||||||
, prevContent : Maybe E.Value
|
|
||||||
, redactedBecause : Maybe ClientEvent
|
|
||||||
, transactionId : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeUnsignedData : UnsignedData -> E.Value
|
|
||||||
encodeUnsignedData (UnsignedData data) =
|
|
||||||
maybeObject
|
|
||||||
[ ( "age", Maybe.map E.int data.age )
|
|
||||||
, ( "prev_content", data.prevContent )
|
|
||||||
, ( "redacted_because", Maybe.map encodeClientEvent data.redactedBecause )
|
|
||||||
, ( "transaction_id", Maybe.map E.string data.transactionId )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
unsignedDataDecoder : D.Decoder UnsignedData
|
|
||||||
unsignedDataDecoder =
|
|
||||||
D.map4
|
|
||||||
(\a b c d ->
|
|
||||||
UnsignedData { age = a, prevContent = b, redactedBecause = c, transactionId = d }
|
|
||||||
)
|
|
||||||
(opField "age" D.int)
|
|
||||||
(opField "prev_content" D.value)
|
|
||||||
(opField "redacted_because" clientEventDecoder)
|
|
||||||
(opField "transaction_id" D.string)
|
|
|
@ -1,40 +0,0 @@
|
||||||
version: v1.4
|
|
||||||
name: Objects
|
|
||||||
objects:
|
|
||||||
ClientEvent:
|
|
||||||
description: Client Event containing all data on an event.
|
|
||||||
fields:
|
|
||||||
content:
|
|
||||||
type: value
|
|
||||||
required: true
|
|
||||||
event_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
origin_server_ts:
|
|
||||||
type: timestamp
|
|
||||||
required: true
|
|
||||||
room_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
sender:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
state_key:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
unsigned:
|
|
||||||
type: UnsignedData
|
|
||||||
UnsignedData:
|
|
||||||
anti_recursion: true
|
|
||||||
description: Extra information about the event.
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
type: int
|
|
||||||
prev_content:
|
|
||||||
type: value
|
|
||||||
redacted_because:
|
|
||||||
type: ClientEvent
|
|
||||||
transaction_id:
|
|
||||||
type: string
|
|
|
@ -1,97 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_4.SpecObjects exposing
|
|
||||||
( ClientEvent
|
|
||||||
, UnsignedData(..)
|
|
||||||
, clientEventDecoder
|
|
||||||
, encodeClientEvent
|
|
||||||
, encodeUnsignedData
|
|
||||||
, unsignedDataDecoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Automatically generated 'SpecObjects'
|
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Internal.Tools.DecodeExtra exposing (opField)
|
|
||||||
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
|
||||||
import Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
{-| Client Event containing all data on an event.
|
|
||||||
-}
|
|
||||||
type alias ClientEvent =
|
|
||||||
{ content : E.Value
|
|
||||||
, eventId : String
|
|
||||||
, originServerTs : Timestamp
|
|
||||||
, roomId : String
|
|
||||||
, sender : String
|
|
||||||
, stateKey : Maybe String
|
|
||||||
, contentType : String
|
|
||||||
, unsigned : Maybe UnsignedData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeClientEvent : ClientEvent -> E.Value
|
|
||||||
encodeClientEvent data =
|
|
||||||
maybeObject
|
|
||||||
[ ( "content", Just <| data.content )
|
|
||||||
, ( "event_id", Just <| E.string data.eventId )
|
|
||||||
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
|
|
||||||
, ( "room_id", Just <| E.string data.roomId )
|
|
||||||
, ( "sender", Just <| E.string data.sender )
|
|
||||||
, ( "state_key", Maybe.map E.string data.stateKey )
|
|
||||||
, ( "type", Just <| E.string data.contentType )
|
|
||||||
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
clientEventDecoder : D.Decoder ClientEvent
|
|
||||||
clientEventDecoder =
|
|
||||||
D.map8
|
|
||||||
(\a b c d e f g h ->
|
|
||||||
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, contentType = g, unsigned = h }
|
|
||||||
)
|
|
||||||
(D.field "content" D.value)
|
|
||||||
(D.field "event_id" D.string)
|
|
||||||
(D.field "origin_server_ts" timestampDecoder)
|
|
||||||
(D.field "room_id" D.string)
|
|
||||||
(D.field "sender" D.string)
|
|
||||||
(opField "state_key" D.string)
|
|
||||||
(D.field "type" D.string)
|
|
||||||
(opField "unsigned" (D.lazy (\_ -> unsignedDataDecoder)))
|
|
||||||
|
|
||||||
|
|
||||||
{-| Extra information about the event.
|
|
||||||
-}
|
|
||||||
type UnsignedData
|
|
||||||
= UnsignedData
|
|
||||||
{ age : Maybe Int
|
|
||||||
, prevContent : Maybe E.Value
|
|
||||||
, redactedBecause : Maybe ClientEvent
|
|
||||||
, transactionId : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeUnsignedData : UnsignedData -> E.Value
|
|
||||||
encodeUnsignedData (UnsignedData data) =
|
|
||||||
maybeObject
|
|
||||||
[ ( "age", Maybe.map E.int data.age )
|
|
||||||
, ( "prev_content", data.prevContent )
|
|
||||||
, ( "redacted_because", Maybe.map encodeClientEvent data.redactedBecause )
|
|
||||||
, ( "transaction_id", Maybe.map E.string data.transactionId )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
unsignedDataDecoder : D.Decoder UnsignedData
|
|
||||||
unsignedDataDecoder =
|
|
||||||
D.map4
|
|
||||||
(\a b c d ->
|
|
||||||
UnsignedData { age = a, prevContent = b, redactedBecause = c, transactionId = d }
|
|
||||||
)
|
|
||||||
(opField "age" D.int)
|
|
||||||
(opField "prev_content" D.value)
|
|
||||||
(opField "redacted_because" clientEventDecoder)
|
|
||||||
(opField "transaction_id" D.string)
|
|
|
@ -1,40 +0,0 @@
|
||||||
version: v1.4
|
|
||||||
name: SpecObjects
|
|
||||||
objects:
|
|
||||||
ClientEvent:
|
|
||||||
description: Client Event containing all data on an event.
|
|
||||||
fields:
|
|
||||||
content:
|
|
||||||
type: value
|
|
||||||
required: true
|
|
||||||
event_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
origin_server_ts:
|
|
||||||
type: timestamp
|
|
||||||
required: true
|
|
||||||
room_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
sender:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
state_key:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
unsigned:
|
|
||||||
type: UnsignedData
|
|
||||||
UnsignedData:
|
|
||||||
anti_recursion: true
|
|
||||||
description: Extra information about the event.
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
type: int
|
|
||||||
prev_content:
|
|
||||||
type: value
|
|
||||||
redacted_because:
|
|
||||||
type: ClientEvent
|
|
||||||
transaction_id:
|
|
||||||
type: string
|
|
|
@ -1,27 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_4.Upcast exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_3.Objects as PO
|
|
||||||
import Internal.Api.GetEvent.V1_4.Objects as O
|
|
||||||
|
|
||||||
|
|
||||||
upcast : PO.ClientEvent -> O.ClientEvent
|
|
||||||
upcast e =
|
|
||||||
{ content = e.content
|
|
||||||
, eventId = e.eventId
|
|
||||||
, originServerTs = e.originServerTs
|
|
||||||
, roomId = e.roomId
|
|
||||||
, sender = e.sender
|
|
||||||
, stateKey = e.stateKey
|
|
||||||
, contentType = e.contentType
|
|
||||||
, unsigned = Maybe.map upcastUnsigned e.unsigned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
upcastUnsigned : PO.UnsignedData -> O.UnsignedData
|
|
||||||
upcastUnsigned (PO.UnsignedData u) =
|
|
||||||
O.UnsignedData
|
|
||||||
{ age = u.age
|
|
||||||
, prevContent = u.prevContent
|
|
||||||
, redactedBecause = Maybe.map upcast u.redactedBecause
|
|
||||||
, transactionId = u.transactionId
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_5.Api exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.Api as Api
|
|
||||||
import Internal.Api.GetEvent.V1_4.Objects as PO
|
|
||||||
import Internal.Api.GetEvent.V1_5.Convert as C
|
|
||||||
import Internal.Api.GetEvent.V1_5.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_5.SpecObjects as SO
|
|
||||||
import Internal.Api.GetEvent.V1_5.Upcast as U
|
|
||||||
import Internal.Api.VersionControl as V
|
|
||||||
|
|
||||||
|
|
||||||
packet : V.SingleVersion Api.GetEventInputV1 PO.ClientEvent Api.GetEventInputV1 O.ClientEvent
|
|
||||||
packet =
|
|
||||||
{ version = "v1.5"
|
|
||||||
, downcast = identity
|
|
||||||
, current = Api.getEventInputV1 SO.clientEventDecoder C.convert
|
|
||||||
, upcast = U.upcast
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_5.Convert exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_5.Objects as O
|
|
||||||
import Internal.Api.GetEvent.V1_5.SpecObjects as SO
|
|
||||||
|
|
||||||
|
|
||||||
convert : SO.ClientEvent -> O.ClientEvent
|
|
||||||
convert e =
|
|
||||||
{ content = e.content
|
|
||||||
, eventId = e.eventId
|
|
||||||
, originServerTs = e.originServerTs
|
|
||||||
, roomId = e.roomId
|
|
||||||
, sender = e.sender
|
|
||||||
, stateKey = e.stateKey
|
|
||||||
, contentType = e.contentType
|
|
||||||
, unsigned = Maybe.map convertUnsigned e.unsigned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
convertUnsigned : SO.UnsignedData -> O.UnsignedData
|
|
||||||
convertUnsigned (SO.UnsignedData u) =
|
|
||||||
O.UnsignedData
|
|
||||||
{ age = u.age
|
|
||||||
, prevContent = u.prevContent
|
|
||||||
, redactedBecause = Maybe.map convert u.redactedBecause
|
|
||||||
, transactionId = u.transactionId
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_5.Objects exposing
|
|
||||||
( ClientEvent
|
|
||||||
, UnsignedData(..)
|
|
||||||
, clientEventDecoder
|
|
||||||
, encodeClientEvent
|
|
||||||
, encodeUnsignedData
|
|
||||||
, unsignedDataDecoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Automatically generated 'Objects'
|
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Internal.Tools.DecodeExtra exposing (opField)
|
|
||||||
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
|
||||||
import Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
{-| Client Event containing all data on an event.
|
|
||||||
-}
|
|
||||||
type alias ClientEvent =
|
|
||||||
{ content : E.Value
|
|
||||||
, eventId : String
|
|
||||||
, originServerTs : Timestamp
|
|
||||||
, roomId : String
|
|
||||||
, sender : String
|
|
||||||
, stateKey : Maybe String
|
|
||||||
, contentType : String
|
|
||||||
, unsigned : Maybe UnsignedData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeClientEvent : ClientEvent -> E.Value
|
|
||||||
encodeClientEvent data =
|
|
||||||
maybeObject
|
|
||||||
[ ( "content", Just <| data.content )
|
|
||||||
, ( "event_id", Just <| E.string data.eventId )
|
|
||||||
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
|
|
||||||
, ( "room_id", Just <| E.string data.roomId )
|
|
||||||
, ( "sender", Just <| E.string data.sender )
|
|
||||||
, ( "state_key", Maybe.map E.string data.stateKey )
|
|
||||||
, ( "type", Just <| E.string data.contentType )
|
|
||||||
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
clientEventDecoder : D.Decoder ClientEvent
|
|
||||||
clientEventDecoder =
|
|
||||||
D.map8
|
|
||||||
(\a b c d e f g h ->
|
|
||||||
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, contentType = g, unsigned = h }
|
|
||||||
)
|
|
||||||
(D.field "content" D.value)
|
|
||||||
(D.field "event_id" D.string)
|
|
||||||
(D.field "origin_server_ts" timestampDecoder)
|
|
||||||
(D.field "room_id" D.string)
|
|
||||||
(D.field "sender" D.string)
|
|
||||||
(opField "state_key" D.string)
|
|
||||||
(D.field "type" D.string)
|
|
||||||
(opField "unsigned" (D.lazy (\_ -> unsignedDataDecoder)))
|
|
||||||
|
|
||||||
|
|
||||||
{-| Extra information about the event.
|
|
||||||
-}
|
|
||||||
type UnsignedData
|
|
||||||
= UnsignedData
|
|
||||||
{ age : Maybe Int
|
|
||||||
, prevContent : Maybe E.Value
|
|
||||||
, redactedBecause : Maybe ClientEvent
|
|
||||||
, transactionId : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeUnsignedData : UnsignedData -> E.Value
|
|
||||||
encodeUnsignedData (UnsignedData data) =
|
|
||||||
maybeObject
|
|
||||||
[ ( "age", Maybe.map E.int data.age )
|
|
||||||
, ( "prev_content", data.prevContent )
|
|
||||||
, ( "redacted_because", Maybe.map encodeClientEvent data.redactedBecause )
|
|
||||||
, ( "transaction_id", Maybe.map E.string data.transactionId )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
unsignedDataDecoder : D.Decoder UnsignedData
|
|
||||||
unsignedDataDecoder =
|
|
||||||
D.map4
|
|
||||||
(\a b c d ->
|
|
||||||
UnsignedData { age = a, prevContent = b, redactedBecause = c, transactionId = d }
|
|
||||||
)
|
|
||||||
(opField "age" D.int)
|
|
||||||
(opField "prev_content" D.value)
|
|
||||||
(opField "redacted_because" clientEventDecoder)
|
|
||||||
(opField "transaction_id" D.string)
|
|
|
@ -1,40 +0,0 @@
|
||||||
version: v1.5
|
|
||||||
name: Objects
|
|
||||||
objects:
|
|
||||||
ClientEvent:
|
|
||||||
description: Client Event containing all data on an event.
|
|
||||||
fields:
|
|
||||||
content:
|
|
||||||
type: value
|
|
||||||
required: true
|
|
||||||
event_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
origin_server_ts:
|
|
||||||
type: timestamp
|
|
||||||
required: true
|
|
||||||
room_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
sender:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
state_key:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
unsigned:
|
|
||||||
type: UnsignedData
|
|
||||||
UnsignedData:
|
|
||||||
anti_recursion: true
|
|
||||||
description: Extra information about the event.
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
type: int
|
|
||||||
prev_content:
|
|
||||||
type: value
|
|
||||||
redacted_because:
|
|
||||||
type: ClientEvent
|
|
||||||
transaction_id:
|
|
||||||
type: string
|
|
|
@ -1,97 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_5.SpecObjects exposing
|
|
||||||
( ClientEvent
|
|
||||||
, UnsignedData(..)
|
|
||||||
, clientEventDecoder
|
|
||||||
, encodeClientEvent
|
|
||||||
, encodeUnsignedData
|
|
||||||
, unsignedDataDecoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Automatically generated 'SpecObjects'
|
|
||||||
|
|
||||||
Last generated at Unix time 1673279712
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Internal.Tools.DecodeExtra exposing (opField)
|
|
||||||
import Internal.Tools.EncodeExtra exposing (maybeObject)
|
|
||||||
import Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
|
|
||||||
|
|
||||||
{-| Client Event containing all data on an event.
|
|
||||||
-}
|
|
||||||
type alias ClientEvent =
|
|
||||||
{ content : E.Value
|
|
||||||
, eventId : String
|
|
||||||
, originServerTs : Timestamp
|
|
||||||
, roomId : String
|
|
||||||
, sender : String
|
|
||||||
, stateKey : Maybe String
|
|
||||||
, contentType : String
|
|
||||||
, unsigned : Maybe UnsignedData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeClientEvent : ClientEvent -> E.Value
|
|
||||||
encodeClientEvent data =
|
|
||||||
maybeObject
|
|
||||||
[ ( "content", Just <| data.content )
|
|
||||||
, ( "event_id", Just <| E.string data.eventId )
|
|
||||||
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
|
|
||||||
, ( "room_id", Just <| E.string data.roomId )
|
|
||||||
, ( "sender", Just <| E.string data.sender )
|
|
||||||
, ( "state_key", Maybe.map E.string data.stateKey )
|
|
||||||
, ( "type", Just <| E.string data.contentType )
|
|
||||||
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
clientEventDecoder : D.Decoder ClientEvent
|
|
||||||
clientEventDecoder =
|
|
||||||
D.map8
|
|
||||||
(\a b c d e f g h ->
|
|
||||||
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, contentType = g, unsigned = h }
|
|
||||||
)
|
|
||||||
(D.field "content" D.value)
|
|
||||||
(D.field "event_id" D.string)
|
|
||||||
(D.field "origin_server_ts" timestampDecoder)
|
|
||||||
(D.field "room_id" D.string)
|
|
||||||
(D.field "sender" D.string)
|
|
||||||
(opField "state_key" D.string)
|
|
||||||
(D.field "type" D.string)
|
|
||||||
(opField "unsigned" (D.lazy (\_ -> unsignedDataDecoder)))
|
|
||||||
|
|
||||||
|
|
||||||
{-| Extra information about the event.
|
|
||||||
-}
|
|
||||||
type UnsignedData
|
|
||||||
= UnsignedData
|
|
||||||
{ age : Maybe Int
|
|
||||||
, prevContent : Maybe E.Value
|
|
||||||
, redactedBecause : Maybe ClientEvent
|
|
||||||
, transactionId : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encodeUnsignedData : UnsignedData -> E.Value
|
|
||||||
encodeUnsignedData (UnsignedData data) =
|
|
||||||
maybeObject
|
|
||||||
[ ( "age", Maybe.map E.int data.age )
|
|
||||||
, ( "prev_content", data.prevContent )
|
|
||||||
, ( "redacted_because", Maybe.map encodeClientEvent data.redactedBecause )
|
|
||||||
, ( "transaction_id", Maybe.map E.string data.transactionId )
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
unsignedDataDecoder : D.Decoder UnsignedData
|
|
||||||
unsignedDataDecoder =
|
|
||||||
D.map4
|
|
||||||
(\a b c d ->
|
|
||||||
UnsignedData { age = a, prevContent = b, redactedBecause = c, transactionId = d }
|
|
||||||
)
|
|
||||||
(opField "age" D.int)
|
|
||||||
(opField "prev_content" D.value)
|
|
||||||
(opField "redacted_because" clientEventDecoder)
|
|
||||||
(opField "transaction_id" D.string)
|
|
|
@ -1,40 +0,0 @@
|
||||||
version: v1.5
|
|
||||||
name: SpecObjects
|
|
||||||
objects:
|
|
||||||
ClientEvent:
|
|
||||||
description: Client Event containing all data on an event.
|
|
||||||
fields:
|
|
||||||
content:
|
|
||||||
type: value
|
|
||||||
required: true
|
|
||||||
event_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
origin_server_ts:
|
|
||||||
type: timestamp
|
|
||||||
required: true
|
|
||||||
room_id:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
sender:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
state_key:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
unsigned:
|
|
||||||
type: UnsignedData
|
|
||||||
UnsignedData:
|
|
||||||
anti_recursion: true
|
|
||||||
description: Extra information about the event.
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
type: int
|
|
||||||
prev_content:
|
|
||||||
type: value
|
|
||||||
redacted_because:
|
|
||||||
type: ClientEvent
|
|
||||||
transaction_id:
|
|
||||||
type: string
|
|
|
@ -1,27 +0,0 @@
|
||||||
module Internal.Api.GetEvent.V1_5.Upcast exposing (..)
|
|
||||||
|
|
||||||
import Internal.Api.GetEvent.V1_4.Objects as PO
|
|
||||||
import Internal.Api.GetEvent.V1_5.Objects as O
|
|
||||||
|
|
||||||
|
|
||||||
upcast : PO.ClientEvent -> O.ClientEvent
|
|
||||||
upcast e =
|
|
||||||
{ content = e.content
|
|
||||||
, eventId = e.eventId
|
|
||||||
, originServerTs = e.originServerTs
|
|
||||||
, roomId = e.roomId
|
|
||||||
, sender = e.sender
|
|
||||||
, stateKey = e.stateKey
|
|
||||||
, contentType = e.contentType
|
|
||||||
, unsigned = Maybe.map upcastUnsigned e.unsigned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
upcastUnsigned : PO.UnsignedData -> O.UnsignedData
|
|
||||||
upcastUnsigned (PO.UnsignedData u) =
|
|
||||||
O.UnsignedData
|
|
||||||
{ age = u.age
|
|
||||||
, prevContent = u.prevContent
|
|
||||||
, redactedBecause = Maybe.map upcast u.redactedBecause
|
|
||||||
, transactionId = u.transactionId
|
|
||||||
}
|
|
Loading…
Reference in New Issue