Add requesting user data.
This commit is contained in:
parent
2505610aa2
commit
2449a3c8c4
|
@ -60,6 +60,7 @@ update msg model = case msg of
|
|||
ReceiveLoginResponse r -> updateLoginResponse model r
|
||||
ReceiveFirstSyncResponse r -> updateSyncResponse model r False
|
||||
ReceiveSyncResponse r -> updateSyncResponse model r True
|
||||
ReceiveUserData s r -> (model, Cmd.none)
|
||||
ChangeRoomText r t -> ({ model | roomText = Dict.insert r t model.roomText}, Cmd.none)
|
||||
SendRoomText r -> updateSendRoomText model r
|
||||
SendRoomTextResponse r -> (model, Cmd.none)
|
||||
|
|
|
@ -3,6 +3,7 @@ import Scylla.Model exposing (..)
|
|||
import Scylla.Api exposing (..)
|
||||
import Scylla.Sync exposing (syncResponseDecoder)
|
||||
import Scylla.Login exposing (loginResponseDecoder, Username, Password)
|
||||
import Scylla.UserData exposing (userDataDecoder, UserData)
|
||||
import Json.Encode exposing (object, string, int)
|
||||
import Http exposing (request, emptyBody, jsonBody, expectJson, expectWhatever)
|
||||
|
||||
|
@ -66,3 +67,14 @@ login apiUrl username password = request
|
|||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
userData : ApiUrl -> ApiToken -> Username -> Cmd Msg
|
||||
userData apiUrl token username = request
|
||||
{ method = "GET"
|
||||
, headers = authenticatedHeaders token
|
||||
, url = (fullUrl apiUrl) ++ "/profile/" ++ username
|
||||
, body = emptyBody
|
||||
, expect = expectJson (ReceiveUserData username) userDataDecoder
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ module Scylla.Model exposing (..)
|
|||
import Scylla.Api exposing (..)
|
||||
import Scylla.Sync exposing (SyncResponse, JoinedRoom)
|
||||
import Scylla.Login exposing (LoginResponse, Username, Password)
|
||||
import Scylla.UserData exposing (UserData)
|
||||
import Scylla.Route exposing (Route)
|
||||
import Browser.Navigation as Nav
|
||||
import Dict exposing (Dict)
|
||||
|
@ -35,4 +36,5 @@ type Msg =
|
|||
| ReceiveFirstSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
||||
| ReceiveSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
||||
| ReceiveLoginResponse (Result Http.Error LoginResponse) -- HTTP, Login has finished
|
||||
| ReceiveUserData Username (Result Http.Error UserData)
|
||||
|
||||
|
|
14
src/Scylla/UserData.elm
Normal file
14
src/Scylla/UserData.elm
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Scylla.UserData exposing (..)
|
||||
import Json.Decode as Decode exposing (Decoder, int, string, float, list, value, dict, bool, field)
|
||||
import Json.Decode.Pipeline exposing (required, optional)
|
||||
|
||||
type alias UserData =
|
||||
{ displayName : Maybe String
|
||||
, avatarUrl : Maybe String
|
||||
}
|
||||
|
||||
userDataDecoder : Decoder UserData
|
||||
userDataDecoder =
|
||||
Decode.succeed UserData
|
||||
|> optional "displayname" (Decode.map Just string) Nothing
|
||||
|> optional "avatar_url" (Decode.map Just string) Nothing
|
Loading…
Reference in New Issue
Block a user