diff --git a/src/Internal/Room.elm b/src/Internal/Room.elm index 6d13c07..32ad1c5 100644 --- a/src/Internal/Room.elm +++ b/src/Internal/Room.elm @@ -92,6 +92,15 @@ accountData key = withoutCredentials >> Internal.accountData key +{-| Add account data to the room. +-} +addAccountData : String -> E.Value -> Room -> Room +addAccountData eventType content (Room { room, context }) = + room + |> Internal.addAccountData eventType content + |> withCredentials context + + {-| Adds an internal event to the `Room`. An internal event is a custom event that has been generated by the client. -} diff --git a/src/Internal/Values/Room.elm b/src/Internal/Values/Room.elm index 260bb50..024639d 100644 --- a/src/Internal/Values/Room.elm +++ b/src/Internal/Values/Room.elm @@ -28,6 +28,13 @@ accountData key (IRoom room) = Dict.get key room.accountData +{-| Add new account data to the room. +-} +addAccountData : String -> E.Value -> IRoom -> IRoom +addAccountData eventType content (IRoom room) = + IRoom { room | accountData = Dict.insert eventType content room.accountData } + + {-| Add the data of a single event to the hashdict of events. -} addEvent : IEvent -> IRoom -> IRoom diff --git a/src/Internal/Vault.elm b/src/Internal/Vault.elm index fa5041d..0067cc6 100644 --- a/src/Internal/Vault.elm +++ b/src/Internal/Vault.elm @@ -122,7 +122,21 @@ updateWith vaultUpdate ((Vault ({ cred, context } as data)) as vault) = -- TODO AccountDataSet input () -> - vault + case input.roomId of + Just rId -> + case getRoomById rId vault of + Just room -> + room + |> Room.addAccountData input.eventType input.content + |> insertRoom + |> (|>) vault + + Nothing -> + vault + + -- TODO: Add global account data + Nothing -> + vault -- TODO BanUser input () ->