mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-09 07:03:10 -06:00
convert more deps of clientapi to finer-grained interfaces
This commit is contained in:
parent
9cd74c0a20
commit
de51376ad2
|
|
@ -33,13 +33,13 @@ import (
|
||||||
func AddPublicRoutes(
|
func AddPublicRoutes(
|
||||||
base *base.BaseDendrite,
|
base *base.BaseDendrite,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
transactionsCache *transactions.Cache,
|
transactionsCache *transactions.Cache,
|
||||||
fsAPI federationAPI.FederationInternalAPI,
|
fsAPI federationAPI.FederationInternalAPI,
|
||||||
userAPI userapi.ClientUserAPI,
|
userAPI userapi.ClientUserAPI,
|
||||||
userDirectoryProvider userapi.UserDirectoryProvider,
|
userDirectoryProvider userapi.UserDirectoryProvider,
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.ClientKeyAPI,
|
||||||
extRoomsProvider api.ExtraPublicRoomsProvider,
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
) {
|
) {
|
||||||
cfg := &base.Cfg.ClientAPI
|
cfg := &base.Cfg.ClientAPI
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ type fullyReadEvent struct {
|
||||||
// SaveReadMarker implements POST /rooms/{roomId}/read_markers
|
// SaveReadMarker implements POST /rooms/{roomId}/read_markers
|
||||||
func SaveReadMarker(
|
func SaveReadMarker(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
userAPI api.ClientUserAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
|
userAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
syncProducer *producers.SyncAPIProducer, device *api.Device, roomID string,
|
syncProducer *producers.SyncAPIProducer, device *api.Device, roomID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
// Verify that the user is a member of this room
|
// Verify that the user is a member of this room
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AdminEvacuateRoom(req *http.Request, device *userapi.Device, rsAPI roomserverAPI.RoomserverInternalAPI) util.JSONResponse {
|
func AdminEvacuateRoom(req *http.Request, device *userapi.Device, rsAPI roomserverAPI.ClientRoomserverAPI) util.JSONResponse {
|
||||||
if device.AccountType != userapi.AccountTypeAdmin {
|
if device.AccountType != userapi.AccountTypeAdmin {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import (
|
||||||
|
|
||||||
// GetAliases implements GET /_matrix/client/r0/rooms/{roomId}/aliases
|
// GetAliases implements GET /_matrix/client/r0/rooms/{roomId}/aliases
|
||||||
func GetAliases(
|
func GetAliases(
|
||||||
req *http.Request, rsAPI api.RoomserverInternalAPI, device *userapi.Device, roomID string,
|
req *http.Request, rsAPI api.ClientRoomserverAPI, device *userapi.Device, roomID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
stateTuple := gomatrixserverlib.StateKeyTuple{
|
stateTuple := gomatrixserverlib.StateKeyTuple{
|
||||||
EventType: gomatrixserverlib.MRoomHistoryVisibility,
|
EventType: gomatrixserverlib.MRoomHistoryVisibility,
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
// GetCapabilities returns information about the server's supported feature set
|
// GetCapabilities returns information about the server's supported feature set
|
||||||
// and other relevant capabilities to an authenticated user.
|
// and other relevant capabilities to an authenticated user.
|
||||||
func GetCapabilities(
|
func GetCapabilities(
|
||||||
req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI,
|
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
roomVersionsQueryReq := roomserverAPI.QueryRoomVersionCapabilitiesRequest{}
|
roomVersionsQueryReq := roomserverAPI.QueryRoomVersionCapabilitiesRequest{}
|
||||||
roomVersionsQueryRes := roomserverAPI.QueryRoomVersionCapabilitiesResponse{}
|
roomVersionsQueryRes := roomserverAPI.QueryRoomVersionCapabilitiesResponse{}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ type fledglingEvent struct {
|
||||||
func CreateRoom(
|
func CreateRoom(
|
||||||
req *http.Request, device *api.Device,
|
req *http.Request, device *api.Device,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
profileAPI api.ClientUserAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
|
profileAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var r createRoomRequest
|
var r createRoomRequest
|
||||||
|
|
@ -164,7 +164,7 @@ func createRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
r createRoomRequest, device *api.Device,
|
r createRoomRequest, device *api.Device,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
profileAPI api.ClientUserAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
|
profileAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
evTime time.Time,
|
evTime time.Time,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
|
@ -531,25 +531,23 @@ func createRoom(
|
||||||
gomatrixserverlib.NewInviteV2StrippedState(inviteEvent.Event),
|
gomatrixserverlib.NewInviteV2StrippedState(inviteEvent.Event),
|
||||||
)
|
)
|
||||||
// Send the invite event to the roomserver.
|
// Send the invite event to the roomserver.
|
||||||
err = roomserverAPI.SendInvite(
|
var inviteRes roomserverAPI.PerformInviteResponse
|
||||||
ctx,
|
event := inviteEvent.Headered(roomVersion)
|
||||||
rsAPI,
|
if err := rsAPI.PerformInvite(ctx, &roomserverAPI.PerformInviteRequest{
|
||||||
inviteEvent.Headered(roomVersion),
|
Event: event,
|
||||||
inviteStrippedState, // invite room state
|
InviteRoomState: inviteStrippedState,
|
||||||
cfg.Matrix.ServerName, // send as server
|
RoomVersion: event.RoomVersion,
|
||||||
nil, // transaction ID
|
SendAsServer: string(cfg.Matrix.ServerName),
|
||||||
)
|
}, &inviteRes); err != nil {
|
||||||
switch e := err.(type) {
|
util.GetLogger(ctx).WithError(err).Error("PerformInvite failed")
|
||||||
case *roomserverAPI.PerformError:
|
|
||||||
return e.JSONResponse()
|
|
||||||
case nil:
|
|
||||||
default:
|
|
||||||
util.GetLogger(ctx).WithError(err).Error("roomserverAPI.SendInvite failed")
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusInternalServerError,
|
Code: http.StatusInternalServerError,
|
||||||
JSON: jsonerror.InternalServerError(),
|
JSON: jsonerror.InternalServerError(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if inviteRes.Error != nil {
|
||||||
|
return inviteRes.Error.JSONResponse()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ func DirectoryRoom(
|
||||||
roomAlias string,
|
roomAlias string,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
fedSenderAPI federationAPI.FederationInternalAPI,
|
fedSenderAPI federationAPI.FederationInternalAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
_, domain, err := gomatrixserverlib.SplitID('#', roomAlias)
|
_, domain, err := gomatrixserverlib.SplitID('#', roomAlias)
|
||||||
|
|
@ -117,7 +117,7 @@ func SetLocalAlias(
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
alias string,
|
alias string,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
_, domain, err := gomatrixserverlib.SplitID('#', alias)
|
_, domain, err := gomatrixserverlib.SplitID('#', alias)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -199,7 +199,7 @@ func RemoveLocalAlias(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
alias string,
|
alias string,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
queryReq := roomserverAPI.RemoveRoomAliasRequest{
|
queryReq := roomserverAPI.RemoveRoomAliasRequest{
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
|
|
@ -237,7 +237,7 @@ type roomVisibility struct {
|
||||||
|
|
||||||
// GetVisibility implements GET /directory/list/room/{roomID}
|
// GetVisibility implements GET /directory/list/room/{roomID}
|
||||||
func GetVisibility(
|
func GetVisibility(
|
||||||
req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI,
|
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
roomID string,
|
roomID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var res roomserverAPI.QueryPublishedRoomsResponse
|
var res roomserverAPI.QueryPublishedRoomsResponse
|
||||||
|
|
@ -265,7 +265,7 @@ func GetVisibility(
|
||||||
// SetVisibility implements PUT /directory/list/room/{roomID}
|
// SetVisibility implements PUT /directory/list/room/{roomID}
|
||||||
// TODO: Allow admin users to edit the room visibility
|
// TODO: Allow admin users to edit the room visibility
|
||||||
func SetVisibility(
|
func SetVisibility(
|
||||||
req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI, dev *userapi.Device,
|
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI, dev *userapi.Device,
|
||||||
roomID string,
|
roomID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
resErr := checkMemberInRoom(req.Context(), rsAPI, dev.UserID, roomID)
|
resErr := checkMemberInRoom(req.Context(), rsAPI, dev.UserID, roomID)
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ type filter struct {
|
||||||
|
|
||||||
// GetPostPublicRooms implements GET and POST /publicRooms
|
// GetPostPublicRooms implements GET and POST /publicRooms
|
||||||
func GetPostPublicRooms(
|
func GetPostPublicRooms(
|
||||||
req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI,
|
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
extRoomsProvider api.ExtraPublicRoomsProvider,
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
|
|
@ -91,7 +91,7 @@ func GetPostPublicRooms(
|
||||||
}
|
}
|
||||||
|
|
||||||
func publicRooms(
|
func publicRooms(
|
||||||
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.RoomserverInternalAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
) (*gomatrixserverlib.RespPublicRooms, error) {
|
) (*gomatrixserverlib.RespPublicRooms, error) {
|
||||||
|
|
||||||
response := gomatrixserverlib.RespPublicRooms{
|
response := gomatrixserverlib.RespPublicRooms{
|
||||||
|
|
@ -229,7 +229,7 @@ func sliceInto(slice []gomatrixserverlib.PublicRoom, since int64, limit int16) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshPublicRoomCache(
|
func refreshPublicRoomCache(
|
||||||
ctx context.Context, rsAPI roomserverAPI.RoomserverInternalAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
ctx context.Context, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
) []gomatrixserverlib.PublicRoom {
|
) []gomatrixserverlib.PublicRoom {
|
||||||
cacheMu.Lock()
|
cacheMu.Lock()
|
||||||
defer cacheMu.Unlock()
|
defer cacheMu.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ type getEventRequest struct {
|
||||||
roomID string
|
roomID string
|
||||||
eventID string
|
eventID string
|
||||||
cfg *config.ClientAPI
|
cfg *config.ClientAPI
|
||||||
federation *gomatrixserverlib.FederationClient
|
|
||||||
requestedEvent *gomatrixserverlib.Event
|
requestedEvent *gomatrixserverlib.Event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,8 +42,7 @@ func GetEvent(
|
||||||
roomID string,
|
roomID string,
|
||||||
eventID string,
|
eventID string,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
eventsReq := api.QueryEventsByIDRequest{
|
eventsReq := api.QueryEventsByIDRequest{
|
||||||
EventIDs: []string{eventID},
|
EventIDs: []string{eventID},
|
||||||
|
|
@ -72,7 +70,6 @@ func GetEvent(
|
||||||
roomID: roomID,
|
roomID: roomID,
|
||||||
eventID: eventID,
|
eventID: eventID,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
federation: federation,
|
|
||||||
requestedEvent: requestedEvent,
|
requestedEvent: requestedEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
func JoinRoomByIDOrAlias(
|
func JoinRoomByIDOrAlias(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
device *api.Device,
|
device *api.Device,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
profileAPI api.ClientUserAPI,
|
profileAPI api.ClientUserAPI,
|
||||||
roomIDOrAlias string,
|
roomIDOrAlias string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ type crossSigningRequest struct {
|
||||||
|
|
||||||
func UploadCrossSigningDeviceKeys(
|
func UploadCrossSigningDeviceKeys(
|
||||||
req *http.Request, userInteractiveAuth *auth.UserInteractive,
|
req *http.Request, userInteractiveAuth *auth.UserInteractive,
|
||||||
keyserverAPI api.KeyInternalAPI, device *userapi.Device,
|
keyserverAPI api.ClientKeyAPI, device *userapi.Device,
|
||||||
accountAPI userapi.ClientUserAPI, cfg *config.ClientAPI,
|
accountAPI userapi.ClientUserAPI, cfg *config.ClientAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
uploadReq := &crossSigningRequest{}
|
uploadReq := &crossSigningRequest{}
|
||||||
|
|
@ -105,7 +105,7 @@ func UploadCrossSigningDeviceKeys(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UploadCrossSigningDeviceSignatures(req *http.Request, keyserverAPI api.KeyInternalAPI, device *userapi.Device) util.JSONResponse {
|
func UploadCrossSigningDeviceSignatures(req *http.Request, keyserverAPI api.ClientKeyAPI, device *userapi.Device) util.JSONResponse {
|
||||||
uploadReq := &api.PerformUploadDeviceSignaturesRequest{}
|
uploadReq := &api.PerformUploadDeviceSignaturesRequest{}
|
||||||
uploadRes := &api.PerformUploadDeviceSignaturesResponse{}
|
uploadRes := &api.PerformUploadDeviceSignaturesResponse{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type uploadKeysRequest struct {
|
||||||
OneTimeKeys map[string]json.RawMessage `json:"one_time_keys"`
|
OneTimeKeys map[string]json.RawMessage `json:"one_time_keys"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func UploadKeys(req *http.Request, keyAPI api.KeyInternalAPI, device *userapi.Device) util.JSONResponse {
|
func UploadKeys(req *http.Request, keyAPI api.ClientKeyAPI, device *userapi.Device) util.JSONResponse {
|
||||||
var r uploadKeysRequest
|
var r uploadKeysRequest
|
||||||
resErr := httputil.UnmarshalJSONRequest(req, &r)
|
resErr := httputil.UnmarshalJSONRequest(req, &r)
|
||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
|
|
@ -100,7 +100,7 @@ func (r *queryKeysRequest) GetTimeout() time.Duration {
|
||||||
return time.Duration(r.Timeout) * time.Millisecond
|
return time.Duration(r.Timeout) * time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
func QueryKeys(req *http.Request, keyAPI api.KeyInternalAPI, device *userapi.Device) util.JSONResponse {
|
func QueryKeys(req *http.Request, keyAPI api.ClientKeyAPI, device *userapi.Device) util.JSONResponse {
|
||||||
var r queryKeysRequest
|
var r queryKeysRequest
|
||||||
resErr := httputil.UnmarshalJSONRequest(req, &r)
|
resErr := httputil.UnmarshalJSONRequest(req, &r)
|
||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
|
|
@ -138,7 +138,7 @@ func (r *claimKeysRequest) GetTimeout() time.Duration {
|
||||||
return time.Duration(r.TimeoutMS) * time.Millisecond
|
return time.Duration(r.TimeoutMS) * time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClaimKeys(req *http.Request, keyAPI api.KeyInternalAPI) util.JSONResponse {
|
func ClaimKeys(req *http.Request, keyAPI api.ClientKeyAPI) util.JSONResponse {
|
||||||
var r claimKeysRequest
|
var r claimKeysRequest
|
||||||
resErr := httputil.UnmarshalJSONRequest(req, &r)
|
resErr := httputil.UnmarshalJSONRequest(req, &r)
|
||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
func LeaveRoomByID(
|
func LeaveRoomByID(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
device *api.Device,
|
device *api.Device,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
roomID string,
|
roomID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
// Prepare to ask the roomserver to perform the room join.
|
// Prepare to ask the roomserver to perform the room join.
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/clientapi/threepid"
|
"github.com/matrix-org/dendrite/clientapi/threepid"
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
|
|
@ -40,7 +41,7 @@ var errMissingUserID = errors.New("'user_id' must be supplied")
|
||||||
func SendBan(
|
func SendBan(
|
||||||
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
||||||
roomID string, cfg *config.ClientAPI,
|
roomID string, cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
|
body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
|
||||||
if reqErr != nil {
|
if reqErr != nil {
|
||||||
|
|
@ -83,7 +84,7 @@ func SendBan(
|
||||||
func sendMembership(ctx context.Context, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
func sendMembership(ctx context.Context, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
||||||
roomID, membership, reason string, cfg *config.ClientAPI, targetUserID string, evTime time.Time,
|
roomID, membership, reason string, cfg *config.ClientAPI, targetUserID string, evTime time.Time,
|
||||||
roomVer gomatrixserverlib.RoomVersion,
|
roomVer gomatrixserverlib.RoomVersion,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI) util.JSONResponse {
|
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceQueryAPI) util.JSONResponse {
|
||||||
|
|
||||||
event, err := buildMembershipEvent(
|
event, err := buildMembershipEvent(
|
||||||
ctx, targetUserID, reason, profileAPI, device, membership,
|
ctx, targetUserID, reason, profileAPI, device, membership,
|
||||||
|
|
@ -126,7 +127,7 @@ func sendMembership(ctx context.Context, profileAPI userapi.ClientUserAPI, devic
|
||||||
func SendKick(
|
func SendKick(
|
||||||
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
||||||
roomID string, cfg *config.ClientAPI,
|
roomID string, cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
|
body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
|
||||||
if reqErr != nil {
|
if reqErr != nil {
|
||||||
|
|
@ -166,7 +167,7 @@ func SendKick(
|
||||||
func SendUnban(
|
func SendUnban(
|
||||||
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
||||||
roomID string, cfg *config.ClientAPI,
|
roomID string, cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
|
body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
|
||||||
if reqErr != nil {
|
if reqErr != nil {
|
||||||
|
|
@ -201,7 +202,7 @@ func SendUnban(
|
||||||
func SendInvite(
|
func SendInvite(
|
||||||
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
|
||||||
roomID string, cfg *config.ClientAPI,
|
roomID string, cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
body, evTime, _, reqErr := extractRequestData(req, roomID, rsAPI)
|
body, evTime, _, reqErr := extractRequestData(req, roomID, rsAPI)
|
||||||
if reqErr != nil {
|
if reqErr != nil {
|
||||||
|
|
@ -237,7 +238,7 @@ func sendInvite(
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
roomID, userID, reason string,
|
roomID, userID, reason string,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI, evTime time.Time,
|
asAPI appserviceAPI.AppServiceQueryAPI, evTime time.Time,
|
||||||
) (util.JSONResponse, error) {
|
) (util.JSONResponse, error) {
|
||||||
event, err := buildMembershipEvent(
|
event, err := buildMembershipEvent(
|
||||||
|
|
@ -259,28 +260,27 @@ func sendInvite(
|
||||||
return jsonerror.InternalServerError(), err
|
return jsonerror.InternalServerError(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = roomserverAPI.SendInvite(
|
var inviteRes api.PerformInviteResponse
|
||||||
ctx, rsAPI,
|
if err := rsAPI.PerformInvite(ctx, &api.PerformInviteRequest{
|
||||||
event,
|
Event: event,
|
||||||
nil, // ask the roomserver to draw up invite room state for us
|
InviteRoomState: nil, // ask the roomserver to draw up invite room state for us
|
||||||
cfg.Matrix.ServerName,
|
RoomVersion: event.RoomVersion,
|
||||||
nil,
|
SendAsServer: string(cfg.Matrix.ServerName),
|
||||||
)
|
}, &inviteRes); err != nil {
|
||||||
switch e := err.(type) {
|
util.GetLogger(ctx).WithError(err).Error("PerformInvite failed")
|
||||||
case *roomserverAPI.PerformError:
|
|
||||||
return e.JSONResponse(), err
|
|
||||||
case nil:
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: struct{}{},
|
|
||||||
}, nil
|
|
||||||
default:
|
|
||||||
util.GetLogger(ctx).WithError(err).Error("roomserverAPI.SendInvite failed")
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusInternalServerError,
|
Code: http.StatusInternalServerError,
|
||||||
JSON: jsonerror.InternalServerError(),
|
JSON: jsonerror.InternalServerError(),
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
if inviteRes.Error != nil {
|
||||||
|
return inviteRes.Error.JSONResponse(), inviteRes.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: struct{}{},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildMembershipEvent(
|
func buildMembershipEvent(
|
||||||
|
|
@ -289,7 +289,7 @@ func buildMembershipEvent(
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
membership, roomID string, isDirect bool,
|
membership, roomID string, isDirect bool,
|
||||||
cfg *config.ClientAPI, evTime time.Time,
|
cfg *config.ClientAPI, evTime time.Time,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*gomatrixserverlib.HeaderedEvent, error) {
|
||||||
profile, err := loadProfile(ctx, targetUserID, cfg, profileAPI, asAPI)
|
profile, err := loadProfile(ctx, targetUserID, cfg, profileAPI, asAPI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -344,7 +344,7 @@ func loadProfile(
|
||||||
return profile, err
|
return profile, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractRequestData(req *http.Request, roomID string, rsAPI roomserverAPI.RoomserverInternalAPI) (
|
func extractRequestData(req *http.Request, roomID string, rsAPI roomserverAPI.ClientRoomserverAPI) (
|
||||||
body *threepid.MembershipRequest, evTime time.Time, roomVer gomatrixserverlib.RoomVersion, resErr *util.JSONResponse,
|
body *threepid.MembershipRequest, evTime time.Time, roomVer gomatrixserverlib.RoomVersion, resErr *util.JSONResponse,
|
||||||
) {
|
) {
|
||||||
verReq := roomserverAPI.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
verReq := roomserverAPI.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||||
|
|
@ -379,7 +379,7 @@ func checkAndProcessThreepid(
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
body *threepid.MembershipRequest,
|
body *threepid.MembershipRequest,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
profileAPI userapi.ClientUserAPI,
|
profileAPI userapi.ClientUserAPI,
|
||||||
roomID string,
|
roomID string,
|
||||||
evTime time.Time,
|
evTime time.Time,
|
||||||
|
|
@ -418,7 +418,7 @@ func checkAndProcessThreepid(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMemberInRoom(ctx context.Context, rsAPI roomserverAPI.RoomserverInternalAPI, userID, roomID string) *util.JSONResponse {
|
func checkMemberInRoom(ctx context.Context, rsAPI roomserverAPI.ClientRoomserverAPI, userID, roomID string) *util.JSONResponse {
|
||||||
tuple := gomatrixserverlib.StateKeyTuple{
|
tuple := gomatrixserverlib.StateKeyTuple{
|
||||||
EventType: gomatrixserverlib.MRoomMember,
|
EventType: gomatrixserverlib.MRoomMember,
|
||||||
StateKey: userID,
|
StateKey: userID,
|
||||||
|
|
@ -457,7 +457,7 @@ func checkMemberInRoom(ctx context.Context, rsAPI roomserverAPI.RoomserverIntern
|
||||||
|
|
||||||
func SendForget(
|
func SendForget(
|
||||||
req *http.Request, device *userapi.Device,
|
req *http.Request, device *userapi.Device,
|
||||||
roomID string, rsAPI roomserverAPI.RoomserverInternalAPI,
|
roomID string, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
ctx := req.Context()
|
ctx := req.Context()
|
||||||
logger := util.GetLogger(ctx).WithField("roomID", roomID).WithField("userID", device.UserID)
|
logger := util.GetLogger(ctx).WithField("roomID", roomID).WithField("userID", device.UserID)
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ type databaseJoinedMember struct {
|
||||||
func GetMemberships(
|
func GetMemberships(
|
||||||
req *http.Request, device *userapi.Device, roomID string, joinedOnly bool,
|
req *http.Request, device *userapi.Device, roomID string, joinedOnly bool,
|
||||||
_ *config.ClientAPI,
|
_ *config.ClientAPI,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
queryReq := api.QueryMembershipsForRoomRequest{
|
queryReq := api.QueryMembershipsForRoomRequest{
|
||||||
JoinedOnly: joinedOnly,
|
JoinedOnly: joinedOnly,
|
||||||
|
|
@ -100,7 +100,7 @@ func GetMemberships(
|
||||||
func GetJoinedRooms(
|
func GetJoinedRooms(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var res api.QueryRoomsForUserResponse
|
var res api.QueryRoomsForUserResponse
|
||||||
err := rsAPI.QueryRoomsForUser(req.Context(), &api.QueryRoomsForUserRequest{
|
err := rsAPI.QueryRoomsForUser(req.Context(), &api.QueryRoomsForUserRequest{
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
func PeekRoomByIDOrAlias(
|
func PeekRoomByIDOrAlias(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
device *api.Device,
|
device *api.Device,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
roomIDOrAlias string,
|
roomIDOrAlias string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
// if this is a remote roomIDOrAlias, we have to ask the roomserver (or federation sender?) to
|
// if this is a remote roomIDOrAlias, we have to ask the roomserver (or federation sender?) to
|
||||||
|
|
@ -79,7 +79,7 @@ func PeekRoomByIDOrAlias(
|
||||||
func UnpeekRoomByID(
|
func UnpeekRoomByID(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
device *api.Device,
|
device *api.Device,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
roomID string,
|
roomID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
unpeekReq := roomserverAPI.PerformUnpeekRequest{
|
unpeekReq := roomserverAPI.PerformUnpeekRequest{
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func GetAvatarURL(
|
||||||
// SetAvatarURL implements PUT /profile/{userID}/avatar_url
|
// SetAvatarURL implements PUT /profile/{userID}/avatar_url
|
||||||
func SetAvatarURL(
|
func SetAvatarURL(
|
||||||
req *http.Request, profileAPI userapi.ClientUserAPI,
|
req *http.Request, profileAPI userapi.ClientUserAPI,
|
||||||
device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI,
|
device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if userID != device.UserID {
|
if userID != device.UserID {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
|
|
@ -221,7 +221,7 @@ func GetDisplayName(
|
||||||
// SetDisplayName implements PUT /profile/{userID}/displayname
|
// SetDisplayName implements PUT /profile/{userID}/displayname
|
||||||
func SetDisplayName(
|
func SetDisplayName(
|
||||||
req *http.Request, profileAPI userapi.ClientUserAPI,
|
req *http.Request, profileAPI userapi.ClientUserAPI,
|
||||||
device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI,
|
device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.ClientRoomserverAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if userID != device.UserID {
|
if userID != device.UserID {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
|
|
@ -366,7 +366,7 @@ func buildMembershipEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
roomIDs []string,
|
roomIDs []string,
|
||||||
newProfile authtypes.Profile, userID string, cfg *config.ClientAPI,
|
newProfile authtypes.Profile, userID string, cfg *config.ClientAPI,
|
||||||
evTime time.Time, rsAPI api.RoomserverInternalAPI,
|
evTime time.Time, rsAPI api.ClientRoomserverAPI,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||||
evs := []*gomatrixserverlib.HeaderedEvent{}
|
evs := []*gomatrixserverlib.HeaderedEvent{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ type redactionResponse struct {
|
||||||
|
|
||||||
func SendRedaction(
|
func SendRedaction(
|
||||||
req *http.Request, device *userapi.Device, roomID, eventID string, cfg *config.ClientAPI,
|
req *http.Request, device *userapi.Device, roomID, eventID string, cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
txnID *string,
|
txnID *string,
|
||||||
txnCache *transactions.Cache,
|
txnCache *transactions.Cache,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ import (
|
||||||
func Setup(
|
func Setup(
|
||||||
publicAPIMux, synapseAdminRouter, dendriteAdminRouter *mux.Router,
|
publicAPIMux, synapseAdminRouter, dendriteAdminRouter *mux.Router,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
userAPI userapi.ClientUserAPI,
|
userAPI userapi.ClientUserAPI,
|
||||||
userDirectoryProvider userapi.UserDirectoryProvider,
|
userDirectoryProvider userapi.UserDirectoryProvider,
|
||||||
|
|
@ -58,7 +58,7 @@ func Setup(
|
||||||
syncProducer *producers.SyncAPIProducer,
|
syncProducer *producers.SyncAPIProducer,
|
||||||
transactionsCache *transactions.Cache,
|
transactionsCache *transactions.Cache,
|
||||||
federationSender federationAPI.FederationInternalAPI,
|
federationSender federationAPI.FederationInternalAPI,
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.ClientKeyAPI,
|
||||||
extRoomsProvider api.ExtraPublicRoomsProvider,
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
mscCfg *config.MSCs, natsClient *nats.Conn,
|
mscCfg *config.MSCs, natsClient *nats.Conn,
|
||||||
) {
|
) {
|
||||||
|
|
@ -325,7 +325,7 @@ func Setup(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, federation)
|
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodGet, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodOptions)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func SendEvent(
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
roomID, eventType string, txnID, stateKey *string,
|
roomID, eventType string, txnID, stateKey *string,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
txnCache *transactions.Cache,
|
txnCache *transactions.Cache,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||||
|
|
@ -207,7 +207,7 @@ func generateSendEvent(
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
roomID, eventType string, stateKey *string,
|
roomID, eventType string, stateKey *string,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
evTime time.Time,
|
evTime time.Time,
|
||||||
) (*gomatrixserverlib.Event, *util.JSONResponse) {
|
) (*gomatrixserverlib.Event, *util.JSONResponse) {
|
||||||
// parse the incoming http request
|
// parse the incoming http request
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ type typingContentJSON struct {
|
||||||
// sends the typing events to client API typingProducer
|
// sends the typing events to client API typingProducer
|
||||||
func SendTyping(
|
func SendTyping(
|
||||||
req *http.Request, device *userapi.Device, roomID string,
|
req *http.Request, device *userapi.Device, roomID string,
|
||||||
userID string, rsAPI roomserverAPI.RoomserverInternalAPI,
|
userID string, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
syncProducer *producers.SyncAPIProducer,
|
syncProducer *producers.SyncAPIProducer,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if device.UserID != userID {
|
if device.UserID != userID {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func SendServerNotice(
|
||||||
cfgNotices *config.ServerNotices,
|
cfgNotices *config.ServerNotices,
|
||||||
cfgClient *config.ClientAPI,
|
cfgClient *config.ClientAPI,
|
||||||
userAPI userapi.ClientUserAPI,
|
userAPI userapi.ClientUserAPI,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
senderDevice *userapi.Device,
|
senderDevice *userapi.Device,
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ type stateEventInStateResp struct {
|
||||||
// TODO: Check if the user is in the room. If not, check if the room's history
|
// TODO: Check if the user is in the room. If not, check if the room's history
|
||||||
// is publicly visible. Current behaviour is returning an empty array if the
|
// is publicly visible. Current behaviour is returning an empty array if the
|
||||||
// user cannot see the room's history.
|
// user cannot see the room's history.
|
||||||
func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI api.RoomserverInternalAPI, roomID string) util.JSONResponse {
|
func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI api.ClientRoomserverAPI, roomID string) util.JSONResponse {
|
||||||
var worldReadable bool
|
var worldReadable bool
|
||||||
var wantLatestState bool
|
var wantLatestState bool
|
||||||
|
|
||||||
|
|
@ -162,7 +162,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
|
||||||
// is then (by default) we return the content, otherwise a 404.
|
// is then (by default) we return the content, otherwise a 404.
|
||||||
// If eventFormat=true, sends the whole event else just the content.
|
// If eventFormat=true, sends the whole event else just the content.
|
||||||
func OnIncomingStateTypeRequest(
|
func OnIncomingStateTypeRequest(
|
||||||
ctx context.Context, device *userapi.Device, rsAPI api.RoomserverInternalAPI,
|
ctx context.Context, device *userapi.Device, rsAPI api.ClientRoomserverAPI,
|
||||||
roomID, evType, stateKey string, eventFormat bool,
|
roomID, evType, stateKey string, eventFormat bool,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var worldReadable bool
|
var worldReadable bool
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func UpgradeRoom(
|
||||||
req *http.Request, device *userapi.Device,
|
req *http.Request, device *userapi.Device,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
roomID string, profileAPI userapi.ClientUserAPI,
|
roomID string, profileAPI userapi.ClientUserAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var r upgradeRoomRequest
|
var r upgradeRoomRequest
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func SearchUserDirectory(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
userAPI userapi.ClientUserAPI,
|
userAPI userapi.ClientUserAPI,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
provider userapi.UserDirectoryProvider,
|
provider userapi.UserDirectoryProvider,
|
||||||
serverName gomatrixserverlib.ServerName,
|
serverName gomatrixserverlib.ServerName,
|
||||||
searchString string,
|
searchString string,
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ var (
|
||||||
func CheckAndProcessInvite(
|
func CheckAndProcessInvite(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
device *userapi.Device, body *MembershipRequest, cfg *config.ClientAPI,
|
device *userapi.Device, body *MembershipRequest, cfg *config.ClientAPI,
|
||||||
rsAPI api.RoomserverInternalAPI, db userapi.ClientUserAPI,
|
rsAPI api.ClientRoomserverAPI, db userapi.ClientUserAPI,
|
||||||
roomID string,
|
roomID string,
|
||||||
evTime time.Time,
|
evTime time.Time,
|
||||||
) (inviteStoredOnIDServer bool, err error) {
|
) (inviteStoredOnIDServer bool, err error) {
|
||||||
|
|
@ -337,7 +337,7 @@ func emit3PIDInviteEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
body *MembershipRequest, res *idServerStoreInviteResponse,
|
body *MembershipRequest, res *idServerStoreInviteResponse,
|
||||||
device *userapi.Device, roomID string, cfg *config.ClientAPI,
|
device *userapi.Device, roomID string, cfg *config.ClientAPI,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
evTime time.Time,
|
evTime time.Time,
|
||||||
) error {
|
) error {
|
||||||
builder := &gomatrixserverlib.EventBuilder{
|
builder := &gomatrixserverlib.EventBuilder{
|
||||||
|
|
|
||||||
|
|
@ -166,31 +166,36 @@ func processInvite(
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the invite event to the roomserver.
|
// Add the invite event to the roomserver.
|
||||||
err = api.SendInvite(
|
inviteEvent := signedEvent.Headered(roomVer)
|
||||||
ctx, rsAPI, signedEvent.Headered(roomVer), strippedState, api.DoNotSendToOtherServers, nil,
|
request := &api.PerformInviteRequest{
|
||||||
)
|
Event: inviteEvent,
|
||||||
switch e := err.(type) {
|
InviteRoomState: strippedState,
|
||||||
case *api.PerformError:
|
RoomVersion: inviteEvent.RoomVersion,
|
||||||
return e.JSONResponse()
|
SendAsServer: string(api.DoNotSendToOtherServers),
|
||||||
case nil:
|
TransactionID: nil,
|
||||||
// Return the signed event to the originating server, it should then tell
|
}
|
||||||
// the other servers in the room that we have been invited.
|
response := &api.PerformInviteResponse{}
|
||||||
if isInviteV2 {
|
if err := rsAPI.PerformInvite(ctx, request, response); err != nil {
|
||||||
return util.JSONResponse{
|
util.GetLogger(ctx).WithError(err).Error("PerformInvite failed")
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: gomatrixserverlib.RespInviteV2{Event: signedEvent.JSON()},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: gomatrixserverlib.RespInvite{Event: signedEvent.JSON()},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
util.GetLogger(ctx).WithError(err).Error("api.SendInvite failed")
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusInternalServerError,
|
Code: http.StatusInternalServerError,
|
||||||
JSON: jsonerror.InternalServerError(),
|
JSON: jsonerror.InternalServerError(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if response.Error != nil {
|
||||||
|
return response.Error.JSONResponse()
|
||||||
|
}
|
||||||
|
// Return the signed event to the originating server, it should then tell
|
||||||
|
// the other servers in the room that we have been invited.
|
||||||
|
if isInviteV2 {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: gomatrixserverlib.RespInviteV2{Event: signedEvent.JSON()},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: gomatrixserverlib.RespInvite{Event: signedEvent.JSON()},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ var ErrRoomNoExists = errors.New("room does not exist")
|
||||||
func QueryAndBuildEvent(
|
func QueryAndBuildEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
builder *gomatrixserverlib.EventBuilder, cfg *config.Global, evTime time.Time,
|
builder *gomatrixserverlib.EventBuilder, cfg *config.Global, evTime time.Time,
|
||||||
rsAPI api.RoomserverInternalAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
rsAPI api.QueryLatestEventsAndStateAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*gomatrixserverlib.HeaderedEvent, error) {
|
||||||
if queryRes == nil {
|
if queryRes == nil {
|
||||||
queryRes = &api.QueryLatestEventsAndStateResponse{}
|
queryRes = &api.QueryLatestEventsAndStateResponse{}
|
||||||
|
|
@ -80,7 +80,7 @@ func BuildEvent(
|
||||||
func queryRequiredEventsForBuilder(
|
func queryRequiredEventsForBuilder(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
builder *gomatrixserverlib.EventBuilder,
|
builder *gomatrixserverlib.EventBuilder,
|
||||||
rsAPI api.RoomserverInternalAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
rsAPI api.QueryLatestEventsAndStateAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||||
) (*gomatrixserverlib.StateNeeded, error) {
|
) (*gomatrixserverlib.StateNeeded, error) {
|
||||||
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
|
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -28,21 +28,27 @@ import (
|
||||||
|
|
||||||
type KeyInternalAPI interface {
|
type KeyInternalAPI interface {
|
||||||
SyncKeyAPI
|
SyncKeyAPI
|
||||||
|
ClientKeyAPI
|
||||||
// SetUserAPI assigns a user API to query when extracting device names.
|
// SetUserAPI assigns a user API to query when extracting device names.
|
||||||
SetUserAPI(i userapi.UserInternalAPI)
|
SetUserAPI(i userapi.UserInternalAPI)
|
||||||
// InputDeviceListUpdate from a federated server EDU
|
// InputDeviceListUpdate from a federated server EDU
|
||||||
InputDeviceListUpdate(ctx context.Context, req *InputDeviceListUpdateRequest, res *InputDeviceListUpdateResponse)
|
InputDeviceListUpdate(ctx context.Context, req *InputDeviceListUpdateRequest, res *InputDeviceListUpdateResponse)
|
||||||
PerformUploadKeys(ctx context.Context, req *PerformUploadKeysRequest, res *PerformUploadKeysResponse)
|
|
||||||
// PerformClaimKeys claims one-time keys for use in pre-key messages
|
|
||||||
PerformClaimKeys(ctx context.Context, req *PerformClaimKeysRequest, res *PerformClaimKeysResponse)
|
|
||||||
PerformDeleteKeys(ctx context.Context, req *PerformDeleteKeysRequest, res *PerformDeleteKeysResponse)
|
PerformDeleteKeys(ctx context.Context, req *PerformDeleteKeysRequest, res *PerformDeleteKeysResponse)
|
||||||
PerformUploadDeviceKeys(ctx context.Context, req *PerformUploadDeviceKeysRequest, res *PerformUploadDeviceKeysResponse)
|
|
||||||
PerformUploadDeviceSignatures(ctx context.Context, req *PerformUploadDeviceSignaturesRequest, res *PerformUploadDeviceSignaturesResponse)
|
|
||||||
QueryKeys(ctx context.Context, req *QueryKeysRequest, res *QueryKeysResponse)
|
|
||||||
QueryDeviceMessages(ctx context.Context, req *QueryDeviceMessagesRequest, res *QueryDeviceMessagesResponse)
|
QueryDeviceMessages(ctx context.Context, req *QueryDeviceMessagesRequest, res *QueryDeviceMessagesResponse)
|
||||||
QuerySignatures(ctx context.Context, req *QuerySignaturesRequest, res *QuerySignaturesResponse)
|
QuerySignatures(ctx context.Context, req *QuerySignaturesRequest, res *QuerySignaturesResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// API functions required by the clientapi
|
||||||
|
type ClientKeyAPI interface {
|
||||||
|
QueryKeys(ctx context.Context, req *QueryKeysRequest, res *QueryKeysResponse)
|
||||||
|
PerformUploadKeys(ctx context.Context, req *PerformUploadKeysRequest, res *PerformUploadKeysResponse)
|
||||||
|
PerformUploadDeviceKeys(ctx context.Context, req *PerformUploadDeviceKeysRequest, res *PerformUploadDeviceKeysResponse)
|
||||||
|
PerformUploadDeviceSignatures(ctx context.Context, req *PerformUploadDeviceSignaturesRequest, res *PerformUploadDeviceSignaturesResponse)
|
||||||
|
// PerformClaimKeys claims one-time keys for use in pre-key messages
|
||||||
|
PerformClaimKeys(ctx context.Context, req *PerformClaimKeysRequest, res *PerformClaimKeysResponse)
|
||||||
|
}
|
||||||
|
|
||||||
// API functions required by the syncapi
|
// API functions required by the syncapi
|
||||||
type SyncKeyAPI interface {
|
type SyncKeyAPI interface {
|
||||||
QueryKeyChanges(ctx context.Context, req *QueryKeyChangesRequest, res *QueryKeyChangesResponse)
|
QueryKeyChanges(ctx context.Context, req *QueryKeyChangesRequest, res *QueryKeyChangesResponse)
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,13 @@ import (
|
||||||
|
|
||||||
// RoomserverInputAPI is used to write events to the room server.
|
// RoomserverInputAPI is used to write events to the room server.
|
||||||
type RoomserverInternalAPI interface {
|
type RoomserverInternalAPI interface {
|
||||||
|
InputRoomEventsAPI
|
||||||
|
QueryLatestEventsAndStateAPI
|
||||||
|
QueryEventsAPI
|
||||||
|
|
||||||
SyncRoomserverAPI
|
SyncRoomserverAPI
|
||||||
AppserviceRoomserverAPI
|
AppserviceRoomserverAPI
|
||||||
|
ClientRoomserverAPI
|
||||||
|
|
||||||
// needed to avoid chicken and egg scenario when setting up the
|
// needed to avoid chicken and egg scenario when setting up the
|
||||||
// interdependencies between the roomserver and other input APIs
|
// interdependencies between the roomserver and other input APIs
|
||||||
|
|
@ -21,12 +26,6 @@ type RoomserverInternalAPI interface {
|
||||||
SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI)
|
SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI)
|
||||||
SetUserAPI(userAPI userapi.UserInternalAPI)
|
SetUserAPI(userAPI userapi.UserInternalAPI)
|
||||||
|
|
||||||
InputRoomEvents(
|
|
||||||
ctx context.Context,
|
|
||||||
request *InputRoomEventsRequest,
|
|
||||||
response *InputRoomEventsResponse,
|
|
||||||
)
|
|
||||||
|
|
||||||
PerformInvite(
|
PerformInvite(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *PerformInviteRequest,
|
req *PerformInviteRequest,
|
||||||
|
|
@ -69,12 +68,6 @@ type RoomserverInternalAPI interface {
|
||||||
res *PerformInboundPeekResponse,
|
res *PerformInboundPeekResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
PerformAdminEvacuateRoom(
|
|
||||||
ctx context.Context,
|
|
||||||
req *PerformAdminEvacuateRoomRequest,
|
|
||||||
res *PerformAdminEvacuateRoomResponse,
|
|
||||||
)
|
|
||||||
|
|
||||||
QueryPublishedRooms(
|
QueryPublishedRooms(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *QueryPublishedRoomsRequest,
|
req *QueryPublishedRoomsRequest,
|
||||||
|
|
@ -84,22 +77,22 @@ type RoomserverInternalAPI interface {
|
||||||
// Query if we think we're still in a room.
|
// Query if we think we're still in a room.
|
||||||
QueryServerJoinedToRoom(
|
QueryServerJoinedToRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryServerJoinedToRoomRequest,
|
req *QueryServerJoinedToRoomRequest,
|
||||||
response *QueryServerJoinedToRoomResponse,
|
res *QueryServerJoinedToRoomResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Query whether a server is allowed to see an event
|
// Query whether a server is allowed to see an event
|
||||||
QueryServerAllowedToSeeEvent(
|
QueryServerAllowedToSeeEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryServerAllowedToSeeEventRequest,
|
req *QueryServerAllowedToSeeEventRequest,
|
||||||
response *QueryServerAllowedToSeeEventResponse,
|
res *QueryServerAllowedToSeeEventResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Query missing events for a room from roomserver
|
// Query missing events for a room from roomserver
|
||||||
QueryMissingEvents(
|
QueryMissingEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryMissingEventsRequest,
|
req *QueryMissingEventsRequest,
|
||||||
response *QueryMissingEventsResponse,
|
res *QueryMissingEventsResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Query to get state and auth chain for a (potentially hypothetical) event.
|
// Query to get state and auth chain for a (potentially hypothetical) event.
|
||||||
|
|
@ -107,8 +100,8 @@ type RoomserverInternalAPI interface {
|
||||||
// the state and auth chain to return.
|
// the state and auth chain to return.
|
||||||
QueryStateAndAuthChain(
|
QueryStateAndAuthChain(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryStateAndAuthChainRequest,
|
req *QueryStateAndAuthChainRequest,
|
||||||
response *QueryStateAndAuthChainResponse,
|
res *QueryStateAndAuthChainResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// QueryAuthChain returns the entire auth chain for the event IDs given.
|
// QueryAuthChain returns the entire auth chain for the event IDs given.
|
||||||
|
|
@ -116,106 +109,122 @@ type RoomserverInternalAPI interface {
|
||||||
// Omits without error for any missing auth events. There will be no duplicates.
|
// Omits without error for any missing auth events. There will be no duplicates.
|
||||||
QueryAuthChain(
|
QueryAuthChain(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryAuthChainRequest,
|
req *QueryAuthChainRequest,
|
||||||
response *QueryAuthChainResponse,
|
res *QueryAuthChainResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// QueryCurrentState retrieves the requested state events. If state events are not found, they will be missing from
|
|
||||||
// the response.
|
|
||||||
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
|
||||||
// QueryRoomsForUser retrieves a list of room IDs matching the given query.
|
// QueryRoomsForUser retrieves a list of room IDs matching the given query.
|
||||||
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
|
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
|
||||||
// QueryKnownUsers returns a list of users that we know about from our joined rooms.
|
|
||||||
QueryKnownUsers(ctx context.Context, req *QueryKnownUsersRequest, res *QueryKnownUsersResponse) error
|
|
||||||
// QueryServerBannedFromRoom returns whether a server is banned from a room by server ACLs.
|
// QueryServerBannedFromRoom returns whether a server is banned from a room by server ACLs.
|
||||||
QueryServerBannedFromRoom(ctx context.Context, req *QueryServerBannedFromRoomRequest, res *QueryServerBannedFromRoomResponse) error
|
QueryServerBannedFromRoom(ctx context.Context, req *QueryServerBannedFromRoomRequest, res *QueryServerBannedFromRoomResponse) error
|
||||||
|
|
||||||
// PerformForget forgets a rooms history for a specific user
|
|
||||||
PerformForget(ctx context.Context, req *PerformForgetRequest, resp *PerformForgetResponse) 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)
|
||||||
|
|
||||||
// Asks for the default room version as preferred by the server.
|
// Asks for the default room version as preferred by the server.
|
||||||
QueryRoomVersionCapabilities(
|
QueryRoomVersionCapabilities(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryRoomVersionCapabilitiesRequest,
|
req *QueryRoomVersionCapabilitiesRequest,
|
||||||
response *QueryRoomVersionCapabilitiesResponse,
|
res *QueryRoomVersionCapabilitiesResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Asks for the room version for a given room.
|
// Asks for the room version for a given room.
|
||||||
QueryRoomVersionForRoom(
|
QueryRoomVersionForRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryRoomVersionForRoomRequest,
|
req *QueryRoomVersionForRoomRequest,
|
||||||
response *QueryRoomVersionForRoomResponse,
|
res *QueryRoomVersionForRoomResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Set a room alias
|
// Set a room alias
|
||||||
SetRoomAlias(
|
SetRoomAlias(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *SetRoomAliasRequest,
|
req *SetRoomAliasRequest,
|
||||||
response *SetRoomAliasResponse,
|
res *SetRoomAliasResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Get the room ID for an alias
|
// Get the room ID for an alias
|
||||||
GetRoomIDForAlias(
|
GetRoomIDForAlias(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *GetRoomIDForAliasRequest,
|
req *GetRoomIDForAliasRequest,
|
||||||
response *GetRoomIDForAliasResponse,
|
res *GetRoomIDForAliasResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Get the user ID of the creator of an alias
|
// Get the user ID of the creator of an alias
|
||||||
GetCreatorIDForAlias(
|
GetCreatorIDForAlias(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *GetCreatorIDForAliasRequest,
|
req *GetCreatorIDForAliasRequest,
|
||||||
response *GetCreatorIDForAliasResponse,
|
res *GetCreatorIDForAliasResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Remove a room alias
|
// Remove a room alias
|
||||||
RemoveRoomAlias(
|
RemoveRoomAlias(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *RemoveRoomAliasRequest,
|
req *RemoveRoomAliasRequest,
|
||||||
response *RemoveRoomAliasResponse,
|
res *RemoveRoomAliasResponse,
|
||||||
) error
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InputRoomEventsAPI interface {
|
||||||
|
InputRoomEvents(
|
||||||
|
ctx context.Context,
|
||||||
|
req *InputRoomEventsRequest,
|
||||||
|
res *InputRoomEventsResponse,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query the latest events and state for a room from the room server.
|
||||||
|
type QueryLatestEventsAndStateAPI interface {
|
||||||
|
QueryLatestEventsAndState(ctx context.Context, req *QueryLatestEventsAndStateRequest, res *QueryLatestEventsAndStateResponse) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBulkStateContent does a bulk query for state event content in the given rooms.
|
||||||
|
type QueryBulkStateContentAPI interface {
|
||||||
|
QueryBulkStateContent(ctx context.Context, req *QueryBulkStateContentRequest, res *QueryBulkStateContentResponse) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryEventsAPI interface {
|
||||||
|
// Query a list of events by event ID.
|
||||||
|
QueryEventsByID(
|
||||||
|
ctx context.Context,
|
||||||
|
req *QueryEventsByIDRequest,
|
||||||
|
res *QueryEventsByIDResponse,
|
||||||
|
) error
|
||||||
|
// QueryCurrentState retrieves the requested state events. If state events are not found, they will be missing from
|
||||||
|
// the response.
|
||||||
|
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
||||||
|
}
|
||||||
|
|
||||||
// API functions required by the syncapi
|
// API functions required by the syncapi
|
||||||
type SyncRoomserverAPI interface {
|
type SyncRoomserverAPI interface {
|
||||||
// Query the latest events and state for a room from the room server.
|
QueryLatestEventsAndStateAPI
|
||||||
QueryLatestEventsAndState(
|
QueryBulkStateContentAPI
|
||||||
ctx context.Context,
|
|
||||||
request *QueryLatestEventsAndStateRequest,
|
|
||||||
response *QueryLatestEventsAndStateResponse,
|
|
||||||
) error
|
|
||||||
// QueryBulkStateContent does a bulk query for state event content in the given rooms.
|
|
||||||
QueryBulkStateContent(ctx context.Context, req *QueryBulkStateContentRequest, res *QueryBulkStateContentResponse) error
|
|
||||||
// QuerySharedUsers returns a list of users who share at least 1 room in common with the given user.
|
// QuerySharedUsers returns a list of users who share at least 1 room in common with the given user.
|
||||||
QuerySharedUsers(ctx context.Context, req *QuerySharedUsersRequest, res *QuerySharedUsersResponse) error
|
QuerySharedUsers(ctx context.Context, req *QuerySharedUsersRequest, res *QuerySharedUsersResponse) error
|
||||||
// Query a list of events by event ID.
|
// Query a list of events by event ID.
|
||||||
QueryEventsByID(
|
QueryEventsByID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryEventsByIDRequest,
|
req *QueryEventsByIDRequest,
|
||||||
response *QueryEventsByIDResponse,
|
res *QueryEventsByIDResponse,
|
||||||
) error
|
) error
|
||||||
// Query the membership event for an user for a room.
|
// Query the membership event for an user for a room.
|
||||||
QueryMembershipForUser(
|
QueryMembershipForUser(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryMembershipForUserRequest,
|
req *QueryMembershipForUserRequest,
|
||||||
response *QueryMembershipForUserResponse,
|
res *QueryMembershipForUserResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Query the state after a list of events in a room from the room server.
|
// Query the state after a list of events in a room from the room server.
|
||||||
QueryStateAfterEvents(
|
QueryStateAfterEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryStateAfterEventsRequest,
|
req *QueryStateAfterEventsRequest,
|
||||||
response *QueryStateAfterEventsResponse,
|
res *QueryStateAfterEventsResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Query a given amount (or less) of events prior to a given set of events.
|
// Query a given amount (or less) of events prior to a given set of events.
|
||||||
PerformBackfill(
|
PerformBackfill(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *PerformBackfillRequest,
|
req *PerformBackfillRequest,
|
||||||
response *PerformBackfillResponse,
|
res *PerformBackfillResponse,
|
||||||
) error
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,19 +232,56 @@ type AppserviceRoomserverAPI interface {
|
||||||
// Query a list of events by event ID.
|
// Query a list of events by event ID.
|
||||||
QueryEventsByID(
|
QueryEventsByID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryEventsByIDRequest,
|
req *QueryEventsByIDRequest,
|
||||||
response *QueryEventsByIDResponse,
|
res *QueryEventsByIDResponse,
|
||||||
) error
|
) error
|
||||||
// Query a list of membership events for a room
|
// Query a list of membership events for a room
|
||||||
QueryMembershipsForRoom(
|
QueryMembershipsForRoom(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryMembershipsForRoomRequest,
|
req *QueryMembershipsForRoomRequest,
|
||||||
response *QueryMembershipsForRoomResponse,
|
res *QueryMembershipsForRoomResponse,
|
||||||
) error
|
) error
|
||||||
// Get all known aliases for a room ID
|
// Get all known aliases for a room ID
|
||||||
GetAliasesForRoomID(
|
GetAliasesForRoomID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *GetAliasesForRoomIDRequest,
|
req *GetAliasesForRoomIDRequest,
|
||||||
response *GetAliasesForRoomIDResponse,
|
res *GetAliasesForRoomIDResponse,
|
||||||
) error
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClientRoomserverAPI interface {
|
||||||
|
InputRoomEventsAPI
|
||||||
|
QueryLatestEventsAndStateAPI
|
||||||
|
QueryBulkStateContentAPI
|
||||||
|
QueryEventsAPI
|
||||||
|
QueryMembershipForUser(ctx context.Context, req *QueryMembershipForUserRequest, res *QueryMembershipForUserResponse) error
|
||||||
|
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
||||||
|
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
|
||||||
|
QueryStateAfterEvents(ctx context.Context, req *QueryStateAfterEventsRequest, res *QueryStateAfterEventsResponse) error
|
||||||
|
// QueryKnownUsers returns a list of users that we know about from our joined rooms.
|
||||||
|
QueryKnownUsers(ctx context.Context, req *QueryKnownUsersRequest, res *QueryKnownUsersResponse) error
|
||||||
|
QueryRoomVersionForRoom(ctx context.Context, req *QueryRoomVersionForRoomRequest, res *QueryRoomVersionForRoomResponse) error
|
||||||
|
QueryPublishedRooms(ctx context.Context, req *QueryPublishedRoomsRequest, res *QueryPublishedRoomsResponse) error
|
||||||
|
QueryRoomVersionCapabilities(ctx context.Context, req *QueryRoomVersionCapabilitiesRequest, res *QueryRoomVersionCapabilitiesResponse) error
|
||||||
|
|
||||||
|
GetRoomIDForAlias(ctx context.Context, req *GetRoomIDForAliasRequest, res *GetRoomIDForAliasResponse) error
|
||||||
|
GetAliasesForRoomID(ctx context.Context, req *GetAliasesForRoomIDRequest, res *GetAliasesForRoomIDResponse) error
|
||||||
|
|
||||||
|
// PerformRoomUpgrade upgrades a room to a newer version
|
||||||
|
PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse)
|
||||||
|
PerformAdminEvacuateRoom(
|
||||||
|
ctx context.Context,
|
||||||
|
req *PerformAdminEvacuateRoomRequest,
|
||||||
|
res *PerformAdminEvacuateRoomResponse,
|
||||||
|
)
|
||||||
|
PerformPeek(ctx context.Context, req *PerformPeekRequest, res *PerformPeekResponse)
|
||||||
|
PerformUnpeek(ctx context.Context, req *PerformUnpeekRequest, res *PerformUnpeekResponse)
|
||||||
|
PerformInvite(ctx context.Context, req *PerformInviteRequest, res *PerformInviteResponse) error
|
||||||
|
PerformJoin(ctx context.Context, req *PerformJoinRequest, res *PerformJoinResponse)
|
||||||
|
PerformLeave(ctx context.Context, req *PerformLeaveRequest, res *PerformLeaveResponse) error
|
||||||
|
PerformPublish(ctx context.Context, req *PerformPublishRequest, res *PerformPublishResponse)
|
||||||
|
// PerformForget forgets a rooms history for a specific user
|
||||||
|
PerformForget(ctx context.Context, req *PerformForgetRequest, resp *PerformForgetResponse) error
|
||||||
|
SetRoomAlias(ctx context.Context, req *SetRoomAliasRequest, res *SetRoomAliasResponse) error
|
||||||
|
RemoveRoomAlias(ctx context.Context, req *RemoveRoomAliasRequest, res *RemoveRoomAliasResponse) error
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
@ -24,7 +23,7 @@ import (
|
||||||
|
|
||||||
// SendEvents to the roomserver The events are written with KindNew.
|
// SendEvents to the roomserver The events are written with KindNew.
|
||||||
func SendEvents(
|
func SendEvents(
|
||||||
ctx context.Context, rsAPI RoomserverInternalAPI,
|
ctx context.Context, rsAPI InputRoomEventsAPI,
|
||||||
kind Kind, events []*gomatrixserverlib.HeaderedEvent,
|
kind Kind, events []*gomatrixserverlib.HeaderedEvent,
|
||||||
origin gomatrixserverlib.ServerName,
|
origin gomatrixserverlib.ServerName,
|
||||||
sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID,
|
sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID,
|
||||||
|
|
@ -47,7 +46,7 @@ func SendEvents(
|
||||||
// with the state at the event as KindOutlier before it. Will not send any event that is
|
// with the state at the event as KindOutlier before it. Will not send any event that is
|
||||||
// marked as `true` in haveEventIDs.
|
// marked as `true` in haveEventIDs.
|
||||||
func SendEventWithState(
|
func SendEventWithState(
|
||||||
ctx context.Context, rsAPI RoomserverInternalAPI, kind Kind,
|
ctx context.Context, rsAPI InputRoomEventsAPI, kind Kind,
|
||||||
state *gomatrixserverlib.RespState, event *gomatrixserverlib.HeaderedEvent,
|
state *gomatrixserverlib.RespState, event *gomatrixserverlib.HeaderedEvent,
|
||||||
origin gomatrixserverlib.ServerName, haveEventIDs map[string]bool, async bool,
|
origin gomatrixserverlib.ServerName, haveEventIDs map[string]bool, async bool,
|
||||||
) error {
|
) error {
|
||||||
|
|
@ -83,7 +82,7 @@ func SendEventWithState(
|
||||||
|
|
||||||
// SendInputRoomEvents to the roomserver.
|
// SendInputRoomEvents to the roomserver.
|
||||||
func SendInputRoomEvents(
|
func SendInputRoomEvents(
|
||||||
ctx context.Context, rsAPI RoomserverInternalAPI,
|
ctx context.Context, rsAPI InputRoomEventsAPI,
|
||||||
ires []InputRoomEvent, async bool,
|
ires []InputRoomEvent, async bool,
|
||||||
) error {
|
) error {
|
||||||
request := InputRoomEventsRequest{
|
request := InputRoomEventsRequest{
|
||||||
|
|
@ -95,37 +94,8 @@ func SendInputRoomEvents(
|
||||||
return response.Err()
|
return response.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendInvite event to the roomserver.
|
|
||||||
// This should only be needed for invite events that occur outside of a known room.
|
|
||||||
// If we are in the room then the event should be sent using the SendEvents method.
|
|
||||||
func SendInvite(
|
|
||||||
ctx context.Context,
|
|
||||||
rsAPI RoomserverInternalAPI, inviteEvent *gomatrixserverlib.HeaderedEvent,
|
|
||||||
inviteRoomState []gomatrixserverlib.InviteV2StrippedState,
|
|
||||||
sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID,
|
|
||||||
) error {
|
|
||||||
// Start by sending the invite request into the roomserver. This will
|
|
||||||
// trigger the federation request amongst other things if needed.
|
|
||||||
request := &PerformInviteRequest{
|
|
||||||
Event: inviteEvent,
|
|
||||||
InviteRoomState: inviteRoomState,
|
|
||||||
RoomVersion: inviteEvent.RoomVersion,
|
|
||||||
SendAsServer: string(sendAsServer),
|
|
||||||
TransactionID: txnID,
|
|
||||||
}
|
|
||||||
response := &PerformInviteResponse{}
|
|
||||||
if err := rsAPI.PerformInvite(ctx, request, response); err != nil {
|
|
||||||
return fmt.Errorf("rsAPI.PerformInvite: %w", err)
|
|
||||||
}
|
|
||||||
if response.Error != nil {
|
|
||||||
return response.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetEvent returns the event or nil, even on errors.
|
// GetEvent returns the event or nil, even on errors.
|
||||||
func GetEvent(ctx context.Context, rsAPI RoomserverInternalAPI, eventID string) *gomatrixserverlib.HeaderedEvent {
|
func GetEvent(ctx context.Context, rsAPI QueryEventsAPI, eventID string) *gomatrixserverlib.HeaderedEvent {
|
||||||
var res QueryEventsByIDResponse
|
var res QueryEventsByIDResponse
|
||||||
err := rsAPI.QueryEventsByID(ctx, &QueryEventsByIDRequest{
|
err := rsAPI.QueryEventsByID(ctx, &QueryEventsByIDRequest{
|
||||||
EventIDs: []string{eventID},
|
EventIDs: []string{eventID},
|
||||||
|
|
@ -141,7 +111,7 @@ func GetEvent(ctx context.Context, rsAPI RoomserverInternalAPI, eventID string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStateEvent returns the current state event in the room or nil.
|
// GetStateEvent returns the current state event in the room or nil.
|
||||||
func GetStateEvent(ctx context.Context, rsAPI RoomserverInternalAPI, roomID string, tuple gomatrixserverlib.StateKeyTuple) *gomatrixserverlib.HeaderedEvent {
|
func GetStateEvent(ctx context.Context, rsAPI QueryEventsAPI, roomID string, tuple gomatrixserverlib.StateKeyTuple) *gomatrixserverlib.HeaderedEvent {
|
||||||
var res QueryCurrentStateResponse
|
var res QueryCurrentStateResponse
|
||||||
err := rsAPI.QueryCurrentState(ctx, &QueryCurrentStateRequest{
|
err := rsAPI.QueryCurrentState(ctx, &QueryCurrentStateRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
|
|
@ -175,7 +145,7 @@ func IsServerBannedFromRoom(ctx context.Context, rsAPI RoomserverInternalAPI, ro
|
||||||
// PopulatePublicRooms extracts PublicRoom information for all the provided room IDs. The IDs are not checked to see if they are visible in the
|
// PopulatePublicRooms extracts PublicRoom information for all the provided room IDs. The IDs are not checked to see if they are visible in the
|
||||||
// published room directory.
|
// published room directory.
|
||||||
// due to lots of switches
|
// due to lots of switches
|
||||||
func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI RoomserverInternalAPI) ([]gomatrixserverlib.PublicRoom, error) {
|
func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkStateContentAPI) ([]gomatrixserverlib.PublicRoom, error) {
|
||||||
avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
|
avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
|
||||||
nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
|
nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
|
||||||
canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
|
canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue