Properly collect state events from a room.
This commit is contained in:
parent
130b964d29
commit
437039bcc4
|
@ -433,19 +433,38 @@ senderName s =
|
||||||
in
|
in
|
||||||
String.slice 1 colonIndex s
|
String.slice 1 colonIndex s
|
||||||
|
|
||||||
|
roomStateEvents : JoinedRoom -> List StateEvent
|
||||||
|
roomStateEvents jr =
|
||||||
|
let
|
||||||
|
stateEvents = Maybe.withDefault [] <| Maybe.andThen .events jr.state
|
||||||
|
timelineEvents = Maybe.withDefault [] <| Maybe.andThen .events jr.timeline
|
||||||
|
roomToStateEvent re =
|
||||||
|
{ content = re.content
|
||||||
|
, type_ = re.type_
|
||||||
|
, eventId = re.eventId
|
||||||
|
, sender = re.sender
|
||||||
|
, originServerTs = re.originServerTs
|
||||||
|
, unsigned = re.unsigned
|
||||||
|
, prevContent = Nothing
|
||||||
|
, stateKey = ""
|
||||||
|
}
|
||||||
|
allEvents = uniqueBy .eventId (stateEvents ++ (List.map roomToStateEvent timelineEvents))
|
||||||
|
in
|
||||||
|
allEvents
|
||||||
|
|
||||||
|
roomAccountData : JoinedRoom -> String -> Maybe Decode.Value
|
||||||
|
roomAccountData jr et =
|
||||||
|
Maybe.map .content
|
||||||
|
<| Maybe.andThen (List.head << List.filter (((==) et) << .type_))
|
||||||
|
<| Maybe.andThen .events jr.accountData
|
||||||
|
|
||||||
roomName : JoinedRoom -> Maybe String
|
roomName : JoinedRoom -> Maybe String
|
||||||
roomName jr =
|
roomName jr =
|
||||||
let
|
let
|
||||||
nameEvent = Maybe.andThen (findLastEvent (((==) "m.room.name") << .type_))
|
|
||||||
<< Maybe.andThen .events
|
|
||||||
name c = Result.toMaybe <| Decode.decodeValue (field "name" string) c
|
name c = Result.toMaybe <| Decode.decodeValue (field "name" string) c
|
||||||
maybeStateEvent = nameEvent jr.state
|
nameEvent = findLastEvent (((==) "m.room.name") << .type_) <| roomStateEvents jr
|
||||||
maybeTimelineEvent = nameEvent jr.timeline
|
|
||||||
realEventContent = case maybeTimelineEvent of
|
|
||||||
Just te -> Just te.content
|
|
||||||
_ -> Maybe.map .content maybeStateEvent
|
|
||||||
in
|
in
|
||||||
Maybe.andThen name realEventContent
|
Maybe.andThen (name << .content) nameEvent
|
||||||
|
|
||||||
-- Business Logic: Event Extraction
|
-- Business Logic: Event Extraction
|
||||||
notificationText : RoomEvent -> String
|
notificationText : RoomEvent -> String
|
||||||
|
|
Loading…
Reference in New Issue
Block a user