WIP - Implementing /_matrix/client/r0/pushers/set

This commit is contained in:
Dan Peleg 2021-04-25 17:42:36 +03:00
parent a1d1f2b02c
commit 633dbe0900
6 changed files with 146 additions and 5 deletions

View file

@ -78,3 +78,28 @@ func GetPushersByLocalpart(
JSON: res,
}
}
// SetPushersByLocalpart handles /_matrix/client/r0/pushers/set
// This endpoint allows the creation, modification and deletion of pushers for this user ID.
// The behaviour of this endpoint varies depending on the values in the JSON body.
func SetPusherByLocalpart(
req *http.Request, userAPI userapi.UserInternalAPI, device *api.Device,
) util.JSONResponse {
body := pusherJSON{}
if resErr := httputil.UnmarshalJSONRequest(req, &body); resErr != nil {
return *resErr
}
// TODO:
// 1. if kind == null, GetPusherByPushkey and delete it! 🗑
// 2. if GetPusherByPushkey returns existing Pusher, update it with the received body
// 3. if GetPusherByPushkey returns nothing, create a new Pusher with the received body
res := body
return util.JSONResponse{
Code: http.StatusOK,
JSON: res,
}
}

View file

@ -808,6 +808,16 @@ func Setup(
return GetPushersByLocalpart(req, userAPI, device)
}),
).Methods(http.MethodGet, http.MethodOptions)
r0mux.Handle("/pushers/set",
httputil.MakeAuthAPI("set_pushers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
if r := rateLimits.rateLimit(req); r != nil {
return *r
}
return SetPushersByLocalpart(req, userAPI, device)
}),
).Methods(http.MethodPost, http.MethodOptions)
// Stub implementations for sytest
r0mux.Handle("/events",
httputil.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse {