Some serverside stuff
This commit is contained in:
parent
9ebeaaf93f
commit
22da1f3157
|
@ -32,11 +32,12 @@ type fedRoomserverAPI struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformJoin will call this function
|
// PerformJoin will call this function
|
||||||
func (f *fedRoomserverAPI) InputRoomEvents(ctx context.Context, req *rsapi.InputRoomEventsRequest, res *rsapi.InputRoomEventsResponse) {
|
func (f *fedRoomserverAPI) InputRoomEvents(ctx context.Context, req *rsapi.InputRoomEventsRequest, res *rsapi.InputRoomEventsResponse) error {
|
||||||
if f.inputRoomEvents == nil {
|
if f.inputRoomEvents == nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
f.inputRoomEvents(ctx, req, res)
|
f.inputRoomEvents(ctx, req, res)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// keychange consumer calls this
|
// keychange consumer calls this
|
||||||
|
|
|
@ -64,11 +64,12 @@ func (t *testRoomserverAPI) InputRoomEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
response *api.InputRoomEventsResponse,
|
response *api.InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
t.inputRoomEvents = append(t.inputRoomEvents, request.InputRoomEvents...)
|
t.inputRoomEvents = append(t.inputRoomEvents, request.InputRoomEvents...)
|
||||||
for _, ire := range request.InputRoomEvents {
|
for _, ire := range request.InputRoomEvents {
|
||||||
fmt.Println("InputRoomEvents: ", ire.Event.EventID())
|
fmt.Println("InputRoomEvents: ", ire.Event.EventID())
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the latest events and state for a room from the room server.
|
// Query the latest events and state for a room from the room server.
|
||||||
|
|
|
@ -40,7 +40,7 @@ type InputRoomEventsAPI interface {
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *InputRoomEventsRequest,
|
req *InputRoomEventsRequest,
|
||||||
res *InputRoomEventsResponse,
|
res *InputRoomEventsResponse,
|
||||||
)
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the latest events and state for a room from the room server.
|
// Query the latest events and state for a room from the room server.
|
||||||
|
@ -139,15 +139,15 @@ type ClientRoomserverAPI interface {
|
||||||
GetAliasesForRoomID(ctx context.Context, req *GetAliasesForRoomIDRequest, res *GetAliasesForRoomIDResponse) error
|
GetAliasesForRoomID(ctx context.Context, req *GetAliasesForRoomIDRequest, res *GetAliasesForRoomIDResponse) error
|
||||||
|
|
||||||
// PerformRoomUpgrade upgrades a room to a newer version
|
// PerformRoomUpgrade upgrades a room to a newer version
|
||||||
PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse)
|
PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse) error
|
||||||
PerformAdminEvacuateRoom(ctx context.Context, req *PerformAdminEvacuateRoomRequest, res *PerformAdminEvacuateRoomResponse)
|
PerformAdminEvacuateRoom(ctx context.Context, req *PerformAdminEvacuateRoomRequest, res *PerformAdminEvacuateRoomResponse) error
|
||||||
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse)
|
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse) error
|
||||||
PerformPeek(ctx context.Context, req *PerformPeekRequest, res *PerformPeekResponse)
|
PerformPeek(ctx context.Context, req *PerformPeekRequest, res *PerformPeekResponse) error
|
||||||
PerformUnpeek(ctx context.Context, req *PerformUnpeekRequest, res *PerformUnpeekResponse)
|
PerformUnpeek(ctx context.Context, req *PerformUnpeekRequest, res *PerformUnpeekResponse) error
|
||||||
PerformInvite(ctx context.Context, req *PerformInviteRequest, res *PerformInviteResponse) error
|
PerformInvite(ctx context.Context, req *PerformInviteRequest, res *PerformInviteResponse) error
|
||||||
PerformJoin(ctx context.Context, req *PerformJoinRequest, res *PerformJoinResponse)
|
PerformJoin(ctx context.Context, req *PerformJoinRequest, res *PerformJoinResponse) error
|
||||||
PerformLeave(ctx context.Context, req *PerformLeaveRequest, res *PerformLeaveResponse) error
|
PerformLeave(ctx context.Context, req *PerformLeaveRequest, res *PerformLeaveResponse) error
|
||||||
PerformPublish(ctx context.Context, req *PerformPublishRequest, res *PerformPublishResponse)
|
PerformPublish(ctx context.Context, req *PerformPublishRequest, res *PerformPublishResponse) error
|
||||||
// PerformForget forgets a rooms history for a specific user
|
// PerformForget forgets a rooms history for a specific user
|
||||||
PerformForget(ctx context.Context, req *PerformForgetRequest, resp *PerformForgetResponse) error
|
PerformForget(ctx context.Context, req *PerformForgetRequest, resp *PerformForgetResponse) error
|
||||||
SetRoomAlias(ctx context.Context, req *SetRoomAliasRequest, res *SetRoomAliasResponse) error
|
SetRoomAlias(ctx context.Context, req *SetRoomAliasRequest, res *SetRoomAliasResponse) error
|
||||||
|
@ -158,7 +158,7 @@ type UserRoomserverAPI interface {
|
||||||
QueryLatestEventsAndStateAPI
|
QueryLatestEventsAndStateAPI
|
||||||
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
||||||
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
||||||
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse)
|
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type FederationRoomserverAPI interface {
|
type FederationRoomserverAPI interface {
|
||||||
|
|
|
@ -35,9 +35,10 @@ func (t *RoomserverInternalAPITrace) InputRoomEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *InputRoomEventsRequest,
|
req *InputRoomEventsRequest,
|
||||||
res *InputRoomEventsResponse,
|
res *InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.InputRoomEvents(ctx, req, res)
|
err := t.Impl.InputRoomEvents(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("InputRoomEvents req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformInvite(
|
func (t *RoomserverInternalAPITrace) PerformInvite(
|
||||||
|
@ -45,44 +46,49 @@ func (t *RoomserverInternalAPITrace) PerformInvite(
|
||||||
req *PerformInviteRequest,
|
req *PerformInviteRequest,
|
||||||
res *PerformInviteResponse,
|
res *PerformInviteResponse,
|
||||||
) error {
|
) error {
|
||||||
util.GetLogger(ctx).Infof("PerformInvite req=%+v res=%+v", js(req), js(res))
|
err := t.Impl.PerformInvite(ctx, req, res)
|
||||||
return t.Impl.PerformInvite(ctx, req, res)
|
util.GetLogger(ctx).WithError(err).Infof("PerformInvite req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformPeek(
|
func (t *RoomserverInternalAPITrace) PerformPeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformPeekRequest,
|
req *PerformPeekRequest,
|
||||||
res *PerformPeekResponse,
|
res *PerformPeekResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformPeek(ctx, req, res)
|
err := t.Impl.PerformPeek(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformPeek req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformPeek req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformUnpeek(
|
func (t *RoomserverInternalAPITrace) PerformUnpeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformUnpeekRequest,
|
req *PerformUnpeekRequest,
|
||||||
res *PerformUnpeekResponse,
|
res *PerformUnpeekResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformUnpeek(ctx, req, res)
|
err := t.Impl.PerformUnpeek(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformUnpeek req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformUnpeek req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformRoomUpgrade(
|
func (t *RoomserverInternalAPITrace) PerformRoomUpgrade(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformRoomUpgradeRequest,
|
req *PerformRoomUpgradeRequest,
|
||||||
res *PerformRoomUpgradeResponse,
|
res *PerformRoomUpgradeResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformRoomUpgrade(ctx, req, res)
|
err := t.Impl.PerformRoomUpgrade(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformRoomUpgrade req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformRoomUpgrade req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformJoin(
|
func (t *RoomserverInternalAPITrace) PerformJoin(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformJoinRequest,
|
req *PerformJoinRequest,
|
||||||
res *PerformJoinResponse,
|
res *PerformJoinResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformJoin(ctx, req, res)
|
err := t.Impl.PerformJoin(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformJoin req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformJoin req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformLeave(
|
func (t *RoomserverInternalAPITrace) PerformLeave(
|
||||||
|
@ -99,27 +105,30 @@ func (t *RoomserverInternalAPITrace) PerformPublish(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformPublishRequest,
|
req *PerformPublishRequest,
|
||||||
res *PerformPublishResponse,
|
res *PerformPublishResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformPublish(ctx, req, res)
|
err := t.Impl.PerformPublish(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformPublish req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformPublish req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateRoom(
|
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformAdminEvacuateRoomRequest,
|
req *PerformAdminEvacuateRoomRequest,
|
||||||
res *PerformAdminEvacuateRoomResponse,
|
res *PerformAdminEvacuateRoomResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformAdminEvacuateRoom(ctx, req, res)
|
err := t.Impl.PerformAdminEvacuateRoom(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformAdminEvacuateRoom req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformAdminEvacuateRoom req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateUser(
|
func (t *RoomserverInternalAPITrace) PerformAdminEvacuateUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformAdminEvacuateUserRequest,
|
req *PerformAdminEvacuateUserRequest,
|
||||||
res *PerformAdminEvacuateUserResponse,
|
res *PerformAdminEvacuateUserResponse,
|
||||||
) {
|
) error {
|
||||||
t.Impl.PerformAdminEvacuateUser(ctx, req, res)
|
err := t.Impl.PerformAdminEvacuateUser(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformAdminEvacuateUser req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformAdminEvacuateUser req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RoomserverInternalAPITrace) PerformInboundPeek(
|
func (t *RoomserverInternalAPITrace) PerformInboundPeek(
|
||||||
|
@ -128,7 +137,7 @@ func (t *RoomserverInternalAPITrace) PerformInboundPeek(
|
||||||
res *PerformInboundPeekResponse,
|
res *PerformInboundPeekResponse,
|
||||||
) error {
|
) error {
|
||||||
err := t.Impl.PerformInboundPeek(ctx, req, res)
|
err := t.Impl.PerformInboundPeek(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("PerformInboundPeek req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).WithError(err).Infof("PerformInboundPeek req=%+v res=%+v", js(req), js(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -337,18 +337,18 @@ func (r *Inputer) InputRoomEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
response *api.InputRoomEventsResponse,
|
response *api.InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
// Queue up the event into the roomserver.
|
// Queue up the event into the roomserver.
|
||||||
replySub, err := r.queueInputRoomEvents(ctx, request)
|
replySub, err := r.queueInputRoomEvents(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrMsg = err.Error()
|
response.ErrMsg = err.Error()
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we aren't waiting for synchronous responses then we can
|
// If we aren't waiting for synchronous responses then we can
|
||||||
// give up here, there is nothing further to do.
|
// give up here, there is nothing further to do.
|
||||||
if replySub == nil {
|
if replySub == nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we'll want to sit and wait for the responses
|
// Otherwise, we'll want to sit and wait for the responses
|
||||||
|
@ -360,12 +360,14 @@ func (r *Inputer) InputRoomEvents(
|
||||||
msg, err := replySub.NextMsgWithContext(ctx)
|
msg, err := replySub.NextMsgWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrMsg = err.Error()
|
response.ErrMsg = err.Error()
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if len(msg.Data) > 0 {
|
if len(msg.Data) > 0 {
|
||||||
response.ErrMsg = string(msg.Data)
|
response.ErrMsg = string(msg.Data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var roomserverInputBackpressure = prometheus.NewGaugeVec(
|
var roomserverInputBackpressure = prometheus.NewGaugeVec(
|
||||||
|
|
|
@ -43,21 +43,21 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformAdminEvacuateRoomRequest,
|
req *api.PerformAdminEvacuateRoomRequest,
|
||||||
res *api.PerformAdminEvacuateRoomResponse,
|
res *api.PerformAdminEvacuateRoomResponse,
|
||||||
) {
|
) error {
|
||||||
roomInfo, err := r.DB.RoomInfo(ctx, req.RoomID)
|
roomInfo, err := r.DB.RoomInfo(ctx, req.RoomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.RoomInfo: %s", err),
|
Msg: fmt.Sprintf("r.DB.RoomInfo: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if roomInfo == nil || roomInfo.IsStub() {
|
if roomInfo == nil || roomInfo.IsStub() {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorNoRoom,
|
Code: api.PerformErrorNoRoom,
|
||||||
Msg: fmt.Sprintf("Room %s not found", req.RoomID),
|
Msg: fmt.Sprintf("Room %s not found", req.RoomID),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
memberNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
|
memberNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
|
||||||
|
@ -66,7 +66,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.GetMembershipEventNIDsForRoom: %s", err),
|
Msg: fmt.Sprintf("r.DB.GetMembershipEventNIDsForRoom: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
memberEvents, err := r.DB.Events(ctx, memberNIDs)
|
memberEvents, err := r.DB.Events(ctx, memberNIDs)
|
||||||
|
@ -75,7 +75,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.Events: %s", err),
|
Msg: fmt.Sprintf("r.DB.Events: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
|
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
|
||||||
|
@ -89,7 +89,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.Queryer.QueryLatestEventsAndState: %s", err),
|
Msg: fmt.Sprintf("r.Queryer.QueryLatestEventsAndState: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
prevEvents := latestRes.LatestEvents
|
prevEvents := latestRes.LatestEvents
|
||||||
|
@ -104,7 +104,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("json.Unmarshal: %s", err),
|
Msg: fmt.Sprintf("json.Unmarshal: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
memberContent.Membership = gomatrixserverlib.Leave
|
memberContent.Membership = gomatrixserverlib.Leave
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("json.Marshal: %s", err),
|
Msg: fmt.Sprintf("json.Marshal: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(fledglingEvent)
|
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(fledglingEvent)
|
||||||
|
@ -131,7 +131,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("gomatrixserverlib.StateNeededForEventBuilder: %s", err),
|
Msg: fmt.Sprintf("gomatrixserverlib.StateNeededForEventBuilder: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
event, err := eventutil.BuildEvent(ctx, fledglingEvent, r.Cfg.Matrix, time.Now(), &eventsNeeded, latestRes)
|
event, err := eventutil.BuildEvent(ctx, fledglingEvent, r.Cfg.Matrix, time.Now(), &eventsNeeded, latestRes)
|
||||||
|
@ -140,7 +140,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("eventutil.BuildEvent: %s", err),
|
Msg: fmt.Sprintf("eventutil.BuildEvent: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
inputEvents = append(inputEvents, api.InputRoomEvent{
|
inputEvents = append(inputEvents, api.InputRoomEvent{
|
||||||
|
@ -160,28 +160,28 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
||||||
Asynchronous: true,
|
Asynchronous: true,
|
||||||
}
|
}
|
||||||
inputRes := &api.InputRoomEventsResponse{}
|
inputRes := &api.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(ctx, inputReq, inputRes)
|
return r.Inputer.InputRoomEvents(ctx, inputReq, inputRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Admin) PerformAdminEvacuateUser(
|
func (r *Admin) PerformAdminEvacuateUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformAdminEvacuateUserRequest,
|
req *api.PerformAdminEvacuateUserRequest,
|
||||||
res *api.PerformAdminEvacuateUserResponse,
|
res *api.PerformAdminEvacuateUserResponse,
|
||||||
) {
|
) error {
|
||||||
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
|
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("Malformed user ID: %s", err),
|
Msg: fmt.Sprintf("Malformed user ID: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if domain != r.Cfg.Matrix.ServerName {
|
if domain != r.Cfg.Matrix.ServerName {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: "Can only evacuate local users using this endpoint",
|
Msg: "Can only evacuate local users using this endpoint",
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
roomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Join)
|
roomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Join)
|
||||||
|
@ -190,7 +190,7 @@ func (r *Admin) PerformAdminEvacuateUser(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
inviteRoomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Invite)
|
inviteRoomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Invite)
|
||||||
|
@ -199,7 +199,7 @@ func (r *Admin) PerformAdminEvacuateUser(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
Msg: fmt.Sprintf("r.DB.GetRoomsByMembership: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, roomID := range append(roomIDs, inviteRoomIDs...) {
|
for _, roomID := range append(roomIDs, inviteRoomIDs...) {
|
||||||
|
@ -214,7 +214,7 @@ func (r *Admin) PerformAdminEvacuateUser(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.Leaver.PerformLeave: %s", err),
|
Msg: fmt.Sprintf("r.Leaver.PerformLeave: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if len(outputEvents) == 0 {
|
if len(outputEvents) == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -224,9 +224,10 @@ func (r *Admin) PerformAdminEvacuateUser(
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
Msg: fmt.Sprintf("r.Inputer.WriteOutputEvents: %s", err),
|
Msg: fmt.Sprintf("r.Inputer.WriteOutputEvents: %s", err),
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Affected = append(res.Affected, roomID)
|
res.Affected = append(res.Affected, roomID)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (r *Joiner) PerformJoin(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *rsAPI.PerformJoinRequest,
|
req *rsAPI.PerformJoinRequest,
|
||||||
res *rsAPI.PerformJoinResponse,
|
res *rsAPI.PerformJoinResponse,
|
||||||
) {
|
) error {
|
||||||
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
|
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
|
||||||
"room_id": req.RoomIDOrAlias,
|
"room_id": req.RoomIDOrAlias,
|
||||||
"user_id": req.UserID,
|
"user_id": req.UserID,
|
||||||
|
@ -71,11 +71,12 @@ func (r *Joiner) PerformJoin(
|
||||||
Msg: err.Error(),
|
Msg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
logger.Info("User joined room successfully")
|
logger.Info("User joined room successfully")
|
||||||
res.RoomID = roomID
|
res.RoomID = roomID
|
||||||
res.JoinedVia = joinedVia
|
res.JoinedVia = joinedVia
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Joiner) performJoin(
|
func (r *Joiner) performJoin(
|
||||||
|
|
|
@ -44,7 +44,7 @@ func (r *Peeker) PerformPeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformPeekRequest,
|
req *api.PerformPeekRequest,
|
||||||
res *api.PerformPeekResponse,
|
res *api.PerformPeekResponse,
|
||||||
) {
|
) error {
|
||||||
roomID, err := r.performPeek(ctx, req)
|
roomID, err := r.performPeek(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
perr, ok := err.(*api.PerformError)
|
perr, ok := err.(*api.PerformError)
|
||||||
|
@ -57,6 +57,7 @@ func (r *Peeker) PerformPeek(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.RoomID = roomID
|
res.RoomID = roomID
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Peeker) performPeek(
|
func (r *Peeker) performPeek(
|
||||||
|
|
|
@ -29,11 +29,12 @@ func (r *Publisher) PerformPublish(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformPublishRequest,
|
req *api.PerformPublishRequest,
|
||||||
res *api.PerformPublishResponse,
|
res *api.PerformPublishResponse,
|
||||||
) {
|
) error {
|
||||||
err := r.DB.PublishRoom(ctx, req.RoomID, req.Visibility == "public")
|
err := r.DB.PublishRoom(ctx, req.RoomID, req.Visibility == "public")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Msg: err.Error(),
|
Msg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (r *Unpeeker) PerformUnpeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformUnpeekRequest,
|
req *api.PerformUnpeekRequest,
|
||||||
res *api.PerformUnpeekResponse,
|
res *api.PerformUnpeekResponse,
|
||||||
) {
|
) error {
|
||||||
if err := r.performUnpeek(ctx, req); err != nil {
|
if err := r.performUnpeek(ctx, req); err != nil {
|
||||||
perr, ok := err.(*api.PerformError)
|
perr, ok := err.(*api.PerformError)
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -52,6 +52,7 @@ func (r *Unpeeker) PerformUnpeek(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Unpeeker) performUnpeek(
|
func (r *Unpeeker) performUnpeek(
|
||||||
|
|
|
@ -45,12 +45,13 @@ func (r *Upgrader) PerformRoomUpgrade(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformRoomUpgradeRequest,
|
req *api.PerformRoomUpgradeRequest,
|
||||||
res *api.PerformRoomUpgradeResponse,
|
res *api.PerformRoomUpgradeResponse,
|
||||||
) {
|
) error {
|
||||||
res.NewRoomID, res.Error = r.performRoomUpgrade(ctx, req)
|
res.NewRoomID, res.Error = r.performRoomUpgrade(ctx, req)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
res.NewRoomID = ""
|
res.NewRoomID = ""
|
||||||
logrus.WithContext(ctx).WithError(res.Error).Error("Room upgrade failed")
|
logrus.WithContext(ctx).WithError(res.Error).Error("Room upgrade failed")
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Upgrader) performRoomUpgrade(
|
func (r *Upgrader) performRoomUpgrade(
|
||||||
|
|
|
@ -151,11 +151,12 @@ func (h *httpRoomserverInternalAPI) InputRoomEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
response *api.InputRoomEventsResponse,
|
response *api.InputRoomEventsResponse,
|
||||||
) {
|
) error {
|
||||||
response.ErrMsg = httputil.CallInternalRPCAPI(
|
response.ErrMsg = httputil.CallInternalRPCAPI(
|
||||||
"InputRoomEvents", h.roomserverURL+RoomserverInputRoomEventsPath,
|
"InputRoomEvents", h.roomserverURL+RoomserverInputRoomEventsPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
).Error()
|
).Error()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformInvite(
|
func (h *httpRoomserverInternalAPI) PerformInvite(
|
||||||
|
@ -173,8 +174,8 @@ func (h *httpRoomserverInternalAPI) PerformJoin(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformJoinRequest,
|
request *api.PerformJoinRequest,
|
||||||
response *api.PerformJoinResponse,
|
response *api.PerformJoinResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"PerformJoin", h.roomserverURL+RoomserverPerformJoinPath,
|
"PerformJoin", h.roomserverURL+RoomserverPerformJoinPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
@ -184,8 +185,8 @@ func (h *httpRoomserverInternalAPI) PerformPeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformPeekRequest,
|
request *api.PerformPeekRequest,
|
||||||
response *api.PerformPeekResponse,
|
response *api.PerformPeekResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"PerformPeek", h.roomserverURL+RoomserverPerformPeekPath,
|
"PerformPeek", h.roomserverURL+RoomserverPerformPeekPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
@ -206,8 +207,8 @@ func (h *httpRoomserverInternalAPI) PerformUnpeek(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformUnpeekRequest,
|
request *api.PerformUnpeekRequest,
|
||||||
response *api.PerformUnpeekResponse,
|
response *api.PerformUnpeekResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"PerformUnpeek", h.roomserverURL+RoomserverPerformUnpeekPath,
|
"PerformUnpeek", h.roomserverURL+RoomserverPerformUnpeekPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
@ -217,8 +218,8 @@ func (h *httpRoomserverInternalAPI) PerformRoomUpgrade(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformRoomUpgradeRequest,
|
request *api.PerformRoomUpgradeRequest,
|
||||||
response *api.PerformRoomUpgradeResponse,
|
response *api.PerformRoomUpgradeResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"PerformRoomUpgrade", h.roomserverURL+RoomserverPerformRoomUpgradePath,
|
"PerformRoomUpgrade", h.roomserverURL+RoomserverPerformRoomUpgradePath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
@ -239,8 +240,8 @@ func (h *httpRoomserverInternalAPI) PerformPublish(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformPublishRequest,
|
request *api.PerformPublishRequest,
|
||||||
response *api.PerformPublishResponse,
|
response *api.PerformPublishResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"PerformPublish", h.roomserverURL+RoomserverPerformPublishPath,
|
"PerformPublish", h.roomserverURL+RoomserverPerformPublishPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
@ -250,8 +251,8 @@ func (h *httpRoomserverInternalAPI) PerformAdminEvacuateRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformAdminEvacuateRoomRequest,
|
request *api.PerformAdminEvacuateRoomRequest,
|
||||||
response *api.PerformAdminEvacuateRoomResponse,
|
response *api.PerformAdminEvacuateRoomResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"PerformAdminEvacuateRoom", h.roomserverURL+RoomserverPerformAdminEvacuateRoomPath,
|
"PerformAdminEvacuateRoom", h.roomserverURL+RoomserverPerformAdminEvacuateRoomPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
@ -261,8 +262,8 @@ func (h *httpRoomserverInternalAPI) PerformAdminEvacuateUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.PerformAdminEvacuateUserRequest,
|
request *api.PerformAdminEvacuateUserRequest,
|
||||||
response *api.PerformAdminEvacuateUserResponse,
|
response *api.PerformAdminEvacuateUserResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"PerformAdminEvacuateUser", h.roomserverURL+RoomserverPerformAdminEvacuateUserPath,
|
"PerformAdminEvacuateUser", h.roomserverURL+RoomserverPerformAdminEvacuateUserPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,499 +1,201 @@
|
||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
|
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
||||||
internalAPIMux.Handle(RoomserverInputRoomEventsPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
|
RoomserverInputRoomEventsPath,
|
||||||
var request api.InputRoomEventsRequest
|
httputil.MakeInternalRPCAPI("InputRoomEvents", r.InputRoomEvents),
|
||||||
var response api.InputRoomEventsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.InputRoomEvents(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformInvitePath,
|
|
||||||
httputil.MakeInternalAPI("performInvite", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformInviteRequest
|
RoomserverPerformInvitePath,
|
||||||
var response api.PerformInviteResponse
|
httputil.MakeInternalRPCAPI("PerformInvite", r.PerformInvite),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.PerformInvite(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformJoinPath,
|
|
||||||
httputil.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformJoinRequest
|
RoomserverPerformJoinPath,
|
||||||
var response api.PerformJoinResponse
|
httputil.MakeInternalRPCAPI("PerformJoin", r.PerformJoin),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformJoin(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformLeavePath,
|
|
||||||
httputil.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformLeaveRequest
|
RoomserverPerformLeavePath,
|
||||||
var response api.PerformLeaveResponse
|
httputil.MakeInternalRPCAPI("PerformLeave", r.PerformLeave),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.PerformLeave(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformPeekPath,
|
|
||||||
httputil.MakeInternalAPI("performPeek", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformPeekRequest
|
RoomserverPerformPeekPath,
|
||||||
var response api.PerformPeekResponse
|
httputil.MakeInternalRPCAPI("PerformPeek", r.PerformPeek),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformPeek(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformInboundPeekPath,
|
|
||||||
httputil.MakeInternalAPI("performInboundPeek", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformInboundPeekRequest
|
RoomserverPerformInboundPeekPath,
|
||||||
var response api.PerformInboundPeekResponse
|
httputil.MakeInternalRPCAPI("PerformInboundPeek", r.PerformInboundPeek),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.PerformInboundPeek(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformPeekPath,
|
|
||||||
httputil.MakeInternalAPI("performUnpeek", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformUnpeekRequest
|
RoomserverPerformUnpeekPath,
|
||||||
var response api.PerformUnpeekResponse
|
httputil.MakeInternalRPCAPI("PerformUnpeek", r.PerformUnpeek),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformUnpeek(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformRoomUpgradePath,
|
|
||||||
httputil.MakeInternalAPI("performRoomUpgrade", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformRoomUpgradeRequest
|
RoomserverPerformRoomUpgradePath,
|
||||||
var response api.PerformRoomUpgradeResponse
|
httputil.MakeInternalRPCAPI("PerformRoomUpgrade", r.PerformRoomUpgrade),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformRoomUpgrade(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformPublishPath,
|
|
||||||
httputil.MakeInternalAPI("performPublish", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformPublishRequest
|
RoomserverPerformPublishPath,
|
||||||
var response api.PerformPublishResponse
|
httputil.MakeInternalRPCAPI("PerformPublish", r.PerformPublish),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformPublish(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformAdminEvacuateRoomPath,
|
|
||||||
httputil.MakeInternalAPI("performAdminEvacuateRoom", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformAdminEvacuateRoomRequest
|
RoomserverPerformAdminEvacuateRoomPath,
|
||||||
var response api.PerformAdminEvacuateRoomResponse
|
httputil.MakeInternalRPCAPI("PerformAdminEvacuateRoom", r.PerformAdminEvacuateRoom),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformAdminEvacuateRoom(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverPerformAdminEvacuateUserPath,
|
|
||||||
httputil.MakeInternalAPI("performAdminEvacuateUser", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
var request api.PerformAdminEvacuateUserRequest
|
RoomserverPerformAdminEvacuateUserPath,
|
||||||
var response api.PerformAdminEvacuateUserResponse
|
httputil.MakeInternalRPCAPI("PerformAdminEvacuateUser", r.PerformAdminEvacuateUser),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
r.PerformAdminEvacuateUser(req.Context(), &request, &response)
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryPublishedRoomsPath,
|
RoomserverQueryPublishedRoomsPath,
|
||||||
httputil.MakeInternalAPI("queryPublishedRooms", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryPublishedRooms", r.QueryPublishedRooms),
|
||||||
var request api.QueryPublishedRoomsRequest
|
|
||||||
var response api.QueryPublishedRoomsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryPublishedRooms(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryLatestEventsAndStatePath,
|
RoomserverQueryLatestEventsAndStatePath,
|
||||||
httputil.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryLatestEventsAndState", r.QueryLatestEventsAndState),
|
||||||
var request api.QueryLatestEventsAndStateRequest
|
|
||||||
var response api.QueryLatestEventsAndStateResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryLatestEventsAndState(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryStateAfterEventsPath,
|
RoomserverQueryStateAfterEventsPath,
|
||||||
httputil.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryStateAfterEvents", r.QueryStateAfterEvents),
|
||||||
var request api.QueryStateAfterEventsRequest
|
|
||||||
var response api.QueryStateAfterEventsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryStateAfterEvents(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryEventsByIDPath,
|
RoomserverQueryEventsByIDPath,
|
||||||
httputil.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryEventsByID", r.QueryEventsByID),
|
||||||
var request api.QueryEventsByIDRequest
|
|
||||||
var response api.QueryEventsByIDResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryEventsByID(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryMembershipForUserPath,
|
RoomserverQueryMembershipForUserPath,
|
||||||
httputil.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryMembershipForUser", r.QueryMembershipForUser),
|
||||||
var request api.QueryMembershipForUserRequest
|
|
||||||
var response api.QueryMembershipForUserResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryMembershipForUser(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryMembershipsForRoomPath,
|
RoomserverQueryMembershipsForRoomPath,
|
||||||
httputil.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryMembershipsForRoom", r.QueryMembershipsForRoom),
|
||||||
var request api.QueryMembershipsForRoomRequest
|
|
||||||
var response api.QueryMembershipsForRoomResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryMembershipsForRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryServerJoinedToRoomPath,
|
RoomserverQueryServerJoinedToRoomPath,
|
||||||
httputil.MakeInternalAPI("queryServerJoinedToRoom", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryServerJoinedToRoom", r.QueryServerJoinedToRoom),
|
||||||
var request api.QueryServerJoinedToRoomRequest
|
|
||||||
var response api.QueryServerJoinedToRoomResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryServerJoinedToRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
RoomserverQueryServerJoinedToRoomPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryServerJoinedToRoom", r.QueryServerJoinedToRoom),
|
||||||
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryServerAllowedToSeeEventPath,
|
RoomserverQueryServerAllowedToSeeEventPath,
|
||||||
httputil.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryServerAllowedToSeeEvent", r.QueryServerAllowedToSeeEvent),
|
||||||
var request api.QueryServerAllowedToSeeEventRequest
|
|
||||||
var response api.QueryServerAllowedToSeeEventResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryServerAllowedToSeeEvent(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryMissingEventsPath,
|
RoomserverQueryMissingEventsPath,
|
||||||
httputil.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryMissingEvents", r.QueryMissingEvents),
|
||||||
var request api.QueryMissingEventsRequest
|
|
||||||
var response api.QueryMissingEventsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryMissingEvents(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryStateAndAuthChainPath,
|
RoomserverQueryStateAndAuthChainPath,
|
||||||
httputil.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryStateAndAuthChain", r.QueryStateAndAuthChain),
|
||||||
var request api.QueryStateAndAuthChainRequest
|
|
||||||
var response api.QueryStateAndAuthChainResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryStateAndAuthChain(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverPerformBackfillPath,
|
RoomserverPerformBackfillPath,
|
||||||
httputil.MakeInternalAPI("PerformBackfill", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("PerformBackfill", r.PerformBackfill),
|
||||||
var request api.PerformBackfillRequest
|
|
||||||
var response api.PerformBackfillResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.PerformBackfill(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverPerformForgetPath,
|
RoomserverPerformForgetPath,
|
||||||
httputil.MakeInternalAPI("PerformForget", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("PerformForget", r.PerformForget),
|
||||||
var request api.PerformForgetRequest
|
|
||||||
var response api.PerformForgetResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.PerformForget(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryRoomVersionCapabilitiesPath,
|
RoomserverQueryRoomVersionCapabilitiesPath,
|
||||||
httputil.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryRoomVersionCapabilities", r.QueryRoomVersionCapabilities),
|
||||||
var request api.QueryRoomVersionCapabilitiesRequest
|
|
||||||
var response api.QueryRoomVersionCapabilitiesResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryRoomVersionCapabilities(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryRoomVersionForRoomPath,
|
RoomserverQueryRoomVersionForRoomPath,
|
||||||
httputil.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("QueryRoomVersionForRoom", r.QueryRoomVersionForRoom),
|
||||||
var request api.QueryRoomVersionForRoomRequest
|
|
||||||
var response api.QueryRoomVersionForRoomResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.QueryRoomVersionForRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverSetRoomAliasPath,
|
RoomserverSetRoomAliasPath,
|
||||||
httputil.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("SetRoomAlias", r.SetRoomAlias),
|
||||||
var request api.SetRoomAliasRequest
|
|
||||||
var response api.SetRoomAliasResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.SetRoomAlias(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverGetRoomIDForAliasPath,
|
RoomserverGetRoomIDForAliasPath,
|
||||||
httputil.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("GetRoomIDForAlias", r.GetRoomIDForAlias),
|
||||||
var request api.GetRoomIDForAliasRequest
|
|
||||||
var response api.GetRoomIDForAliasResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.GetRoomIDForAlias(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverGetAliasesForRoomIDPath,
|
RoomserverGetAliasesForRoomIDPath,
|
||||||
httputil.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("GetAliasesForRoomID", r.GetAliasesForRoomID),
|
||||||
var request api.GetAliasesForRoomIDRequest
|
|
||||||
var response api.GetAliasesForRoomIDResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.GetAliasesForRoomID(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverRemoveRoomAliasPath,
|
RoomserverRemoveRoomAliasPath,
|
||||||
httputil.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalRPCAPI("RemoveRoomAlias", r.RemoveRoomAlias),
|
||||||
var request api.RemoveRoomAliasRequest
|
|
||||||
var response api.RemoveRoomAliasResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
if err := r.RemoveRoomAlias(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryCurrentStatePath,
|
|
||||||
httputil.MakeInternalAPI("queryCurrentState", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryCurrentStateRequest{}
|
RoomserverQueryCurrentStatePath,
|
||||||
response := api.QueryCurrentStateResponse{}
|
httputil.MakeInternalRPCAPI("QueryCurrentState", r.QueryCurrentState),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryCurrentState(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryRoomsForUserPath,
|
|
||||||
httputil.MakeInternalAPI("queryRoomsForUser", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryRoomsForUserRequest{}
|
RoomserverQueryRoomsForUserPath,
|
||||||
response := api.QueryRoomsForUserResponse{}
|
httputil.MakeInternalRPCAPI("QueryRoomsForUser", r.QueryRoomsForUser),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryRoomsForUser(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryBulkStateContentPath,
|
|
||||||
httputil.MakeInternalAPI("queryBulkStateContent", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryBulkStateContentRequest{}
|
RoomserverQueryBulkStateContentPath,
|
||||||
response := api.QueryBulkStateContentResponse{}
|
httputil.MakeInternalRPCAPI("QueryBulkStateContent", r.QueryBulkStateContent),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryBulkStateContent(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQuerySharedUsersPath,
|
|
||||||
httputil.MakeInternalAPI("querySharedUsers", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QuerySharedUsersRequest{}
|
RoomserverQuerySharedUsersPath,
|
||||||
response := api.QuerySharedUsersResponse{}
|
httputil.MakeInternalRPCAPI("QuerySharedUsers", r.QuerySharedUsers),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QuerySharedUsers(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryKnownUsersPath,
|
|
||||||
httputil.MakeInternalAPI("queryKnownUsers", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryKnownUsersRequest{}
|
RoomserverQueryKnownUsersPath,
|
||||||
response := api.QueryKnownUsersResponse{}
|
httputil.MakeInternalRPCAPI("QueryKnownUsers", r.QueryKnownUsers),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryKnownUsers(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryServerBannedFromRoomPath,
|
|
||||||
httputil.MakeInternalAPI("queryServerBannedFromRoom", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryServerBannedFromRoomRequest{}
|
RoomserverQueryServerBannedFromRoomPath,
|
||||||
response := api.QueryServerBannedFromRoomResponse{}
|
httputil.MakeInternalRPCAPI("QueryServerBannedFromRoom", r.QueryServerBannedFromRoom),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryServerBannedFromRoom(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryAuthChainPath,
|
|
||||||
httputil.MakeInternalAPI("queryAuthChain", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryAuthChainRequest{}
|
RoomserverQueryAuthChainPath,
|
||||||
response := api.QueryAuthChainResponse{}
|
httputil.MakeInternalRPCAPI("QueryAuthChain", r.QueryAuthChain),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryAuthChain(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(RoomserverQueryRestrictedJoinAllowed,
|
|
||||||
httputil.MakeInternalAPI("queryRestrictedJoinAllowed", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryRestrictedJoinAllowedRequest{}
|
RoomserverQueryRestrictedJoinAllowed,
|
||||||
response := api.QueryRestrictedJoinAllowedResponse{}
|
httputil.MakeInternalRPCAPI("QueryRestrictedJoinAllowed", r.QueryRestrictedJoinAllowed),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := r.QueryRestrictedJoinAllowed(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ type ClientUserAPI interface {
|
||||||
QueryNotifications(ctx context.Context, req *QueryNotificationsRequest, res *QueryNotificationsResponse) error
|
QueryNotifications(ctx context.Context, req *QueryNotificationsRequest, res *QueryNotificationsResponse) error
|
||||||
InputAccountData(ctx context.Context, req *InputAccountDataRequest, res *InputAccountDataResponse) error
|
InputAccountData(ctx context.Context, req *InputAccountDataRequest, res *InputAccountDataResponse) error
|
||||||
PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) error
|
PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) error
|
||||||
QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse)
|
QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) error
|
||||||
|
|
||||||
QueryThreePIDsForLocalpart(ctx context.Context, req *QueryThreePIDsForLocalpartRequest, res *QueryThreePIDsForLocalpartResponse) error
|
QueryThreePIDsForLocalpart(ctx context.Context, req *QueryThreePIDsForLocalpartRequest, res *QueryThreePIDsForLocalpartResponse) error
|
||||||
QueryLocalpartForThreePID(ctx context.Context, req *QueryLocalpartForThreePIDRequest, res *QueryLocalpartForThreePIDResponse) error
|
QueryLocalpartForThreePID(ctx context.Context, req *QueryLocalpartForThreePIDRequest, res *QueryLocalpartForThreePIDResponse) error
|
||||||
|
|
|
@ -94,9 +94,10 @@ func (t *UserInternalAPITrace) PerformPushRulesPut(ctx context.Context, req *Per
|
||||||
util.GetLogger(ctx).Infof("PerformPushRulesPut req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).Infof("PerformPushRulesPut req=%+v res=%+v", js(req), js(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (t *UserInternalAPITrace) QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) {
|
func (t *UserInternalAPITrace) QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) error {
|
||||||
t.Impl.QueryKeyBackup(ctx, req, res)
|
err := t.Impl.QueryKeyBackup(ctx, req, res)
|
||||||
util.GetLogger(ctx).Infof("QueryKeyBackup req=%+v res=%+v", js(req), js(res))
|
util.GetLogger(ctx).Infof("QueryKeyBackup req=%+v res=%+v", js(req), js(res))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
func (t *UserInternalAPITrace) QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error {
|
func (t *UserInternalAPITrace) QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error {
|
||||||
err := t.Impl.QueryProfile(ctx, req, res)
|
err := t.Impl.QueryProfile(ctx, req, res)
|
||||||
|
|
|
@ -627,16 +627,16 @@ func (a *UserInternalAPI) uploadBackupKeys(ctx context.Context, req *api.Perform
|
||||||
res.KeyETag = etag
|
res.KeyETag = etag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *UserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyBackupRequest, res *api.QueryKeyBackupResponse) {
|
func (a *UserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyBackupRequest, res *api.QueryKeyBackupResponse) error {
|
||||||
version, algorithm, authData, etag, deleted, err := a.DB.GetKeyBackup(ctx, req.UserID, req.Version)
|
version, algorithm, authData, etag, deleted, err := a.DB.GetKeyBackup(ctx, req.UserID, req.Version)
|
||||||
res.Version = version
|
res.Version = version
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
res.Exists = false
|
res.Exists = false
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
res.Error = fmt.Sprintf("failed to query key backup: %s", err)
|
res.Error = fmt.Sprintf("failed to query key backup: %s", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
res.Algorithm = algorithm
|
res.Algorithm = algorithm
|
||||||
res.AuthData = authData
|
res.AuthData = authData
|
||||||
|
@ -648,15 +648,16 @@ func (a *UserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyB
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = fmt.Sprintf("failed to count keys: %s", err)
|
res.Error = fmt.Sprintf("failed to count keys: %s", err)
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := a.DB.GetBackupKeys(ctx, version, req.UserID, req.KeysForRoomID, req.KeysForSessionID)
|
result, err := a.DB.GetBackupKeys(ctx, version, req.UserID, req.KeysForRoomID, req.KeysForSessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = fmt.Sprintf("failed to query keys: %s", err)
|
res.Error = fmt.Sprintf("failed to query keys: %s", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
res.Keys = result
|
res.Keys = result
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *UserInternalAPI) QueryNotifications(ctx context.Context, req *api.QueryNotificationsRequest, res *api.QueryNotificationsResponse) error {
|
func (a *UserInternalAPI) QueryNotifications(ctx context.Context, req *api.QueryNotificationsRequest, res *api.QueryNotificationsResponse) error {
|
||||||
|
|
|
@ -269,8 +269,8 @@ func (h *httpUserInternalAPI) QueryKeyBackup(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QueryKeyBackupRequest,
|
request *api.QueryKeyBackupRequest,
|
||||||
response *api.QueryKeyBackupResponse,
|
response *api.QueryKeyBackupResponse,
|
||||||
) {
|
) error {
|
||||||
_ = httputil.CallInternalRPCAPI(
|
return httputil.CallInternalRPCAPI(
|
||||||
"QueryKeyBackup", h.apiURL+QueryKeyBackupPath,
|
"QueryKeyBackup", h.apiURL+QueryKeyBackupPath,
|
||||||
h.httpClient, ctx, request, response,
|
h.httpClient, ctx, request, response,
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
@ -29,337 +27,137 @@ import (
|
||||||
func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
||||||
addRoutesLoginToken(internalAPIMux, s)
|
addRoutesLoginToken(internalAPIMux, s)
|
||||||
|
|
||||||
internalAPIMux.Handle(PerformAccountCreationPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performAccountCreation", func(req *http.Request) util.JSONResponse {
|
PerformAccountCreationPath,
|
||||||
request := api.PerformAccountCreationRequest{}
|
httputil.MakeInternalRPCAPI("PerformAccountCreation", s.PerformAccountCreation),
|
||||||
response := api.PerformAccountCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformAccountCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformPasswordUpdatePath,
|
|
||||||
httputil.MakeInternalAPI("performPasswordUpdate", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformPasswordUpdateRequest{}
|
|
||||||
response := api.PerformPasswordUpdateResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPasswordUpdate(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformDeviceCreationPath,
|
|
||||||
httputil.MakeInternalAPI("performDeviceCreation", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformDeviceCreationRequest{}
|
|
||||||
response := api.PerformDeviceCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformDeviceCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformLastSeenUpdatePath,
|
|
||||||
httputil.MakeInternalAPI("performLastSeenUpdate", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformLastSeenUpdateRequest{}
|
|
||||||
response := api.PerformLastSeenUpdateResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformLastSeenUpdate(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformDeviceUpdatePath,
|
|
||||||
httputil.MakeInternalAPI("performDeviceUpdate", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformDeviceUpdateRequest{}
|
|
||||||
response := api.PerformDeviceUpdateResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformDeviceUpdate(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformDeviceDeletionPath,
|
|
||||||
httputil.MakeInternalAPI("performDeviceDeletion", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformDeviceDeletionRequest{}
|
|
||||||
response := api.PerformDeviceDeletionResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformDeviceDeletion(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformAccountDeactivationPath,
|
|
||||||
httputil.MakeInternalAPI("performAccountDeactivation", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformAccountDeactivationRequest{}
|
|
||||||
response := api.PerformAccountDeactivationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformAccountDeactivation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformOpenIDTokenCreationPath,
|
|
||||||
httputil.MakeInternalAPI("performOpenIDTokenCreation", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformOpenIDTokenCreationRequest{}
|
|
||||||
response := api.PerformOpenIDTokenCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformOpenIDTokenCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryProfilePath,
|
|
||||||
httputil.MakeInternalAPI("queryProfile", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryProfileRequest{}
|
|
||||||
response := api.QueryProfileResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryProfile(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryAccessTokenPath,
|
|
||||||
httputil.MakeInternalAPI("queryAccessToken", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryAccessTokenRequest{}
|
|
||||||
response := api.QueryAccessTokenResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccessToken(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryDevicesPath,
|
|
||||||
httputil.MakeInternalAPI("queryDevices", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryDevicesRequest{}
|
|
||||||
response := api.QueryDevicesResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryDevices(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{}
|
|
||||||
response := api.QueryAccountDataResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccountData(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryDeviceInfosPath,
|
|
||||||
httputil.MakeInternalAPI("queryDeviceInfos", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryDeviceInfosRequest{}
|
|
||||||
response := api.QueryDeviceInfosResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryDeviceInfos(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QuerySearchProfilesPath,
|
|
||||||
httputil.MakeInternalAPI("querySearchProfiles", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QuerySearchProfilesRequest{}
|
|
||||||
response := api.QuerySearchProfilesResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QuerySearchProfiles(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryOpenIDTokenPath,
|
|
||||||
httputil.MakeInternalAPI("queryOpenIDToken", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryOpenIDTokenRequest{}
|
|
||||||
response := api.QueryOpenIDTokenResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryOpenIDToken(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(InputAccountDataPath,
|
|
||||||
httputil.MakeInternalAPI("inputAccountDataPath", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.InputAccountDataRequest{}
|
|
||||||
response := api.InputAccountDataResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.InputAccountData(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryKeyBackupPath,
|
|
||||||
httputil.MakeInternalAPI("queryKeyBackup", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.QueryKeyBackupRequest{}
|
|
||||||
response := api.QueryKeyBackupResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
s.QueryKeyBackup(req.Context(), &request, &response)
|
|
||||||
if response.Error != "" {
|
|
||||||
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", response.Error))
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformKeyBackupPath,
|
|
||||||
httputil.MakeInternalAPI("performKeyBackup", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformKeyBackupRequest{}
|
|
||||||
response := api.PerformKeyBackupResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
err := s.PerformKeyBackup(req.Context(), &request, &response)
|
|
||||||
if err != nil {
|
|
||||||
return util.JSONResponse{Code: http.StatusBadRequest, JSON: &response}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(QueryNotificationsPath,
|
|
||||||
httputil.MakeInternalAPI("queryNotifications", func(req *http.Request) util.JSONResponse {
|
|
||||||
var request api.QueryNotificationsRequest
|
|
||||||
var response api.QueryNotificationsResponse
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryNotifications(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(PerformPusherSetPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performPusherSet", func(req *http.Request) util.JSONResponse {
|
PerformPasswordUpdatePath,
|
||||||
request := api.PerformPusherSetRequest{}
|
httputil.MakeInternalRPCAPI("PerformPasswordUpdate", s.PerformPasswordUpdate),
|
||||||
response := struct{}{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPusherSet(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
internalAPIMux.Handle(PerformPusherDeletionPath,
|
|
||||||
httputil.MakeInternalAPI("performPusherDeletion", func(req *http.Request) util.JSONResponse {
|
|
||||||
request := api.PerformPusherDeletionRequest{}
|
|
||||||
response := struct{}{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPusherDeletion(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(QueryPushersPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("queryPushers", func(req *http.Request) util.JSONResponse {
|
PerformDeviceCreationPath,
|
||||||
request := api.QueryPushersRequest{}
|
httputil.MakeInternalRPCAPI("PerformDeviceCreation", s.PerformDeviceCreation),
|
||||||
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(PerformPushRulesPutPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performPushRulesPut", func(req *http.Request) util.JSONResponse {
|
PerformLastSeenUpdatePath,
|
||||||
request := api.PerformPushRulesPutRequest{}
|
httputil.MakeInternalRPCAPI("PerformLastSeenUpdate", s.PerformLastSeenUpdate),
|
||||||
response := struct{}{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformPushRulesPut(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internalAPIMux.Handle(QueryPushRulesPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("queryPushRules", func(req *http.Request) util.JSONResponse {
|
PerformDeviceUpdatePath,
|
||||||
request := api.QueryPushRulesRequest{}
|
httputil.MakeInternalRPCAPI("PerformDeviceUpdate", s.PerformDeviceUpdate),
|
||||||
response := api.QueryPushRulesResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryPushRules(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformSetAvatarURLPath,
|
|
||||||
httputil.MakeInternalAPI("performSetAvatarURL", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformSetAvatarURLRequest{}
|
PerformDeviceDeletionPath,
|
||||||
response := api.PerformSetAvatarURLResponse{}
|
httputil.MakeInternalRPCAPI("PerformDeviceDeletion", s.PerformDeviceDeletion),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.SetAvatarURL(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformAccountDeactivationPath,
|
||||||
|
httputil.MakeInternalRPCAPI("PerformAccountDeactivation", s.PerformAccountDeactivation),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformOpenIDTokenCreationPath,
|
||||||
|
httputil.MakeInternalRPCAPI("PerformOpenIDTokenCreation", s.PerformOpenIDTokenCreation),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryProfilePath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryProfile", s.QueryProfile),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryAccessTokenPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryAccessToken", s.QueryAccessToken),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryAccessTokenPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryAccessToken", s.QueryAccessToken),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryDevicesPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryDevices", s.QueryDevices),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryAccountDataPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryAccountData", s.QueryAccountData),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryDeviceInfosPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryDeviceInfos", s.QueryDeviceInfos),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QuerySearchProfilesPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QuerySearchProfiles", s.QuerySearchProfiles),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryOpenIDTokenPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryOpenIDToken", s.QueryOpenIDToken),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
InputAccountDataPath,
|
||||||
|
httputil.MakeInternalRPCAPI("InputAccountData", s.InputAccountData),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryKeyBackupPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryKeyBackup", s.QueryKeyBackup),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformKeyBackupPath,
|
||||||
|
httputil.MakeInternalRPCAPI("PerformKeyBackup", s.PerformKeyBackup),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryNotificationsPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryNotifications", s.QueryNotifications),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformPusherSetPath,
|
||||||
|
httputil.MakeInternalRPCAPI("PerformPusherSet", s.PerformPusherSet),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformPusherDeletionPath,
|
||||||
|
httputil.MakeInternalRPCAPI("PerformPusherDeletion", s.PerformPusherDeletion),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryPushersPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryPushers", s.QueryPushers),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformPushRulesPutPath,
|
||||||
|
httputil.MakeInternalRPCAPI("PerformPushRulesPut", s.PerformPushRulesPut),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
QueryPushRulesPath,
|
||||||
|
httputil.MakeInternalRPCAPI("QueryPushRules", s.QueryPushRules),
|
||||||
|
)
|
||||||
|
|
||||||
|
internalAPIMux.Handle(
|
||||||
|
PerformSetAvatarURLPath,
|
||||||
|
httputil.MakeInternalRPCAPI("PerformSetAvatarURL", s.SetAvatarURL),
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: Look at the shape of this
|
||||||
internalAPIMux.Handle(QueryNumericLocalpartPath,
|
internalAPIMux.Handle(QueryNumericLocalpartPath,
|
||||||
httputil.MakeInternalAPI("queryNumericLocalpart", func(req *http.Request) util.JSONResponse {
|
httputil.MakeInternalAPI("queryNumericLocalpart", func(req *http.Request) util.JSONResponse {
|
||||||
response := api.QueryNumericLocalpartResponse{}
|
response := api.QueryNumericLocalpartResponse{}
|
||||||
|
@ -369,92 +167,39 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryAccountAvailabilityPath,
|
|
||||||
httputil.MakeInternalAPI("queryAccountAvailability", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryAccountAvailabilityRequest{}
|
QueryAccountAvailabilityPath,
|
||||||
response := api.QueryAccountAvailabilityResponse{}
|
httputil.MakeInternalRPCAPI("QueryAccountAvailability", s.QueryAccountAvailability),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccountAvailability(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryAccountByPasswordPath,
|
|
||||||
httputil.MakeInternalAPI("queryAccountByPassword", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryAccountByPasswordRequest{}
|
QueryAccountByPasswordPath,
|
||||||
response := api.QueryAccountByPasswordResponse{}
|
httputil.MakeInternalRPCAPI("QueryAccountByPassword", s.QueryAccountByPassword),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryAccountByPassword(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformSetDisplayNamePath,
|
|
||||||
httputil.MakeInternalAPI("performSetDisplayName", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformUpdateDisplayNameRequest{}
|
PerformSetDisplayNamePath,
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
httputil.MakeInternalRPCAPI("SetDisplayName", s.SetDisplayName),
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.SetDisplayName(req.Context(), &request, &struct{}{}); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryLocalpartForThreePIDPath,
|
|
||||||
httputil.MakeInternalAPI("queryLocalpartForThreePID", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryLocalpartForThreePIDRequest{}
|
QueryLocalpartForThreePIDPath,
|
||||||
response := api.QueryLocalpartForThreePIDResponse{}
|
httputil.MakeInternalRPCAPI("QueryLocalpartForThreePID", s.QueryLocalpartForThreePID),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryLocalpartForThreePID(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryThreePIDsForLocalpartPath,
|
|
||||||
httputil.MakeInternalAPI("queryThreePIDsForLocalpart", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryThreePIDsForLocalpartRequest{}
|
QueryThreePIDsForLocalpartPath,
|
||||||
response := api.QueryThreePIDsForLocalpartResponse{}
|
httputil.MakeInternalRPCAPI("QueryThreePIDsForLocalpart", s.QueryThreePIDsForLocalpart),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryThreePIDsForLocalpart(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformForgetThreePIDPath,
|
|
||||||
httputil.MakeInternalAPI("performForgetThreePID", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformForgetThreePIDRequest{}
|
PerformForgetThreePIDPath,
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
httputil.MakeInternalRPCAPI("PerformForgetThreePID", s.PerformForgetThreePID),
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformForgetThreePID(req.Context(), &request, &struct{}{}); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformSaveThreePIDAssociationPath,
|
|
||||||
httputil.MakeInternalAPI("performSaveThreePIDAssociation", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformSaveThreePIDAssociationRequest{}
|
PerformSaveThreePIDAssociationPath,
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
httputil.MakeInternalRPCAPI("PerformSaveThreePIDAssociation", s.PerformSaveThreePIDAssociation),
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformSaveThreePIDAssociation(req.Context(), &request, &struct{}{}); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,54 +15,25 @@
|
||||||
package inthttp
|
package inthttp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// addRoutesLoginToken adds routes for all login token API calls.
|
// addRoutesLoginToken adds routes for all login token API calls.
|
||||||
func addRoutesLoginToken(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
func addRoutesLoginToken(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
||||||
internalAPIMux.Handle(PerformLoginTokenCreationPath,
|
internalAPIMux.Handle(
|
||||||
httputil.MakeInternalAPI("performLoginTokenCreation", func(req *http.Request) util.JSONResponse {
|
PerformLoginTokenCreationPath,
|
||||||
request := api.PerformLoginTokenCreationRequest{}
|
httputil.MakeInternalRPCAPI("PerformLoginTokenCreation", s.PerformLoginTokenCreation),
|
||||||
response := api.PerformLoginTokenCreationResponse{}
|
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformLoginTokenCreation(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(PerformLoginTokenDeletionPath,
|
|
||||||
httputil.MakeInternalAPI("performLoginTokenDeletion", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.PerformLoginTokenDeletionRequest{}
|
PerformLoginTokenDeletionPath,
|
||||||
response := api.PerformLoginTokenDeletionResponse{}
|
httputil.MakeInternalRPCAPI("PerformLoginTokenDeletion", s.PerformLoginTokenDeletion),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.PerformLoginTokenDeletion(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(QueryLoginTokenPath,
|
|
||||||
httputil.MakeInternalAPI("queryLoginToken", func(req *http.Request) util.JSONResponse {
|
internalAPIMux.Handle(
|
||||||
request := api.QueryLoginTokenRequest{}
|
QueryLoginTokenPath,
|
||||||
response := api.QueryLoginTokenResponse{}
|
httputil.MakeInternalRPCAPI("QueryLoginToken", s.QueryLoginToken),
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
if err := s.QueryLoginToken(req.Context(), &request, &response); err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue