Scylla/src/Scylla/UserData.elm

27 lines
781 B
Elm
Raw Normal View History

2018-12-13 02:15:14 -08:00
module Scylla.UserData exposing (..)
2019-09-11 00:52:42 -07:00
import Scylla.Login exposing (Username)
2018-12-13 02:15:14 -08:00
import Json.Decode as Decode exposing (Decoder, int, string, float, list, value, dict, bool, field)
import Json.Decode.Pipeline exposing (required, optional)
2019-09-11 00:52:42 -07:00
import Dict exposing (Dict)
2018-12-13 02:15:14 -08:00
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
2019-09-11 00:52:42 -07:00
getSenderName : Username -> String
getSenderName s =
let
colonIndex = Maybe.withDefault -1
<| List.head
<| String.indexes ":" s
in
String.slice 1 colonIndex s