Add notifications

This commit is contained in:
2018-12-13 13:42:23 -08:00
parent b25e5d77af
commit 46352c429a
4 changed files with 35 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
module Scylla.Model exposing (..)
import Scylla.Api exposing (..)
import Scylla.Sync exposing (SyncResponse, JoinedRoom)
import Scylla.Sync exposing (SyncResponse, JoinedRoom, senderName)
import Scylla.Login exposing (LoginResponse, Username, Password)
import Scylla.UserData exposing (UserData)
import Scylla.Route exposing (Route)
@@ -39,3 +39,5 @@ type Msg =
| ReceiveLoginResponse (Result Http.Error LoginResponse) -- HTTP, Login has finished
| ReceiveUserData Username (Result Http.Error UserData)
displayName : Model -> Username -> String
displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData

View File

@@ -370,13 +370,17 @@ roomName jr =
Maybe.andThen name <| Maybe.andThen nameEvent <| Maybe.andThen .events <| state
-- Business Logic: Event Extraction
notificationEvent : SyncResponse -> Maybe (String, RoomEvent)
notificationEvent s =
notificationText : RoomEvent -> String
notificationText re = case (Decode.decodeValue (field "msgtype" string) re.content) of
Ok "m.text" -> Result.withDefault "" <| (Decode.decodeValue (field "body" string) re.content)
_ -> ""
notificationEvents : SyncResponse -> List (String, RoomEvent)
notificationEvents s =
let
applyPair k = List.map (\v -> (k, v))
in
List.head
<| List.sortBy (\(k, v) -> v.originServerTs)
List.sortBy (\(k, v) -> v.originServerTs)
<| Dict.foldl (\k v a -> a ++ applyPair k v) []
<| joinedRoomsEvents s

View File

@@ -3,6 +3,7 @@ import Scylla.Model exposing (..)
import Scylla.Sync exposing (..)
import Scylla.Route exposing (..)
import Scylla.Fnv as Fnv
import Scylla.Login exposing (Username)
import Svg
import Svg.Attributes
import Url.Builder
@@ -126,12 +127,9 @@ eventView m re =
Maybe.map createRow
<| Maybe.andThen (\f -> f m re) viewFunction
eventSenderView : Model -> String -> Html Msg
eventSenderView : Model -> Username -> Html Msg
eventSenderView m s =
let
displayName = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData
in
span [ style "background-color" <| stringColor s, class "sender-wrapper" ] [ text displayName ]
span [ style "background-color" <| stringColor s, class "sender-wrapper" ] [ text <| displayName m s ]
messageView : Model -> RoomEvent -> Maybe (Html Msg)
messageView m re =