Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980module Brain.Other.State exposing (..)
import Alienimport Brain.Common.State as Commonimport Brain.Ports as Portsimport Brain.Task.Portsimport Brain.Types exposing (..)import Dictimport Json.Decode as Jsonimport List.Extra as Listimport Return exposing (return)import Return.Ext as Returnimport Sources exposing (Service(..))import Sources.Encodingimport Sources.Refresh.AccessTokenimport Time
-- 🔱
refreshedAccessToken : Json.Value -> ManagerrefreshedAccessToken value model = case Json.decodeValue Sources.Refresh.AccessToken.portArgumentsDecoder value of Ok portArguments -> case portArguments.service of Google -> model.hypaethralUserData.sources |> List.find (.id >> (==) portArguments.sourceId) |> Maybe.map (\source -> source.data |> Dict.insert "accessToken" portArguments.accessToken |> Dict.insert "expiresAt" (String.fromInt portArguments.expiresAt) |> (\newData -> { source | data = newData }) ) |> Maybe.map (\source -> source |> Sources.Encoding.encode |> Alien.broadcast Alien.UpdateSourceData |> Ports.toUI ) |> Maybe.withDefault Cmd.none |> return model
_ -> Return.singleton model
Err err -> Common.reportUI Alien.ToCache (Json.errorToString err) model
setCurrentTime : Time.Posix -> ManagersetCurrentTime time model = Return.singleton { model | currentTime = time }
{-| Save alien data to cache.-}toCache : Json.Value -> ManagertoCache data = case Json.decodeValue Alien.hostDecoder data of Ok alienEvent -> case Alien.tagFromString alienEvent.tag of Just tag -> alienEvent.data |> Brain.Task.Ports.toCache tag |> Common.attemptPortTask (always Bypass) |> Return.communicate
Nothing -> Common.reportUI Alien.ToCache "Failed to decode alien tag"
Err err -> err |> Json.errorToString |> Common.reportUI Alien.ToCache