mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 21:12:45 +00:00
Move MakeJoin logic to GMSL (#3081)
This commit is contained in:
parent
0489d16f95
commit
67d6876857
80 changed files with 1158 additions and 494 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
asAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||
fsAPI "github.com/matrix-org/dendrite/federationapi/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
|
@ -224,6 +225,12 @@ type FederationRoomserverAPI interface {
|
|||
PerformInvite(ctx context.Context, req *PerformInviteRequest) error
|
||||
// Query a given amount (or less) of events prior to a given set of events.
|
||||
PerformBackfill(ctx context.Context, req *PerformBackfillRequest, res *PerformBackfillResponse) error
|
||||
|
||||
CurrentStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (gomatrixserverlib.PDU, error)
|
||||
InvitePending(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (bool, error)
|
||||
QueryRoomInfo(ctx context.Context, roomID spec.RoomID) (*types.RoomInfo, error)
|
||||
UserJoinedToRoom(ctx context.Context, roomID types.RoomNID, userID spec.UserID) (bool, error)
|
||||
LocallyJoinedUsers(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, roomNID types.RoomNID) ([]gomatrixserverlib.PDU, error)
|
||||
}
|
||||
|
||||
type KeyserverRoomserverAPI interface {
|
||||
|
|
|
@ -52,7 +52,7 @@ func (r *Admin) PerformAdminEvacuateRoom(
|
|||
return nil, err
|
||||
}
|
||||
if roomInfo == nil || roomInfo.IsStub() {
|
||||
return nil, eventutil.ErrRoomNoExists
|
||||
return nil, eventutil.ErrRoomNoExists{}
|
||||
}
|
||||
|
||||
memberNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
|
||||
|
@ -240,7 +240,7 @@ func (r *Admin) PerformAdminDownloadState(
|
|||
}
|
||||
|
||||
if roomInfo == nil || roomInfo.IsStub() {
|
||||
return eventutil.ErrRoomNoExists
|
||||
return eventutil.ErrRoomNoExists{}
|
||||
}
|
||||
|
||||
fwdExtremities, _, depth, err := r.DB.LatestEventIDs(ctx, roomInfo.RoomNID)
|
||||
|
|
|
@ -145,7 +145,7 @@ func (r *Joiner) performJoinRoomByAlias(
|
|||
return r.performJoinRoomByID(ctx, req)
|
||||
}
|
||||
|
||||
// TODO: Break this function up a bit
|
||||
// TODO: Break this function up a bit & move to GMSL
|
||||
// nolint:gocyclo
|
||||
func (r *Joiner) performJoinRoomByID(
|
||||
ctx context.Context,
|
||||
|
@ -286,7 +286,7 @@ func (r *Joiner) performJoinRoomByID(
|
|||
}
|
||||
event, err := eventutil.QueryAndBuildEvent(ctx, &proto, r.Cfg.Matrix, identity, time.Now(), r.RSAPI, &buildRes)
|
||||
|
||||
switch err {
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
// The room join is local. Send the new join event into the
|
||||
// roomserver. First of all check that the user isn't already
|
||||
|
@ -328,7 +328,7 @@ func (r *Joiner) performJoinRoomByID(
|
|||
// Otherwise we'll try a federated join as normal, since it's quite
|
||||
// possible that the room still exists on other servers.
|
||||
if len(req.ServerNames) == 0 {
|
||||
return "", "", eventutil.ErrRoomNoExists
|
||||
return "", "", eventutil.ErrRoomNoExists{}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ func publishNewRoomAndUnpublishOldRoom(
|
|||
|
||||
func (r *Upgrader) validateRoomExists(ctx context.Context, roomID string) error {
|
||||
if _, err := r.URSAPI.QueryRoomVersionForRoom(ctx, roomID); err != nil {
|
||||
return eventutil.ErrRoomNoExists
|
||||
return eventutil.ErrRoomNoExists{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -556,15 +556,18 @@ func (r *Upgrader) makeHeaderedEvent(ctx context.Context, evTime time.Time, user
|
|||
}
|
||||
var queryRes api.QueryLatestEventsAndStateResponse
|
||||
headeredEvent, err := eventutil.QueryAndBuildEvent(ctx, &proto, r.Cfg.Matrix, identity, evTime, r.URSAPI, &queryRes)
|
||||
if err == eventutil.ErrRoomNoExists {
|
||||
return nil, err
|
||||
} else if e, ok := err.(gomatrixserverlib.BadJSONError); ok {
|
||||
switch e := err.(type) {
|
||||
case nil:
|
||||
case eventutil.ErrRoomNoExists:
|
||||
return nil, e
|
||||
} else if e, ok := err.(gomatrixserverlib.EventValidationError); ok {
|
||||
case gomatrixserverlib.BadJSONError:
|
||||
return nil, e
|
||||
} else if err != nil {
|
||||
case gomatrixserverlib.EventValidationError:
|
||||
return nil, e
|
||||
default:
|
||||
return nil, fmt.Errorf("failed to build new %q event: %w", proto.Type, err)
|
||||
}
|
||||
|
||||
// check to see if this user can perform this operation
|
||||
stateEvents := make([]gomatrixserverlib.PDU, len(queryRes.StateEvents))
|
||||
for i := range queryRes.StateEvents {
|
||||
|
|
|
@ -858,6 +858,49 @@ func (r *Queryer) QueryAuthChain(ctx context.Context, req *api.QueryAuthChainReq
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *Queryer) InvitePending(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (bool, error) {
|
||||
pending, _, _, _, err := helpers.IsInvitePending(ctx, r.DB, roomID.String(), userID.String())
|
||||
return pending, err
|
||||
}
|
||||
|
||||
func (r *Queryer) QueryRoomInfo(ctx context.Context, roomID spec.RoomID) (*types.RoomInfo, error) {
|
||||
return r.DB.RoomInfo(ctx, roomID.String())
|
||||
}
|
||||
|
||||
func (r *Queryer) CurrentStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (gomatrixserverlib.PDU, error) {
|
||||
return r.DB.GetStateEvent(ctx, roomID.String(), string(eventType), "")
|
||||
}
|
||||
|
||||
func (r *Queryer) UserJoinedToRoom(ctx context.Context, roomNID types.RoomNID, userID spec.UserID) (bool, error) {
|
||||
_, isIn, _, err := r.DB.GetMembership(ctx, roomNID, userID.String())
|
||||
return isIn, err
|
||||
}
|
||||
|
||||
func (r *Queryer) LocallyJoinedUsers(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, roomNID types.RoomNID) ([]gomatrixserverlib.PDU, error) {
|
||||
joinNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomNID, true, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
events, err := r.DB.Events(ctx, roomVersion, joinNIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// For each of the joined users, let's see if we can get a valid
|
||||
// membership event.
|
||||
joinedUsers := []gomatrixserverlib.PDU{}
|
||||
for _, event := range events {
|
||||
if event.Type() != spec.MRoomMember || event.StateKey() == nil {
|
||||
continue // shouldn't happen
|
||||
}
|
||||
|
||||
joinedUsers = append(joinedUsers, event)
|
||||
}
|
||||
|
||||
return joinedUsers, nil
|
||||
}
|
||||
|
||||
// nolint:gocyclo
|
||||
func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.QueryRestrictedJoinAllowedRequest, res *api.QueryRestrictedJoinAllowedResponse) error {
|
||||
// Look up if we know anything about the room. If it doesn't exist
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue