Add ephemeral events to Room

pull/31/head
Bram 2024-06-08 15:19:55 +02:00
parent f6a6bb535e
commit 0ded7ab6bd
2 changed files with 28 additions and 1 deletions

View File

@ -313,6 +313,7 @@ fields :
}
, room :
{ accountData : Desc
, ephemeral : Desc
, events : Desc
, roomId : Desc
, state : Desc
@ -486,6 +487,9 @@ fields =
, room =
{ accountData =
[ "Room account data tracking the user's private storage about this room." ]
, ephemeral =
[ "Ephemeral events that were sent recently in this room."
]
, events =
[ "Database containing events that were sent in this room." ]
, roomId =

View File

@ -53,6 +53,7 @@ import Internal.Config.Text as Text
import Internal.Filter.Timeline as Filter exposing (Filter)
import Internal.Tools.Hashdict as Hashdict exposing (Hashdict)
import Internal.Tools.Json as Json
import Internal.Tools.StrippedEvent as StrippedEvent exposing (StrippedEvent)
import Internal.Values.Event as Event exposing (Event)
import Internal.Values.StateManager as StateManager exposing (StateManager)
import Internal.Values.Timeline as Timeline exposing (Timeline)
@ -71,6 +72,7 @@ homeserver.
-}
type alias Room =
{ accountData : Dict String Json.Value
, ephemeral : List StrippedEvent
, events : Hashdict Event
, roomId : String
, state : StateManager
@ -86,7 +88,9 @@ type RoomUpdate
| AddSync Batch
| Invite User
| More (List RoomUpdate)
| Optional (Maybe RoomUpdate)
| SetAccountData String Json.Value
| SetEphemeral (List { eventType : String, content : Json.Value })
{-| Add new events to the Room's event directory + Room's timeline.
@ -140,7 +144,7 @@ addSync =
-}
coder : Json.Coder Room
coder =
Json.object5
Json.object6
{ name = Text.docs.room.name
, description = Text.docs.room.description
, init = Room
@ -154,6 +158,15 @@ coder =
, defaultToString = Json.encode (Json.fastDict Json.value) >> E.encode 0
}
)
(Json.field.optional.withDefault
{ fieldName = "ephemeral"
, toField = .ephemeral
, description = Text.fields.room.ephemeral
, coder = Json.list StrippedEvent.coder
, default = ( [], [] )
, defaultToString = Json.encode (Json.list StrippedEvent.coder) >> E.encode 0
}
)
(Json.field.optional.withDefault
{ fieldName = "events"
, toField = .events
@ -216,6 +229,7 @@ getAccountData key room =
init : String -> Room
init roomId =
{ accountData = Dict.empty
, ephemeral = []
, events = Hashdict.empty .eventId
, roomId = roomId
, state = StateManager.empty
@ -262,5 +276,14 @@ update ru room =
More items ->
List.foldl update room items
Optional (Just u) ->
update u room
Optional Nothing ->
room
SetAccountData key value ->
setAccountData key value room
SetEphemeral eph ->
{ room | ephemeral = eph }