Add new lookup functions.
This commit is contained in:
parent
0e2cd8c9e9
commit
5627168d20
|
@ -110,8 +110,9 @@ updateSyncResponse model r notify =
|
||||||
<| List.map (userData model.apiUrl
|
<| List.map (userData model.apiUrl
|
||||||
<| Maybe.withDefault "" model.token)
|
<| Maybe.withDefault "" model.token)
|
||||||
<| newUsers sr
|
<| newUsers sr
|
||||||
notification sr = List.head
|
notification sr = findFirstBy
|
||||||
<| List.filter (\(s, e) -> e.sender /= model.loginUsername)
|
(\(s, e) -> e.originServerTs)
|
||||||
|
(\(s, e) -> e.sender /= model.loginUsername)
|
||||||
<| notificationEvents sr
|
<| notificationEvents sr
|
||||||
notificationCommand sr = Maybe.withDefault Cmd.none
|
notificationCommand sr = Maybe.withDefault Cmd.none
|
||||||
<| Maybe.map (\(s, e) -> sendNotificationPort
|
<| Maybe.map (\(s, e) -> sendNotificationPort
|
||||||
|
|
|
@ -269,6 +269,18 @@ uniqueByRecursive f l s = case l of
|
||||||
uniqueBy : (a -> comparable) -> List a -> List a
|
uniqueBy : (a -> comparable) -> List a -> List a
|
||||||
uniqueBy f l = uniqueByRecursive f l Set.empty
|
uniqueBy f l = uniqueByRecursive f l Set.empty
|
||||||
|
|
||||||
|
findFirstBy : (a -> comparable) -> (a -> Bool) -> List a -> Maybe a
|
||||||
|
findFirstBy sortFunction cond l = List.head <| List.sortBy sortFunction <| List.filter cond l
|
||||||
|
|
||||||
|
findLastBy : (a -> comparable) -> (a -> Bool) -> List a -> Maybe a
|
||||||
|
findLastBy sortFunction cond l = List.head <| List.reverse <| List.sortBy sortFunction <| List.filter cond l
|
||||||
|
|
||||||
|
findFirstEvent : ({ a | originServerTs : Int } -> Bool) -> List { a | originServerTs : Int } -> Maybe { a | originServerTs : Int }
|
||||||
|
findFirstEvent = findFirstBy .originServerTs
|
||||||
|
|
||||||
|
findLastEvent : ({ a | originServerTs : Int } -> Bool) -> List { a | originServerTs : Int } -> Maybe { a | originServerTs : Int }
|
||||||
|
findLastEvent = findLastBy .originServerTs
|
||||||
|
|
||||||
-- Business Logic: Merging
|
-- Business Logic: Merging
|
||||||
mergeMaybe : (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
|
mergeMaybe : (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
|
||||||
mergeMaybe f l r = case (l, r) of
|
mergeMaybe f l r = case (l, r) of
|
||||||
|
@ -368,7 +380,7 @@ roomName : JoinedRoom -> Maybe String
|
||||||
roomName jr =
|
roomName jr =
|
||||||
let
|
let
|
||||||
state = jr.state
|
state = jr.state
|
||||||
nameEvent = List.head << List.sortBy (\e -> -e.originServerTs) << List.filter (\e -> e.type_ == "m.room.name")
|
nameEvent = findLastEvent (((==) "m.room.name") << .type_)
|
||||||
name e = Result.toMaybe <| Decode.decodeValue (field "name" string) e.content
|
name e = Result.toMaybe <| Decode.decodeValue (field "name" string) e.content
|
||||||
in
|
in
|
||||||
Maybe.andThen name <| Maybe.andThen nameEvent <| Maybe.andThen .events <| state
|
Maybe.andThen name <| Maybe.andThen nameEvent <| Maybe.andThen .events <| state
|
||||||
|
|
Loading…
Reference in New Issue
Block a user