mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Initial implementation of GET /_matrix/client/r0/pushers
This commit is contained in:
parent
dd8b05c310
commit
2c9ec8c1ab
3 changed files with 103 additions and 0 deletions
81
clientapi/routing/pusher.go
Normal file
81
clientapi/routing/pusher.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2021 Dan Peleg <dan@globekeeper.com>
|
||||
//
|
||||
// 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 routing
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-pushers
|
||||
type pusherJSON struct {
|
||||
PusherID string `json:"pusher_id"`
|
||||
PushKey string `json:"pushkey"`
|
||||
Kind string `json:"kind"`
|
||||
AppID string `json:"app_id"`
|
||||
AppDisplayName string `json:"app_display_name"`
|
||||
DeviceDisplayName string `json:"device_display_name"`
|
||||
ProfileTag string `json:"profile_tag"`
|
||||
Language string `json:"lang"`
|
||||
Data pusherDataJSON `json:"data"`
|
||||
}
|
||||
|
||||
type pushersJSON struct {
|
||||
Pushers []pusherJSON `json:"pushers"`
|
||||
}
|
||||
|
||||
type pusherDataJSON struct {
|
||||
URL string `json:"url"`
|
||||
Format string `json:"format"`
|
||||
}
|
||||
|
||||
// GetPushersByLocalpart handles /pushers
|
||||
func GetPushersByLocalpart(
|
||||
req *http.Request, userAPI userapi.UserInternalAPI, pusher *api.Pusher,
|
||||
) util.JSONResponse {
|
||||
var queryRes userapi.QueryPushersResponse
|
||||
err := userAPI.QueryPushers(req.Context(), &userapi.QueryPushersRequest{
|
||||
UserID: pusher.UserID,
|
||||
}, &queryRes)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("QueryPushers failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
res := pushersJSON{}
|
||||
|
||||
for _, pusher := range queryRes.Pushers {
|
||||
res.Pushers = append(res.Pushers, pusherJSON{
|
||||
PusherID: pusher.ID,
|
||||
PushKey: pusher.PushKey,
|
||||
Kind: pusher.Kind,
|
||||
AppID: pusher.AppID,
|
||||
AppDisplayName: pusher.AppDisplayName,
|
||||
DeviceDisplayName: pusher.DeviceDisplayName,
|
||||
ProfileTag: pusher.ProfileTag,
|
||||
Language: pusher.Language,
|
||||
Data: pusherDataJSON(pusher.Data),
|
||||
})
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: res,
|
||||
}
|
||||
}
|
|
@ -40,6 +40,7 @@ const (
|
|||
QueryProfilePath = "/userapi/queryProfile"
|
||||
QueryAccessTokenPath = "/userapi/queryAccessToken"
|
||||
QueryDevicesPath = "/userapi/queryDevices"
|
||||
QueryPushersPath = "/userapi/queryPushers"
|
||||
QueryAccountDataPath = "/userapi/queryAccountData"
|
||||
QueryDeviceInfosPath = "/userapi/queryDeviceInfos"
|
||||
QuerySearchProfilesPath = "/userapi/querySearchProfiles"
|
||||
|
@ -202,6 +203,14 @@ func (h *httpUserInternalAPI) QueryDevices(ctx context.Context, req *api.QueryDe
|
|||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
||||
}
|
||||
|
||||
func (h *httpUserInternalAPI) QueryPushers(ctx context.Context, req *api.QueryPushersRequest, res *api.QueryPushersResponse) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPushers")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.apiURL + QueryPushersPath
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
||||
}
|
||||
|
||||
func (h *httpUserInternalAPI) QueryAccountData(ctx context.Context, req *api.QueryAccountDataRequest, res *api.QueryAccountDataResponse) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAccountData")
|
||||
defer span.Finish()
|
||||
|
|
|
@ -169,6 +169,19 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
|||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
internalAPIMux.Handle(QueryPushersPath,
|
||||
httputil.MakeInternalAPI("queryPushers", func(req *http.Request) util.JSONResponse {
|
||||
request := api.QueryPushersRequest{}
|
||||
response := api.QueryPushersResponse{}
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
if err := s.QueryPushers(req.Context(), &request, &response); err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
internalAPIMux.Handle(QueryAccountDataPath,
|
||||
httputil.MakeInternalAPI("queryAccountData", func(req *http.Request) util.JSONResponse {
|
||||
request := api.QueryAccountDataRequest{}
|
||||
|
|
Loading…
Reference in a new issue