// Copyright 2020 The Matrix.org Foundation C.I.C. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package msc2836 'Threading' implements https://github.com/matrix-org/matrix-doc/pull/2836 package msc2836 import ( "encoding/json" "fmt" "net/http" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/setup" userapi "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/util" ) type eventRelationshipRequest struct { EventID string `json:"event_id"` MaxDepth int `json:"max_depth"` MaxBreadth int `json:"max_breadth"` Limit int `json:"limit"` DepthFirst bool `json:"depth_first"` RecentFirst bool `json:"recent_first"` IncludeParent bool `json:"include_parent"` IncludeChildren bool `json:"include_children"` Direction string `json:"direction"` Batch string `json:"batch"` } // Enable this MSC func Enable(base *setup.BaseDendrite, monolith *setup.Monolith) error { _, err := NewDatabase(&base.Cfg.MSCs.Database) if err != nil { return fmt.Errorf("Cannot enable MSC2836: %w", err) } base.PublicClientAPIMux.Handle("/unstable/event_relationships", httputil.MakeAuthAPI("eventRelationships", monolith.UserAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { var relation eventRelationshipRequest if err := json.NewDecoder(req.Body).Decode(&relation); err != nil { util.GetLogger(req.Context()).WithError(err).Error("failed to decode HTTP request as JSON") return util.JSONResponse{ Code: 400, JSON: jsonerror.BadJSON(fmt.Sprintf("invalid json: %s", err)), } } return util.JSONResponse{ Code: 200, JSON: struct{}{}, } }), ).Methods(http.MethodPost, http.MethodOptions) return nil }