mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-11 16:13:10 -06:00
Use new gmsl HandleMakeJoin api
This commit is contained in:
parent
f3cb344679
commit
7c9730c9a5
|
|
@ -38,51 +38,47 @@ type JoinRoomQuerier struct {
|
|||
roomserver api.FederationRoomserverAPI
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) RoomInfo(ctx context.Context, roomID spec.RoomID) (*gomatrixserverlib.RoomInfo, error) {
|
||||
roomInfo, err := rq.roomserver.QueryRoomInfo(ctx, roomID)
|
||||
var result *gomatrixserverlib.RoomInfo
|
||||
if roomInfo != nil && !roomInfo.IsStub() {
|
||||
result = &gomatrixserverlib.RoomInfo{
|
||||
Version: roomInfo.RoomVersion,
|
||||
NID: int64(roomInfo.RoomNID),
|
||||
}
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) CurrentStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (gomatrixserverlib.PDU, error) {
|
||||
return rq.roomserver.GetStateEvent(ctx, roomID, eventType, stateKey)
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) ServerInRoom(ctx context.Context, server spec.ServerName, roomID spec.RoomID) (*gomatrixserverlib.JoinedToRoomResponse, error) {
|
||||
req := api.QueryServerJoinedToRoomRequest{
|
||||
ServerName: server,
|
||||
RoomID: roomID.String(),
|
||||
}
|
||||
res := api.QueryServerJoinedToRoomResponse{}
|
||||
if err := rq.roomserver.QueryServerJoinedToRoom(ctx, &req, &res); err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
||||
return nil, fmt.Errorf("InternalServerError: Failed to query room")
|
||||
}
|
||||
|
||||
joinedResponse := gomatrixserverlib.JoinedToRoomResponse{
|
||||
RoomExists: res.RoomExists,
|
||||
ServerInRoom: res.IsInRoom,
|
||||
}
|
||||
return &joinedResponse, nil
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) UserJoinedToRoom(ctx context.Context, roomNID int64, userID spec.UserID) (bool, error) {
|
||||
return rq.roomserver.UserJoinedToRoom(ctx, types.RoomNID(roomNID), userID)
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) GetJoinedUsers(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, roomNID int64) ([]gomatrixserverlib.PDU, error) {
|
||||
return rq.roomserver.GetLocallyJoinedUsers(ctx, roomVersion, types.RoomNID(roomNID))
|
||||
return rq.roomserver.CurrentStateEvent(ctx, roomID, eventType, stateKey)
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) InvitePending(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (bool, error) {
|
||||
return rq.roomserver.IsInvitePending(ctx, roomID, userID)
|
||||
return rq.roomserver.InvitePending(ctx, roomID, userID)
|
||||
}
|
||||
|
||||
func (rq *JoinRoomQuerier) RestrictedRoomJoinInfo(ctx context.Context, roomID spec.RoomID, userID spec.UserID, localServerName spec.ServerName) (*gomatrixserverlib.RestrictedRoomJoinInfo, error) {
|
||||
roomInfo, err := rq.roomserver.QueryRoomInfo(ctx, roomID)
|
||||
if err != nil || roomInfo == nil || roomInfo.IsStub() {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := api.QueryServerJoinedToRoomRequest{
|
||||
ServerName: localServerName,
|
||||
RoomID: roomID.String(),
|
||||
}
|
||||
res := api.QueryServerJoinedToRoomResponse{}
|
||||
if err = rq.roomserver.QueryServerJoinedToRoom(ctx, &req, &res); err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
||||
return nil, fmt.Errorf("InternalServerError: Failed to query room: %w", err)
|
||||
}
|
||||
|
||||
userJoinedToRoom, err := rq.roomserver.UserJoinedToRoom(ctx, types.RoomNID(roomInfo.RoomNID), userID)
|
||||
if err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("rsAPI.UserJoinedToRoom failed")
|
||||
return nil, fmt.Errorf("InternalServerError: %w", err)
|
||||
}
|
||||
|
||||
locallyJoinedUsers, err := rq.roomserver.LocallyJoinedUsers(ctx, roomInfo.RoomVersion, types.RoomNID(roomInfo.RoomNID))
|
||||
if err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("rsAPI.GetLocallyJoinedUsers failed")
|
||||
return nil, fmt.Errorf("InternalServerError: %w", err)
|
||||
}
|
||||
|
||||
return &gomatrixserverlib.RestrictedRoomJoinInfo{
|
||||
LocalServerInRoom: res.RoomExists && res.IsInRoom,
|
||||
UserJoinedToRoom: userJoinedToRoom,
|
||||
JoinedUsers: locallyJoinedUsers,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// MakeJoin implements the /make_join API
|
||||
|
|
@ -103,6 +99,19 @@ func MakeJoin(
|
|||
}
|
||||
}
|
||||
|
||||
req := api.QueryServerJoinedToRoomRequest{
|
||||
ServerName: cfg.Matrix.ServerName,
|
||||
RoomID: roomID.String(),
|
||||
}
|
||||
res := api.QueryServerJoinedToRoomResponse{}
|
||||
if err := rsAPI.QueryServerJoinedToRoom(httpReq.Context(), &req, &res); err != nil {
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.InternalServerError{},
|
||||
}
|
||||
}
|
||||
|
||||
createJoinTemplate := func(proto *gomatrixserverlib.ProtoEvent) (gomatrixserverlib.PDU, []gomatrixserverlib.PDU, error) {
|
||||
identity, err := cfg.Matrix.SigningIdentityFor(request.Destination())
|
||||
if err != nil {
|
||||
|
|
@ -147,6 +156,7 @@ func MakeJoin(
|
|||
RequestOrigin: request.Origin(),
|
||||
RequestDestination: request.Destination(),
|
||||
LocalServerName: cfg.Matrix.ServerName,
|
||||
LocalServerInRoom: res.RoomExists && res.IsInRoom,
|
||||
RoomQuerier: &roomQuerier,
|
||||
BuildEventTemplate: createJoinTemplate,
|
||||
}
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -22,7 +22,7 @@ require (
|
|||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230515194922-4426c0fdbf6a
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230515224826-c80a7e3dc01d
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -323,8 +323,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
|
|||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230515194922-4426c0fdbf6a h1:faMIb4rPgoFlYmDewtX9N3Y39iKh/BFpLtYz0kkiQU0=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230515194922-4426c0fdbf6a/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230515224826-c80a7e3dc01d h1:Tf9jUdnK6WyvdRgmeLtkpndhoOFsOdBWWqZGld6lpHU=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230515224826-c80a7e3dc01d/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
||||
|
|
|
|||
|
|
@ -226,11 +226,11 @@ type FederationRoomserverAPI interface {
|
|||
// Query a given amount (or less) of events prior to a given set of events.
|
||||
PerformBackfill(ctx context.Context, req *PerformBackfillRequest, res *PerformBackfillResponse) error
|
||||
|
||||
IsInvitePending(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (bool, 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)
|
||||
GetStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (gomatrixserverlib.PDU, error)
|
||||
UserJoinedToRoom(ctx context.Context, roomID types.RoomNID, userID spec.UserID) (bool, error)
|
||||
GetLocallyJoinedUsers(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, roomNID types.RoomNID) ([]gomatrixserverlib.PDU, error)
|
||||
LocallyJoinedUsers(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, roomNID types.RoomNID) ([]gomatrixserverlib.PDU, error)
|
||||
}
|
||||
|
||||
type KeyserverRoomserverAPI interface {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue