Scylla/src/Scylla/Model.elm

44 lines
1.8 KiB
Elm
Raw Normal View History

2018-12-08 13:49:30 -08:00
module Scylla.Model exposing (..)
import Scylla.Api exposing (..)
2018-12-13 13:42:23 -08:00
import Scylla.Sync exposing (SyncResponse, JoinedRoom, senderName)
2018-12-08 15:06:14 -08:00
import Scylla.Login exposing (LoginResponse, Username, Password)
2018-12-13 02:15:14 -08:00
import Scylla.UserData exposing (UserData)
2018-12-08 19:09:20 -08:00
import Scylla.Route exposing (Route)
2018-12-08 13:49:30 -08:00
import Browser.Navigation as Nav
2018-12-08 17:15:35 -08:00
import Dict exposing (Dict)
2018-12-08 13:49:30 -08:00
import Browser
import Http
import Url exposing (Url)
type alias Model =
{ key : Nav.Key
2018-12-08 19:09:20 -08:00
, route : Route
2018-12-08 13:49:30 -08:00
, token : Maybe ApiToken
2018-12-08 15:06:14 -08:00
, loginUsername : Username
, loginPassword : Password
2018-12-08 13:49:30 -08:00
, apiUrl : ApiUrl
2018-12-08 17:15:35 -08:00
, sync : SyncResponse
, errors : List String
2018-12-09 23:38:43 -08:00
, roomText : Dict String String
, transactionId : Int
, userData : Dict Username UserData
2018-12-08 13:49:30 -08:00
}
type Msg =
2018-12-08 15:06:14 -08:00
ChangeApiUrl ApiUrl -- During login screen: the API URL (homeserver)
| ChangeLoginUsername Username -- During login screen: the username
| ChangeLoginPassword Password -- During login screen: the password
| AttemptLogin -- During login screen, login button presed
| TryUrl Browser.UrlRequest -- User attempts to change URL
2018-12-08 19:09:20 -08:00
| ChangeRoute Route -- URL changes
2018-12-09 23:38:43 -08:00
| ChangeRoomText String String -- Change to a room's input text
| SendRoomText String -- Sends a message typed into a given room's input
| SendRoomTextResponse (Result Http.Error ()) -- A send message response finished
| ReceiveFirstSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
2018-12-08 15:06:14 -08:00
| ReceiveSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
| ReceiveLoginResponse (Result Http.Error LoginResponse) -- HTTP, Login has finished
2018-12-13 02:15:14 -08:00
| ReceiveUserData Username (Result Http.Error UserData)
2018-12-08 13:49:30 -08:00
2018-12-13 13:42:23 -08:00
displayName : Model -> Username -> String
displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData