Expose account_data getter/setter functions
parent
ff84d70d7f
commit
54f99f0f05
|
@ -13,6 +13,7 @@ import Internal.Api.JoinRoomById.Main exposing (JoinRoomByIdInput)
|
|||
import Internal.Api.JoinedMembers.Main exposing (JoinedMembersInput)
|
||||
import Internal.Api.Leave.Main exposing (LeaveInput)
|
||||
import Internal.Api.SendStateKey.Main exposing (SendStateKeyInput)
|
||||
import Internal.Api.SetAccountData.Main exposing (SetAccountInput)
|
||||
import Internal.Api.Sync.Main exposing (SyncInput)
|
||||
import Internal.Api.VaultUpdate as C
|
||||
import Json.Encode as E
|
||||
|
@ -137,6 +138,13 @@ sendStateEvent data cred =
|
|||
|> C.toTask
|
||||
|
||||
|
||||
setAccountData : SetAccountInput -> Credentials -> FutureTask
|
||||
setAccountData data cred =
|
||||
C.makeVBA cred
|
||||
|> Chain.andThen (C.setAccountData data)
|
||||
|> C.toTask
|
||||
|
||||
|
||||
sync : SyncInput -> Credentials -> FutureTask
|
||||
sync data cred =
|
||||
C.makeVBA cred
|
||||
|
|
|
@ -260,3 +260,10 @@ sendMessages pieces (Room { context, room }) =
|
|||
leave : Room -> Task X.Error VaultUpdate
|
||||
leave ((Room { context }) as r) =
|
||||
Api.leave { roomId = roomId r, reason = Nothing } context
|
||||
|
||||
|
||||
{-| Set account data.
|
||||
-}
|
||||
setAccountData : String -> E.Value -> Room -> Task X.Error VaultUpdate
|
||||
setAccountData key value ((Room { context }) as r) =
|
||||
Api.setAccountData { content = value, eventType = key, roomId = Just (roomId r) } context
|
||||
|
|
|
@ -335,6 +335,13 @@ updateWith vaultUpdate ((Vault ({ cred, context } as data)) as vault) =
|
|||
Vault { data | context = Credentials.addToken output.accessToken context }
|
||||
|
||||
|
||||
{-| Set personal account data
|
||||
-}
|
||||
setAccountData : String -> E.Value -> Vault -> Task X.Error VaultUpdate
|
||||
setAccountData key value (Vault { context }) =
|
||||
Api.setAccountData { content = value, eventType = key, roomId = Nothing } context
|
||||
|
||||
|
||||
{-| Synchronize vault
|
||||
-}
|
||||
sync : Vault -> Task X.Error VaultUpdate
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module Matrix exposing
|
||||
( Vault, fromLoginCredentials, fromAccessToken
|
||||
, sync, VaultUpdate, updateWith
|
||||
, getRooms, getRoomById, getInvites
|
||||
, joinRoomById
|
||||
, getRooms, getRoomById, getInvites, accountData
|
||||
, joinRoomById, setAccountData
|
||||
)
|
||||
|
||||
{-| This is the main module of the SDK. Here, you will find basic functions to
|
||||
|
@ -21,12 +21,12 @@ interact with the API.
|
|||
|
||||
# Exploring your vault
|
||||
|
||||
@docs getRooms, getRoomById, getInvites
|
||||
@docs getRooms, getRoomById, getInvites, accountData
|
||||
|
||||
|
||||
# Taking action
|
||||
|
||||
@docs joinRoomById
|
||||
@docs joinRoomById, setAccountData
|
||||
|
||||
-}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import Internal.Invite exposing (RoomInvite)
|
|||
import Internal.Room exposing (Room)
|
||||
import Internal.Tools.Exceptions as X
|
||||
import Internal.Vault
|
||||
import Json.Encode as E
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
|
@ -121,8 +122,26 @@ getInvites =
|
|||
Internal.Vault.getInvites
|
||||
|
||||
|
||||
{-| Account data is personal information that the homeserver will remember for you.
|
||||
|
||||
The information will be kept there, and will remain visible if you log in elsewhere.
|
||||
Other users cannot see this information.
|
||||
|
||||
-}
|
||||
accountData : String -> Vault -> Maybe E.Value
|
||||
accountData =
|
||||
Internal.Vault.accountData
|
||||
|
||||
|
||||
{-| Join a Matrix room based on its room id.
|
||||
-}
|
||||
joinRoomById : String -> Vault -> Task X.Error VaultUpdate
|
||||
joinRoomById =
|
||||
Internal.Vault.joinRoomById
|
||||
|
||||
|
||||
{-| Update the user's personal account data. This saves the information on the homeserver's side and keeps it available for future use.
|
||||
-}
|
||||
setAccountData : String -> E.Value -> Vault -> Task X.Error VaultUpdate
|
||||
setAccountData =
|
||||
Internal.Vault.setAccountData
|
||||
|
|
|
@ -2,6 +2,7 @@ module Matrix.Room exposing
|
|||
( Room, roomId, mostRecentEvents, findOlderEvents
|
||||
, stateEvent, accountData
|
||||
, sendMessage, sendMessages, sendOneEvent, sendMultipleEvents
|
||||
, setAccountData
|
||||
)
|
||||
|
||||
{-| This module provides functions for working with Matrix rooms.
|
||||
|
@ -23,6 +24,11 @@ A room represents a channel of communication within a Matrix home server.
|
|||
|
||||
@docs sendMessage, sendMessages, sendOneEvent, sendMultipleEvents
|
||||
|
||||
|
||||
# Changing a room
|
||||
|
||||
@docs setAccountData
|
||||
|
||||
-}
|
||||
|
||||
import Internal.Api.VaultUpdate exposing (VaultUpdate)
|
||||
|
@ -161,3 +167,13 @@ Keep in mind that this function doesn't send the events in order, it just makes
|
|||
sendMultipleEvents : List { content : E.Value, eventType : String, stateKey : Maybe String } -> Room -> List (Task X.Error VaultUpdate)
|
||||
sendMultipleEvents =
|
||||
Internal.sendEvents
|
||||
|
||||
|
||||
{-| Save personal account data on this room.
|
||||
|
||||
The homeserver will save this information on this room, but it will only be visible to the user who sent it.
|
||||
|
||||
-}
|
||||
setAccountData : String -> E.Value -> Room -> Task X.Error VaultUpdate
|
||||
setAccountData =
|
||||
Internal.setAccountData
|
||||
|
|
Loading…
Reference in New Issue