Documentation for Credentials type
parent
3bdcba13bc
commit
186c92c515
|
@ -22,6 +22,7 @@ type alias SyncInputV1 =
|
||||||
type alias SyncOutputV1 =
|
type alias SyncOutputV1 =
|
||||||
Task X.Error SO1.Sync
|
Task X.Error SO1.Sync
|
||||||
|
|
||||||
|
|
||||||
type alias SyncOutputV2 =
|
type alias SyncOutputV2 =
|
||||||
Task X.Error SO2.Sync
|
Task X.Error SO2.Sync
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Dict
|
||||||
import Internal.Api.Sync.V1.SpecObjects as PO
|
import Internal.Api.Sync.V1.SpecObjects as PO
|
||||||
import Internal.Api.Sync.V2.SpecObjects as SO
|
import Internal.Api.Sync.V2.SpecObjects as SO
|
||||||
|
|
||||||
|
|
||||||
upcastSync : PO.Sync -> SO.Sync
|
upcastSync : PO.Sync -> SO.Sync
|
||||||
upcastSync old =
|
upcastSync old =
|
||||||
{ accountData = old.accountData
|
{ accountData = old.accountData
|
||||||
|
@ -12,6 +13,7 @@ upcastSync old =
|
||||||
, rooms = Maybe.map upcastRooms old.rooms
|
, rooms = Maybe.map upcastRooms old.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
upcastRooms : PO.Rooms -> SO.Rooms
|
upcastRooms : PO.Rooms -> SO.Rooms
|
||||||
upcastRooms old =
|
upcastRooms old =
|
||||||
{ invite = old.invite
|
{ invite = old.invite
|
||||||
|
@ -20,6 +22,7 @@ upcastRooms old =
|
||||||
, leave = Dict.map (\_ -> upcastLeftRoom) old.leave
|
, leave = Dict.map (\_ -> upcastLeftRoom) old.leave
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
upcastJoinedRoom : PO.JoinedRoom -> SO.JoinedRoom
|
upcastJoinedRoom : PO.JoinedRoom -> SO.JoinedRoom
|
||||||
upcastJoinedRoom old =
|
upcastJoinedRoom old =
|
||||||
{ accountData = old.accountData
|
{ accountData = old.accountData
|
||||||
|
@ -31,10 +34,12 @@ upcastJoinedRoom old =
|
||||||
, unreadThreadNotifications = Dict.empty
|
, unreadThreadNotifications = Dict.empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
upcastState : PO.State -> SO.State
|
upcastState : PO.State -> SO.State
|
||||||
upcastState old =
|
upcastState old =
|
||||||
{ events = List.map upcastClientEventWithoutRoomId old.events }
|
{ events = List.map upcastClientEventWithoutRoomId old.events }
|
||||||
|
|
||||||
|
|
||||||
upcastClientEventWithoutRoomId : PO.ClientEventWithoutRoomId -> SO.ClientEventWithoutRoomId
|
upcastClientEventWithoutRoomId : PO.ClientEventWithoutRoomId -> SO.ClientEventWithoutRoomId
|
||||||
upcastClientEventWithoutRoomId old =
|
upcastClientEventWithoutRoomId old =
|
||||||
{ content = old.content
|
{ content = old.content
|
||||||
|
@ -46,6 +51,7 @@ upcastClientEventWithoutRoomId old =
|
||||||
, unsigned = Maybe.map upcastUnsigned old.unsigned
|
, unsigned = Maybe.map upcastUnsigned old.unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
upcastUnsigned : PO.UnsignedData -> SO.UnsignedData
|
upcastUnsigned : PO.UnsignedData -> SO.UnsignedData
|
||||||
upcastUnsigned (PO.UnsignedData old) =
|
upcastUnsigned (PO.UnsignedData old) =
|
||||||
SO.UnsignedData
|
SO.UnsignedData
|
||||||
|
@ -55,6 +61,7 @@ upcastUnsigned (PO.UnsignedData old) =
|
||||||
, transactionId = old.transactionId
|
, transactionId = old.transactionId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
upcastTimeline : PO.Timeline -> SO.Timeline
|
upcastTimeline : PO.Timeline -> SO.Timeline
|
||||||
upcastTimeline old =
|
upcastTimeline old =
|
||||||
{ events = List.map upcastClientEventWithoutRoomId old.events
|
{ events = List.map upcastClientEventWithoutRoomId old.events
|
||||||
|
@ -62,6 +69,7 @@ upcastTimeline old =
|
||||||
, prevBatch = old.prevBatch
|
, prevBatch = old.prevBatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
upcastLeftRoom : PO.LeftRoom -> SO.LeftRoom
|
upcastLeftRoom : PO.LeftRoom -> SO.LeftRoom
|
||||||
upcastLeftRoom old =
|
upcastLeftRoom old =
|
||||||
{ accountData = old.accountData
|
{ accountData = old.accountData
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
module Internal.Values.Credentials exposing (..)
|
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.Tools.Hashdict as Hashdict exposing (Hashdict)
|
||||||
import Internal.Values.Room as Room exposing (Room)
|
import Internal.Values.Room as Room exposing (Room)
|
||||||
|
|
||||||
|
@ -14,6 +18,23 @@ type AccessToken
|
||||||
| UsernameAndPassword { username : String, password : String, accessToken : Maybe String }
|
| 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 : String -> Credentials
|
||||||
defaultCredentials homeserver =
|
defaultCredentials homeserver =
|
||||||
Credentials
|
Credentials
|
||||||
|
@ -23,6 +44,8 @@ defaultCredentials homeserver =
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{-| Create a Credentials type using an unknown access token.
|
||||||
|
-}
|
||||||
fromAccessToken : { accessToken : String, homeserver : String } -> Credentials
|
fromAccessToken : { accessToken : String, homeserver : String } -> Credentials
|
||||||
fromAccessToken { accessToken, homeserver } =
|
fromAccessToken { accessToken, homeserver } =
|
||||||
case defaultCredentials homeserver of
|
case defaultCredentials homeserver of
|
||||||
|
@ -30,6 +53,8 @@ fromAccessToken { accessToken, homeserver } =
|
||||||
Credentials { c | access = AccessToken accessToken }
|
Credentials { c | access = AccessToken accessToken }
|
||||||
|
|
||||||
|
|
||||||
|
{-| Create a Credentials type using a username and password.
|
||||||
|
-}
|
||||||
fromLoginCredentials : { username : String, password : String, homeserver : String } -> Credentials
|
fromLoginCredentials : { username : String, password : String, homeserver : String } -> Credentials
|
||||||
fromLoginCredentials { username, password, homeserver } =
|
fromLoginCredentials { username, password, homeserver } =
|
||||||
case defaultCredentials homeserver of
|
case defaultCredentials homeserver of
|
||||||
|
@ -37,11 +62,18 @@ fromLoginCredentials { username, password, homeserver } =
|
||||||
Credentials { c | access = UsernameAndPassword { username = username, password = password, accessToken = Nothing } }
|
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 : String -> Credentials -> Maybe Room
|
||||||
getRoomById roomId (Credentials cred) =
|
getRoomById roomId (Credentials cred) =
|
||||||
Hashdict.get roomId cred.rooms
|
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 -> Credentials
|
||||||
insertRoom room (Credentials cred) =
|
insertRoom room (Credentials cred) =
|
||||||
Credentials
|
Credentials
|
||||||
|
|
Loading…
Reference in New Issue