contentType --> eventType

pull/1/head
Bram van den Heuvel 2023-03-31 13:50:05 +02:00
parent 1e1d9490bf
commit 01f97255fe
22 changed files with 113 additions and 106 deletions

View File

@ -179,6 +179,8 @@ def main(in_file, out_file):
return DictField(str_to_field(value[1:-1]))
if value in OBJECTS:
return SpecObjectField(value)
if value.startswith('Enums.'):
return EnumField(value[len('Enums.'):])
match value:
case 'value':
@ -210,7 +212,7 @@ def main(in_file, out_file):
@property
def elm_name(self):
if self.key == 'type':
return 'contentType'
return 'eventType'
else:
words = self.key.lower().replace('_', ' ').replace('.', ' ').split(' ')
words = ''.join([w.capitalize() for w in words])

View File

@ -139,7 +139,7 @@ cookies =
|> Matrix.Room.mostRecentEvents
|> List.filterMap
(\event ->
case Matrix.Event.contentType event of
case Matrix.Event.eventType event of
"me.noordstar.demo_cookie" ->
Just (Matrix.Event.sender event)

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ module Internal.Api.GetEvent.V1.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1676311233
Last generated at Unix time 1680263083
-}
@ -29,7 +29,7 @@ type alias ClientEvent =
, roomId : String
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned : Maybe UnsignedData
}
@ -43,7 +43,7 @@ encodeClientEvent data =
, ( "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 )
, ( "type", Just <| E.string data.eventType )
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
]
@ -52,7 +52,7 @@ 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 }
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, eventType = g, unsigned = h }
)
(D.field "content" D.value)
(D.field "event_id" D.string)

View File

@ -9,7 +9,7 @@ module Internal.Api.GetMessages.V1.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1679486096
Last generated at Unix time 1680263083
-}
@ -59,7 +59,7 @@ type alias RoomEvent =
, prevContent : Maybe E.Value
, roomId : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, userId : String
}
@ -74,7 +74,7 @@ encodeRoomEvent data =
, ( "prev_content", data.prevContent )
, ( "room_id", Just <| E.string data.roomId )
, ( "state_key", Maybe.map E.string data.stateKey )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
, ( "user_id", Just <| E.string data.userId )
]
@ -83,7 +83,7 @@ roomEventDecoder : D.Decoder RoomEvent
roomEventDecoder =
D.map9
(\a b c d e f g h i ->
{ age = a, content = b, eventId = c, originServerTs = d, prevContent = e, roomId = f, stateKey = g, contentType = h, userId = i }
{ age = a, content = b, eventId = c, originServerTs = d, prevContent = e, roomId = f, stateKey = g, eventType = h, userId = i }
)
(opField "age" D.int)
(D.field "content" D.value)

View File

@ -12,7 +12,7 @@ module Internal.Api.GetMessages.V2.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1679486096
Last generated at Unix time 1680263083
-}
@ -62,7 +62,7 @@ type alias RoomEvent =
, roomId : String
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned : Maybe UnsignedData
}
@ -77,7 +77,7 @@ encodeRoomEvent data =
, ( "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 )
, ( "type", Just <| E.string data.eventType )
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
]
@ -86,7 +86,7 @@ roomEventDecoder : D.Decoder RoomEvent
roomEventDecoder =
D.map9
(\a b c d e f g h i ->
{ content = a, eventId = b, originServerTs = c, prevContent = d, roomId = e, sender = f, stateKey = g, contentType = h, unsigned = i }
{ content = a, eventId = b, originServerTs = c, prevContent = d, roomId = e, sender = f, stateKey = g, eventType = h, unsigned = i }
)
(D.field "content" D.value)
(D.field "event_id" D.string)

View File

@ -19,7 +19,7 @@ upcastRoomEvent old =
, originServerTs = old.originServerTs
, roomId = old.roomId
, sender = old.userId
, contentType = old.contentType
, eventType = old.eventType
, prevContent = old.prevContent
, stateKey = old.stateKey
, unsigned =

View File

@ -15,7 +15,7 @@ module Internal.Api.GetMessages.V3.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1679486096
Last generated at Unix time 1680263083
-}
@ -68,7 +68,7 @@ type alias RoomEvent =
, roomId : String
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned : Maybe UnsignedData
}
@ -83,7 +83,7 @@ encodeRoomEvent data =
, ( "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 )
, ( "type", Just <| E.string data.eventType )
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
]
@ -92,7 +92,7 @@ roomEventDecoder : D.Decoder RoomEvent
roomEventDecoder =
D.map9
(\a b c d e f g h i ->
{ content = a, eventId = b, originServerTs = c, prevContent = d, roomId = e, sender = f, stateKey = g, contentType = h, unsigned = i }
{ content = a, eventId = b, originServerTs = c, prevContent = d, roomId = e, sender = f, stateKey = g, eventType = h, unsigned = i }
)
(D.field "content" D.value)
(D.field "event_id" D.string)
@ -115,7 +115,7 @@ type alias RoomStateEvent =
, roomId : String
, sender : String
, stateKey : String
, contentType : String
, eventType : String
, unsigned : Maybe UnsignedData
}
@ -130,7 +130,7 @@ encodeRoomStateEvent data =
, ( "room_id", Just <| E.string data.roomId )
, ( "sender", Just <| E.string data.sender )
, ( "state_key", Just <| E.string data.stateKey )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
]
@ -139,7 +139,7 @@ roomStateEventDecoder : D.Decoder RoomStateEvent
roomStateEventDecoder =
D.map9
(\a b c d e f g h i ->
{ content = a, eventId = b, originServerTs = c, prevContent = d, roomId = e, sender = f, stateKey = g, contentType = h, unsigned = i }
{ content = a, eventId = b, originServerTs = c, prevContent = d, roomId = e, sender = f, stateKey = g, eventType = h, unsigned = i }
)
(D.field "content" D.value)
(D.field "event_id" D.string)

View File

@ -20,7 +20,7 @@ upcastRoomEvent old =
, originServerTs = old.originServerTs
, roomId = old.roomId
, sender = old.sender
, contentType = old.contentType
, eventType = old.eventType
, prevContent = old.prevContent
, stateKey = old.stateKey
, unsigned =

View File

@ -12,7 +12,7 @@ module Internal.Api.GetMessages.V4.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1679486096
Last generated at Unix time 1680263084
-}
@ -32,7 +32,7 @@ type alias ClientEvent =
, roomId : String
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned : Maybe UnsignedData
}
@ -46,7 +46,7 @@ encodeClientEvent data =
, ( "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 )
, ( "type", Just <| E.string data.eventType )
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
]
@ -55,7 +55,7 @@ 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 }
{ content = a, eventId = b, originServerTs = c, roomId = d, sender = e, stateKey = f, eventType = g, unsigned = h }
)
(D.field "content" D.value)
(D.field "event_id" D.string)

View File

@ -22,7 +22,7 @@ upcastRoomEvent old =
, roomId = old.roomId
, sender = old.sender
, stateKey = old.stateKey
, contentType = old.contentType
, eventType = old.eventType
, unsigned = Maybe.map (upcastUnsigned old.prevContent) old.unsigned
}
@ -35,7 +35,7 @@ upcastRoomStateEvent old =
, roomId = old.roomId
, sender = old.sender
, stateKey = Just old.stateKey
, contentType = old.contentType
, eventType = old.eventType
, unsigned = Maybe.map (upcastUnsigned old.prevContent) old.unsigned
}

View File

@ -60,7 +60,7 @@ module Internal.Api.Sync.V1.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1676625734
Last generated at Unix time 1680263084
-}
@ -103,7 +103,7 @@ type alias ClientEventWithoutRoomId =
, originServerTs : Timestamp
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned : Maybe UnsignedData
}
@ -116,7 +116,7 @@ encodeClientEventWithoutRoomId data =
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
, ( "sender", Just <| E.string data.sender )
, ( "state_key", Maybe.map E.string data.stateKey )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
]
@ -125,7 +125,7 @@ clientEventWithoutRoomIdDecoder : D.Decoder ClientEventWithoutRoomId
clientEventWithoutRoomIdDecoder =
D.map7
(\a b c d e f g ->
{ content = a, eventId = b, originServerTs = c, sender = d, stateKey = e, contentType = f, unsigned = g }
{ content = a, eventId = b, originServerTs = c, sender = d, stateKey = e, eventType = f, unsigned = g }
)
(D.field "content" D.value)
(D.field "event_id" D.string)
@ -163,7 +163,7 @@ ephemeralDecoder =
-}
type alias Event =
{ content : E.Value
, contentType : String
, eventType : String
}
@ -171,7 +171,7 @@ encodeEvent : Event -> E.Value
encodeEvent data =
maybeObject
[ ( "content", Just <| data.content )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
]
@ -179,7 +179,7 @@ eventDecoder : D.Decoder Event
eventDecoder =
D.map2
(\a b ->
{ content = a, contentType = b }
{ content = a, eventType = b }
)
(D.field "content" D.value)
(D.field "type" D.string)
@ -457,7 +457,7 @@ type alias StrippedStateEvent =
{ content : E.Value
, sender : String
, stateKey : String
, contentType : String
, eventType : String
}
@ -467,7 +467,7 @@ encodeStrippedStateEvent data =
[ ( "content", Just <| data.content )
, ( "sender", Just <| E.string data.sender )
, ( "state_key", Just <| E.string data.stateKey )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
]
@ -475,7 +475,7 @@ strippedStateEventDecoder : D.Decoder StrippedStateEvent
strippedStateEventDecoder =
D.map4
(\a b c d ->
{ content = a, sender = b, stateKey = c, contentType = d }
{ content = a, sender = b, stateKey = c, eventType = d }
)
(D.field "content" D.value)
(D.field "sender" D.string)

View File

@ -63,7 +63,7 @@ module Internal.Api.Sync.V2.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1676625735
Last generated at Unix time 1680263084
-}
@ -106,7 +106,7 @@ type alias ClientEventWithoutRoomId =
, originServerTs : Timestamp
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned : Maybe UnsignedData
}
@ -119,7 +119,7 @@ encodeClientEventWithoutRoomId data =
, ( "origin_server_ts", Just <| encodeTimestamp data.originServerTs )
, ( "sender", Just <| E.string data.sender )
, ( "state_key", Maybe.map E.string data.stateKey )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
, ( "unsigned", Maybe.map encodeUnsignedData data.unsigned )
]
@ -128,7 +128,7 @@ clientEventWithoutRoomIdDecoder : D.Decoder ClientEventWithoutRoomId
clientEventWithoutRoomIdDecoder =
D.map7
(\a b c d e f g ->
{ content = a, eventId = b, originServerTs = c, sender = d, stateKey = e, contentType = f, unsigned = g }
{ content = a, eventId = b, originServerTs = c, sender = d, stateKey = e, eventType = f, unsigned = g }
)
(D.field "content" D.value)
(D.field "event_id" D.string)
@ -166,7 +166,7 @@ ephemeralDecoder =
-}
type alias Event =
{ content : E.Value
, contentType : String
, eventType : String
}
@ -174,7 +174,7 @@ encodeEvent : Event -> E.Value
encodeEvent data =
maybeObject
[ ( "content", Just <| data.content )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
]
@ -182,7 +182,7 @@ eventDecoder : D.Decoder Event
eventDecoder =
D.map2
(\a b ->
{ content = a, contentType = b }
{ content = a, eventType = b }
)
(D.field "content" D.value)
(D.field "type" D.string)
@ -463,7 +463,7 @@ type alias StrippedStateEvent =
{ content : E.Value
, sender : String
, stateKey : String
, contentType : String
, eventType : String
}
@ -473,7 +473,7 @@ encodeStrippedStateEvent data =
[ ( "content", Just <| data.content )
, ( "sender", Just <| E.string data.sender )
, ( "state_key", Just <| E.string data.stateKey )
, ( "type", Just <| E.string data.contentType )
, ( "type", Just <| E.string data.eventType )
]
@ -481,7 +481,7 @@ strippedStateEventDecoder : D.Decoder StrippedStateEvent
strippedStateEventDecoder =
D.map4
(\a b c d ->
{ content = a, sender = b, stateKey = c, contentType = d }
{ content = a, sender = b, stateKey = c, eventType = d }
)
(D.field "content" D.value)
(D.field "sender" D.string)

View File

@ -47,7 +47,7 @@ upcastClientEventWithoutRoomId old =
, originServerTs = old.originServerTs
, sender = old.sender
, stateKey = old.stateKey
, contentType = old.contentType
, eventType = old.eventType
, unsigned = Maybe.map upcastUnsigned old.unsigned
}

View File

@ -49,7 +49,7 @@ initFromGetEvent output =
, roomId = output.roomId
, sender = output.sender
, stateKey = output.stateKey
, contentType = output.contentType
, eventType = output.eventType
, unsigned =
output.unsigned
|> Maybe.map
@ -75,7 +75,7 @@ initFromGetMessages output =
, roomId = output.roomId
, sender = output.sender
, stateKey = output.stateKey
, contentType = output.contentType
, eventType = output.eventType
, unsigned =
output.unsigned
|> Maybe.map
@ -101,7 +101,7 @@ initFromClientEventWithoutRoomId rId output =
, roomId = rId
, sender = output.sender
, stateKey = output.stateKey
, contentType = output.contentType
, eventType = output.eventType
, unsigned =
output.unsigned
|> Maybe.map
@ -156,9 +156,9 @@ stateKey =
withoutCredentials >> Internal.stateKey
contentType : Event -> String
contentType =
withoutCredentials >> Internal.contentType
eventType : Event -> String
eventType =
withoutCredentials >> Internal.eventType
age : Event -> Maybe Int

View File

@ -39,7 +39,7 @@ withoutCredentials (RoomInvite { invite }) =
invite
getEvent : { contentType : String, stateKey : String } -> RoomInvite -> Maybe Internal.RoomInviteEvent
getEvent : { eventType : String, stateKey : String } -> RoomInvite -> Maybe Internal.RoomInviteEvent
getEvent data =
withoutCredentials >> Internal.getEvent data

View File

@ -44,7 +44,7 @@ initFromJoinedRoom data jroom =
jroom.accountData
|> Maybe.map .events
|> Maybe.withDefault []
|> List.map (\{ contentType, content } -> ( contentType, content ))
|> List.map (\{ eventType, content } -> ( eventType, content ))
|> Dict.fromList
, ephemeral =
jroom.ephemeral
@ -86,6 +86,11 @@ initFromJoinedRoom data jroom =
}
accountData : String -> Room -> Maybe E.Value
accountData key =
withoutCredentials >> Internal.accountData key
{-| Adds an internal event to the `Room`. An internal event is a custom event
that has been generated by the client.
-}

View File

@ -12,7 +12,7 @@ type IEvent
, roomId : String
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned :
Maybe
{ age : Maybe Int
@ -30,7 +30,7 @@ init :
, roomId : String
, sender : String
, stateKey : Maybe String
, contentType : String
, eventType : String
, unsigned :
Maybe
{ age : Maybe Int
@ -78,9 +78,9 @@ stateKey (IEvent e) =
e.stateKey
contentType : IEvent -> String
contentType (IEvent e) =
e.contentType
eventType : IEvent -> String
eventType (IEvent e) =
e.eventType
age : IEvent -> Maybe Int
@ -102,7 +102,7 @@ transactionId (IEvent e) =
type BlindEvent
= BlindEvent { contentType : String, content : E.Value }
= BlindEvent { eventType : String, content : E.Value }
blindContent : BlindEvent -> E.Value
@ -112,4 +112,4 @@ blindContent (BlindEvent be) =
blindContentType : BlindEvent -> String
blindContentType (BlindEvent be) =
be.contentType
be.eventType

View File

@ -19,24 +19,24 @@ type RoomInviteEvent
{ content : E.Value
, sender : String
, stateKey : String
, contentType : String
, eventType : String
}
init : { roomId : String, events : List { content : E.Value, sender : String, stateKey : String, contentType : String } } -> IRoomInvite
init : { roomId : String, events : List { content : E.Value, sender : String, stateKey : String, eventType : String } } -> IRoomInvite
init data =
data.events
|> List.map
(\event ->
( ( event.contentType, event.stateKey ), RoomInviteEvent event )
( ( event.eventType, event.stateKey ), RoomInviteEvent event )
)
|> Dict.fromList
|> (\e -> IRoomInvite { roomId = data.roomId, events = e })
getEvent : { contentType : String, stateKey : String } -> IRoomInvite -> Maybe RoomInviteEvent
getEvent : { eventType : String, stateKey : String } -> IRoomInvite -> Maybe RoomInviteEvent
getEvent data (IRoomInvite { events }) =
Dict.get ( data.contentType, data.stateKey ) events
Dict.get ( data.eventType, data.stateKey ) events
getAllEvents : IRoomInvite -> List RoomInviteEvent
@ -64,6 +64,6 @@ stateKey (RoomInviteEvent data) =
data.stateKey
contentType : RoomInviteEvent -> String
contentType (RoomInviteEvent data) =
data.contentType
eventType : RoomInviteEvent -> String
eventType (RoomInviteEvent data) =
data.eventType

View File

@ -12,7 +12,7 @@ addEvent : IEvent -> StateManager -> StateManager
addEvent event oldManager =
case Event.stateKey event of
Just key ->
Dict.insert ( Event.contentType event, key ) event oldManager
Dict.insert ( Event.eventType event, key ) event oldManager
Nothing ->
oldManager

View File

@ -1,5 +1,5 @@
module Matrix.Event exposing
( Event, contentType, content, stateKey
( Event, eventType, content, stateKey
, eventId, roomId, sender, originServerTs, redactedBecause
)
@ -8,7 +8,7 @@ module Matrix.Event exposing
# Event
@docs Event, contentType, content, stateKey
@docs Event, eventType, content, stateKey
## Getting metadata
@ -75,9 +75,9 @@ stateKey =
{-| This is the type of the event's content. For example, `m.room.message` indicates that it was a message.
-}
contentType : Event -> String
contentType =
Internal.contentType
eventType : Event -> String
eventType =
Internal.eventType
{-| In case the event was redacted, this event will point you to the event that redacted it.

View File

@ -1,7 +1,7 @@
module Matrix.RoomInvite exposing
( RoomInvite, accept, reject, acceptWithReason, rejectWithReason
, roomId, RoomInviteEvent, getEvent, getAllEvents
, sender, stateKey, contentType, content
, sender, stateKey, eventType, content
)
{-| Sometimes, your user will be invited to a new room!
@ -26,7 +26,7 @@ want to see.
Once you have the event you want, you can explore it with the following functions.
@docs sender, stateKey, contentType, content
@docs sender, stateKey, eventType, content
-}
@ -105,9 +105,9 @@ content =
{-| Get the event's content type.
-}
contentType : RoomInviteEvent -> String
contentType =
IR.contentType
eventType : RoomInviteEvent -> String
eventType =
IR.eventType
{-| Get the event's state key.
@ -119,7 +119,7 @@ stateKey =
{-| Get a specific event with a specific event content type and state key, if it exists.
-}
getEvent : { contentType : String, stateKey : String } -> RoomInvite -> Maybe RoomInviteEvent
getEvent : { eventType : String, stateKey : String } -> RoomInvite -> Maybe RoomInviteEvent
getEvent data invite =
invite
|> Internal.withoutCredentials