From cf05f9dc4a2909dd6aee1a6300a6e7d2c79b57cd Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 27 Dec 2018 22:33:48 -0800 Subject: [PATCH] Filter useless state events on the server side. This means that presence events appear in the timeline, which is something we DO want. --- src/Scylla/Http.elm | 17 +++++++++++++++-- src/Scylla/Sync.elm | 10 +--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Scylla/Http.elm b/src/Scylla/Http.elm index 74faa93..8f32c59 100644 --- a/src/Scylla/Http.elm +++ b/src/Scylla/Http.elm @@ -5,12 +5,25 @@ import Scylla.Route exposing (RoomId) import Scylla.Sync exposing (syncResponseDecoder, historyResponseDecoder) import Scylla.Login exposing (loginResponseDecoder, Username, Password) import Scylla.UserData exposing (userDataDecoder, UserData) -import Json.Encode exposing (object, string, int, bool) +import Url.Builder +import Json.Encode exposing (object, string, int, bool, list) import Http exposing (request, emptyBody, jsonBody, fileBody, expectJson, expectWhatever) import File exposing (File, name, mime) import Url.Builder as Builder import Json.Decode +firstSyncFilter : Json.Decode.Value +firstSyncFilter = object + [ ("room", object + [ ("state", object + [ ("types", list string [ "m.room.name" ]) + ]) + ]) + ] + +firstSyncFilterString : String +firstSyncFilterString = Json.Encode.encode 0 firstSyncFilter + fullClientUrl : ApiUrl -> ApiUrl fullClientUrl s = s ++ "/_matrix/client/r0" @@ -22,7 +35,7 @@ firstSync : ApiUrl -> ApiToken -> Cmd Msg firstSync apiUrl token = request { method = "GET" , headers = authenticatedHeaders token - , url = (fullClientUrl apiUrl) ++ "/sync" + , url = Url.Builder.crossOrigin (fullClientUrl apiUrl) [ "sync" ] [ Url.Builder.string "filter" firstSyncFilterString ] , body = emptyBody , expect = expectJson ReceiveFirstSyncResponse syncResponseDecoder , timeout = Nothing diff --git a/src/Scylla/Sync.elm b/src/Scylla/Sync.elm index 10b75b2..2b9dbad 100644 --- a/src/Scylla/Sync.elm +++ b/src/Scylla/Sync.elm @@ -392,19 +392,11 @@ mergeRooms r1 r2 = } mergeSyncResponse : SyncResponse -> SyncResponse -> SyncResponse -mergeSyncResponse l r = filterUselessState <| +mergeSyncResponse l r = { r | rooms = mergeMaybe mergeRooms l.rooms r.rooms , accountData = mergeMaybe mergeAccountData l.accountData r.accountData } -filterUselessState : SyncResponse -> SyncResponse -filterUselessState sr = - let - filterUselessRoomState _ r = { r | state = Maybe.map (\s -> { s | events = Maybe.map (List.filter (((==) "m.room.name") << .type_)) s.events }) r.state } - filterUselessRoomsState rs = { rs | join = Maybe.map (Dict.map filterUselessRoomState) rs.join } - in - { sr | rooms = Maybe.map (filterUselessRoomsState) sr.rooms } - appendRoomHistoryResponse : JoinedRoom -> HistoryResponse -> JoinedRoom appendRoomHistoryResponse jr hr = let