package clientapi import ( "net/http" "github.com/dariuszjaniak/warp/server/internal/httputil" "github.com/dariuszjaniak/warp/server/internal/userapi" ) // syncResponse is the subset of the /sync body this build can fill in. type syncResponse struct { NextBatch string `json:"next_batch"` Rooms syncRooms `json:"rooms"` Presence syncEventList `json:"presence"` AccountData syncEventList `json:"account_data"` ToDevice syncEventList `json:"to_device"` DeviceLists syncDeviceLists `json:"device_lists"` } type syncRooms struct { Join map[string]any `json:"join"` Invite map[string]any `json:"invite"` Leave map[string]any `json:"leave"` Knock map[string]any `json:"knock"` } type syncEventList struct { Events []any `json:"events"` } type syncDeviceLists struct { Changed []string `json:"changed"` Left []string `json:"left"` } // syncPlaceholderToken is the only stream position this build has. // // It is a real token shape rather than an empty string so that a client // storing it and sending it back as ?since= gets the same answer. const syncPlaceholderToken = "s0_0" // handleSync implements GET /_matrix/client/v3/sync as far as this build // can. // // It is a placeholder, and since Phase 3 it is an incomplete answer rather // than a complete one: there are rooms now, and this reports none of them. // Filling it in means the event stream — stream tokens, incremental deltas, // long polling, filters and lazy-loaded members — which is the syncapi of // PLAN.md phase 4, and which replaces this wholesale. // // It stays because of what it does buy: a valid token syncs and a revoked // one does not, which is the first thing every client and the test suite // check, and which cannot be observed at all without an endpoint here. A // client can meanwhile see its rooms through /joined_rooms and read them // through /rooms/{roomID}/state. See docs/rooms.md. func (c *ClientAPI) handleSync(w http.ResponseWriter, _ *http.Request, _ userapi.Authenticated) error { // The `timeout` parameter is ignored rather than honoured: blocking for // 30 seconds to return a response this build cannot change would hold a // connection open for nothing. httputil.WriteJSON(w, http.StatusOK, syncResponse{ NextBatch: syncPlaceholderToken, Rooms: syncRooms{ Join: map[string]any{}, Invite: map[string]any{}, Leave: map[string]any{}, Knock: map[string]any{}, }, Presence: syncEventList{Events: []any{}}, AccountData: syncEventList{Events: []any{}}, ToDevice: syncEventList{Events: []any{}}, DeviceLists: syncDeviceLists{Changed: []string{}, Left: []string{}}, }) return nil }