Documentation for Credentials type
parent
3bdcba13bc
commit
186c92c515
|
@ -22,6 +22,7 @@ type alias SyncInputV1 =
|
|||
type alias SyncOutputV1 =
|
||||
Task X.Error SO1.Sync
|
||||
|
||||
|
||||
type alias SyncOutputV2 =
|
||||
Task X.Error SO2.Sync
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import Dict
|
|||
import Internal.Api.Sync.V1.SpecObjects as PO
|
||||
import Internal.Api.Sync.V2.SpecObjects as SO
|
||||
|
||||
|
||||
upcastSync : PO.Sync -> SO.Sync
|
||||
upcastSync old =
|
||||
{ accountData = old.accountData
|
||||
|
@ -12,6 +13,7 @@ upcastSync old =
|
|||
, rooms = Maybe.map upcastRooms old.rooms
|
||||
}
|
||||
|
||||
|
||||
upcastRooms : PO.Rooms -> SO.Rooms
|
||||
upcastRooms old =
|
||||
{ invite = old.invite
|
||||
|
@ -20,6 +22,7 @@ upcastRooms old =
|
|||
, leave = Dict.map (\_ -> upcastLeftRoom) old.leave
|
||||
}
|
||||
|
||||
|
||||
upcastJoinedRoom : PO.JoinedRoom -> SO.JoinedRoom
|
||||
upcastJoinedRoom old =
|
||||
{ accountData = old.accountData
|
||||
|
@ -31,10 +34,12 @@ upcastJoinedRoom old =
|
|||
, unreadThreadNotifications = Dict.empty
|
||||
}
|
||||
|
||||
|
||||
upcastState : PO.State -> SO.State
|
||||
upcastState old =
|
||||
{ events = List.map upcastClientEventWithoutRoomId old.events }
|
||||
|
||||
|
||||
upcastClientEventWithoutRoomId : PO.ClientEventWithoutRoomId -> SO.ClientEventWithoutRoomId
|
||||
upcastClientEventWithoutRoomId old =
|
||||
{ content = old.content
|
||||
|
@ -46,6 +51,7 @@ upcastClientEventWithoutRoomId old =
|
|||
, unsigned = Maybe.map upcastUnsigned old.unsigned
|
||||
}
|
||||
|
||||
|
||||
upcastUnsigned : PO.UnsignedData -> SO.UnsignedData
|
||||
upcastUnsigned (PO.UnsignedData old) =
|
||||
SO.UnsignedData
|
||||
|
@ -55,6 +61,7 @@ upcastUnsigned (PO.UnsignedData old) =
|
|||
, transactionId = old.transactionId
|
||||
}
|
||||
|
||||
|
||||
upcastTimeline : PO.Timeline -> SO.Timeline
|
||||
upcastTimeline old =
|
||||
{ events = List.map upcastClientEventWithoutRoomId old.events
|
||||
|
@ -62,6 +69,7 @@ upcastTimeline old =
|
|||
, prevBatch = old.prevBatch
|
||||
}
|
||||
|
||||
|
||||
upcastLeftRoom : PO.LeftRoom -> SO.LeftRoom
|
||||
upcastLeftRoom old =
|
||||
{ accountData = old.accountData
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
module Internal.Values.Credentials exposing (..)
|
||||
|
||||
{-| The Credentials type is the keychain of the Matrix SDK.
|
||||
It handles all communication with the homeserver.
|
||||
-}
|
||||
|
||||
import Internal.Tools.Hashdict as Hashdict exposing (Hashdict)
|
||||
import Internal.Values.Room as Room exposing (Room)
|
||||
|
||||
|
@ -14,6 +18,23 @@ type AccessToken
|
|||
| UsernameAndPassword { username : String, password : String, accessToken : Maybe String }
|
||||
|
||||
|
||||
{-| Get the access token the Credentials type is using, if any.
|
||||
-}
|
||||
getAccessToken : Credentials -> Maybe String
|
||||
getAccessToken (Credentials { access }) =
|
||||
case access of
|
||||
AccessToken s ->
|
||||
Just s
|
||||
|
||||
NoAccess ->
|
||||
Nothing
|
||||
|
||||
UsernameAndPassword { accessToken } ->
|
||||
accessToken
|
||||
|
||||
|
||||
{-| Internal value to be used as a "default" for credentials settings.
|
||||
-}
|
||||
defaultCredentials : String -> Credentials
|
||||
defaultCredentials homeserver =
|
||||
Credentials
|
||||
|
@ -23,6 +44,8 @@ defaultCredentials homeserver =
|
|||
}
|
||||
|
||||
|
||||
{-| Create a Credentials type using an unknown access token.
|
||||
-}
|
||||
fromAccessToken : { accessToken : String, homeserver : String } -> Credentials
|
||||
fromAccessToken { accessToken, homeserver } =
|
||||
case defaultCredentials homeserver of
|
||||
|
@ -30,6 +53,8 @@ fromAccessToken { accessToken, homeserver } =
|
|||
Credentials { c | access = AccessToken accessToken }
|
||||
|
||||
|
||||
{-| Create a Credentials type using a username and password.
|
||||
-}
|
||||
fromLoginCredentials : { username : String, password : String, homeserver : String } -> Credentials
|
||||
fromLoginCredentials { username, password, homeserver } =
|
||||
case defaultCredentials homeserver of
|
||||
|
@ -37,11 +62,18 @@ fromLoginCredentials { username, password, homeserver } =
|
|||
Credentials { c | access = UsernameAndPassword { username = username, password = password, accessToken = Nothing } }
|
||||
|
||||
|
||||
{-| Get a room from the Credentials type by the room's id.
|
||||
-}
|
||||
getRoomById : String -> Credentials -> Maybe Room
|
||||
getRoomById roomId (Credentials cred) =
|
||||
Hashdict.get roomId cred.rooms
|
||||
|
||||
|
||||
{-| Add a new room to the Credentials type. If a room with this id already exists, it is overwritten.
|
||||
|
||||
This function can hence also be used as an update function for rooms.
|
||||
|
||||
-}
|
||||
insertRoom : Room -> Credentials -> Credentials
|
||||
insertRoom room (Credentials cred) =
|
||||
Credentials
|
||||
|
|
Loading…
Reference in New Issue