mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-25 13:11:37 +00:00
Miscellaneous fixes (#1060)
* Add missing routing for PerformDirectoryLookupRequest * Tweak output * Fix some bugs in devices * Don't default to federated room joins in response to invite * Update sytest-whitelist * Update comments * Return correct room ID from PerformJoin * Fix appservice and EDU server API setup, update sytest-whitelist * Update sytest-whitelist
This commit is contained in:
parent
492af0f2ec
commit
6d50212f29
@ -82,9 +82,7 @@ func SetupAppServiceAPIComponent(
|
|||||||
Cfg: base.Cfg,
|
Cfg: base.Cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
if base.EnableHTTPAPIs {
|
appserviceQueryAPI.SetupHTTP(base.InternalAPIMux)
|
||||||
appserviceQueryAPI.SetupHTTP(http.DefaultServeMux)
|
|
||||||
}
|
|
||||||
|
|
||||||
consumer := consumers.NewOutputRoomEventConsumer(
|
consumer := consumers.NewOutputRoomEventConsumer(
|
||||||
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
|
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/appservice/api"
|
"github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/config"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
@ -182,8 +183,8 @@ func makeHTTPClient() *http.Client {
|
|||||||
|
|
||||||
// SetupHTTP adds the AppServiceQueryPAI handlers to the http.ServeMux. This
|
// SetupHTTP adds the AppServiceQueryPAI handlers to the http.ServeMux. This
|
||||||
// handles and muxes incoming api requests the to internal AppServiceQueryAPI.
|
// handles and muxes incoming api requests the to internal AppServiceQueryAPI.
|
||||||
func (a *AppServiceQueryAPI) SetupHTTP(servMux *http.ServeMux) {
|
func (a *AppServiceQueryAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
||||||
servMux.Handle(
|
internalAPIMux.Handle(
|
||||||
api.AppServiceRoomAliasExistsPath,
|
api.AppServiceRoomAliasExistsPath,
|
||||||
internal.MakeInternalAPI("appserviceRoomAliasExists", func(req *http.Request) util.JSONResponse {
|
internal.MakeInternalAPI("appserviceRoomAliasExists", func(req *http.Request) util.JSONResponse {
|
||||||
var request api.RoomAliasExistsRequest
|
var request api.RoomAliasExistsRequest
|
||||||
@ -197,7 +198,7 @@ func (a *AppServiceQueryAPI) SetupHTTP(servMux *http.ServeMux) {
|
|||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
servMux.Handle(
|
internalAPIMux.Handle(
|
||||||
api.AppServiceUserIDExistsPath,
|
api.AppServiceUserIDExistsPath,
|
||||||
internal.MakeInternalAPI("appserviceUserIDExists", func(req *http.Request) util.JSONResponse {
|
internal.MakeInternalAPI("appserviceUserIDExists", func(req *http.Request) util.JSONResponse {
|
||||||
var request api.UserIDExistsRequest
|
var request api.UserIDExistsRequest
|
||||||
|
@ -206,9 +206,8 @@ func (s *devicesStatements) selectDeviceByID(
|
|||||||
ctx context.Context, localpart, deviceID string,
|
ctx context.Context, localpart, deviceID string,
|
||||||
) (*authtypes.Device, error) {
|
) (*authtypes.Device, error) {
|
||||||
var dev authtypes.Device
|
var dev authtypes.Device
|
||||||
var created sql.NullInt64
|
|
||||||
stmt := s.selectDeviceByIDStmt
|
stmt := s.selectDeviceByIDStmt
|
||||||
err := stmt.QueryRowContext(ctx, localpart, deviceID).Scan(&created)
|
err := stmt.QueryRowContext(ctx, localpart, deviceID).Scan(&dev.DisplayName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dev.ID = deviceID
|
dev.ID = deviceID
|
||||||
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
||||||
@ -230,10 +229,17 @@ func (s *devicesStatements) selectDevicesByLocalpart(
|
|||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var dev authtypes.Device
|
var dev authtypes.Device
|
||||||
err = rows.Scan(&dev.ID, &dev.DisplayName)
|
var id, displayname sql.NullString
|
||||||
|
err = rows.Scan(&id, &displayname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return devices, err
|
return devices, err
|
||||||
}
|
}
|
||||||
|
if id.Valid {
|
||||||
|
dev.ID = id.String
|
||||||
|
}
|
||||||
|
if displayname.Valid {
|
||||||
|
dev.DisplayName = displayname.String
|
||||||
|
}
|
||||||
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
||||||
devices = append(devices, dev)
|
devices = append(devices, dev)
|
||||||
}
|
}
|
||||||
|
@ -208,9 +208,8 @@ func (s *devicesStatements) selectDeviceByID(
|
|||||||
ctx context.Context, localpart, deviceID string,
|
ctx context.Context, localpart, deviceID string,
|
||||||
) (*authtypes.Device, error) {
|
) (*authtypes.Device, error) {
|
||||||
var dev authtypes.Device
|
var dev authtypes.Device
|
||||||
var created sql.NullInt64
|
|
||||||
stmt := s.selectDeviceByIDStmt
|
stmt := s.selectDeviceByIDStmt
|
||||||
err := stmt.QueryRowContext(ctx, localpart, deviceID).Scan(&created)
|
err := stmt.QueryRowContext(ctx, localpart, deviceID).Scan(&dev.DisplayName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dev.ID = deviceID
|
dev.ID = deviceID
|
||||||
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
||||||
@ -231,10 +230,17 @@ func (s *devicesStatements) selectDevicesByLocalpart(
|
|||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var dev authtypes.Device
|
var dev authtypes.Device
|
||||||
err = rows.Scan(&dev.ID, &dev.DisplayName)
|
var id, displayname sql.NullString
|
||||||
|
err = rows.Scan(&id, &displayname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return devices, err
|
return devices, err
|
||||||
}
|
}
|
||||||
|
if id.Valid {
|
||||||
|
dev.ID = id.String
|
||||||
|
}
|
||||||
|
if displayname.Valid {
|
||||||
|
dev.DisplayName = displayname.String
|
||||||
|
}
|
||||||
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
|
||||||
devices = append(devices, dev)
|
devices = append(devices, dev)
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,6 @@ func JoinRoomByIDOrAlias(
|
|||||||
// TODO: Put the response struct somewhere internal.
|
// TODO: Put the response struct somewhere internal.
|
||||||
JSON: struct {
|
JSON: struct {
|
||||||
RoomID string `json:"room_id"`
|
RoomID string `json:"room_id"`
|
||||||
}{joinReq.RoomIDOrAlias},
|
}{joinRes.RoomID},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
package eduserver
|
package eduserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/eduserver/api"
|
"github.com/matrix-org/dendrite/eduserver/api"
|
||||||
"github.com/matrix-org/dendrite/eduserver/cache"
|
"github.com/matrix-org/dendrite/eduserver/cache"
|
||||||
"github.com/matrix-org/dendrite/eduserver/input"
|
"github.com/matrix-org/dendrite/eduserver/input"
|
||||||
@ -35,9 +33,7 @@ func SetupEDUServerComponent(
|
|||||||
OutputTypingEventTopic: string(base.Cfg.Kafka.Topics.OutputTypingEvent),
|
OutputTypingEventTopic: string(base.Cfg.Kafka.Topics.OutputTypingEvent),
|
||||||
}
|
}
|
||||||
|
|
||||||
if base.EnableHTTPAPIs {
|
inputAPI.SetupHTTP(base.InternalAPIMux)
|
||||||
inputAPI.SetupHTTP(http.DefaultServeMux)
|
|
||||||
}
|
|
||||||
|
|
||||||
return inputAPI
|
return inputAPI
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Shopify/sarama"
|
"github.com/Shopify/sarama"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/eduserver/api"
|
"github.com/matrix-org/dendrite/eduserver/api"
|
||||||
"github.com/matrix-org/dendrite/eduserver/cache"
|
"github.com/matrix-org/dendrite/eduserver/cache"
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
@ -90,8 +91,8 @@ func (t *EDUServerInputAPI) sendEvent(ite *api.InputTypingEvent) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetupHTTP adds the EDUServerInputAPI handlers to the http.ServeMux.
|
// SetupHTTP adds the EDUServerInputAPI handlers to the http.ServeMux.
|
||||||
func (t *EDUServerInputAPI) SetupHTTP(servMux *http.ServeMux) {
|
func (t *EDUServerInputAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
||||||
servMux.Handle(api.EDUServerInputTypingEventPath,
|
internalAPIMux.Handle(api.EDUServerInputTypingEventPath,
|
||||||
internal.MakeInternalAPI("inputTypingEvents", func(req *http.Request) util.JSONResponse {
|
internal.MakeInternalAPI("inputTypingEvents", func(req *http.Request) util.JSONResponse {
|
||||||
var request api.InputTypingEventRequest
|
var request api.InputTypingEventRequest
|
||||||
var response api.InputTypingEventResponse
|
var response api.InputTypingEventResponse
|
||||||
|
@ -99,4 +99,17 @@ func (f *FederationSenderInternalAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
|||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
internalAPIMux.Handle(api.FederationSenderPerformDirectoryLookupRequestPath,
|
||||||
|
internal.MakeInternalAPI("PerformDirectoryLookupRequest", func(req *http.Request) util.JSONResponse {
|
||||||
|
var request api.PerformDirectoryLookupRequest
|
||||||
|
var response api.PerformDirectoryLookupResponse
|
||||||
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
if err := f.PerformDirectoryLookup(req.Context(), &request, &response); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ func PostJSON(
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
if msgerr := json.NewDecoder(res.Body).Decode(&errorBody); msgerr == nil {
|
if msgerr := json.NewDecoder(res.Body).Decode(&errorBody); msgerr == nil {
|
||||||
return fmt.Errorf("api: %d from %s: %s", res.StatusCode, apiURL, errorBody.Message)
|
return fmt.Errorf("Internal API: %d from %s: %s", res.StatusCode, apiURL, errorBody.Message)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("api: %d from %s", res.StatusCode, apiURL)
|
return fmt.Errorf("Internal API: %d from %s", res.StatusCode, apiURL)
|
||||||
}
|
}
|
||||||
return json.NewDecoder(res.Body).Decode(response)
|
return json.NewDecoder(res.Body).Decode(response)
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ type PerformJoinRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PerformJoinResponse struct {
|
type PerformJoinResponse struct {
|
||||||
|
RoomID string `json:"room_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpRoomserverInternalAPI) PerformJoin(
|
func (h *httpRoomserverInternalAPI) PerformJoin(
|
||||||
|
@ -90,6 +90,12 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
|||||||
req *api.PerformJoinRequest,
|
req *api.PerformJoinRequest,
|
||||||
res *api.PerformJoinResponse, // nolint:unparam
|
res *api.PerformJoinResponse, // nolint:unparam
|
||||||
) error {
|
) error {
|
||||||
|
// By this point, if req.RoomIDOrAlias contained an alias, then
|
||||||
|
// it will have been overwritten with a room ID by performJoinRoomByAlias.
|
||||||
|
// We should now include this in the response so that the CS API can
|
||||||
|
// return the right room ID.
|
||||||
|
res.RoomID = req.RoomIDOrAlias
|
||||||
|
|
||||||
// Get the domain part of the room ID.
|
// Get the domain part of the room ID.
|
||||||
_, domain, err := gomatrixserverlib.SplitID('!', req.RoomIDOrAlias)
|
_, domain, err := gomatrixserverlib.SplitID('!', req.RoomIDOrAlias)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,20 +127,30 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
|||||||
return fmt.Errorf("eb.SetContent: %w", err)
|
return fmt.Errorf("eb.SetContent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// First work out if this is in response to an existing invite.
|
// First work out if this is in response to an existing invite
|
||||||
// If it is then we avoid the situation where we might think we
|
// from a federated server. If it is then we avoid the situation
|
||||||
// know about a room in the following section but don't know the
|
// where we might think we know about a room in the following
|
||||||
// latest state as all of our users have left.
|
// section but don't know the latest state as all of our users
|
||||||
|
// have left.
|
||||||
isInvitePending, inviteSender, err := r.isInvitePending(ctx, req.RoomIDOrAlias, req.UserID)
|
isInvitePending, inviteSender, err := r.isInvitePending(ctx, req.RoomIDOrAlias, req.UserID)
|
||||||
if err == nil && isInvitePending {
|
if err == nil && isInvitePending {
|
||||||
// Add the server of the person who invited us to the server list,
|
// Check if there's an invite pending.
|
||||||
// as they should be a fairly good bet.
|
_, inviterDomain, ierr := gomatrixserverlib.SplitID('@', inviteSender)
|
||||||
if _, inviterDomain, ierr := gomatrixserverlib.SplitID('@', inviteSender); ierr == nil {
|
if ierr != nil {
|
||||||
req.ServerNames = append(req.ServerNames, inviterDomain)
|
return fmt.Errorf("gomatrixserverlib.SplitID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform a federated room join.
|
// Check that the domain isn't ours. If it's local then we don't
|
||||||
return r.performFederatedJoinRoomByID(ctx, req, res)
|
// need to do anything as our own copy of the room state will be
|
||||||
|
// up-to-date.
|
||||||
|
if inviterDomain != r.Cfg.Matrix.ServerName {
|
||||||
|
// Add the server of the person who invited us to the server list,
|
||||||
|
// as they should be a fairly good bet.
|
||||||
|
req.ServerNames = append(req.ServerNames, inviterDomain)
|
||||||
|
|
||||||
|
// Perform a federated room join.
|
||||||
|
return r.performFederatedJoinRoomByID(ctx, req, res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to construct an actual join event from the template.
|
// Try to construct an actual join event from the template.
|
||||||
|
@ -288,3 +288,4 @@ New room members see their own join event
|
|||||||
Existing members see new members' join events
|
Existing members see new members' join events
|
||||||
Inbound federation can receive events
|
Inbound federation can receive events
|
||||||
Inbound federation can receive redacted events
|
Inbound federation can receive redacted events
|
||||||
|
Can logout current device
|
||||||
|
Loading…
Reference in New Issue
Block a user