mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Handle innvites through regular roomserver ingress
This commit is contained in:
parent
d236317878
commit
3b289ff248
|
|
@ -99,19 +99,3 @@ func (c *RoomserverProducer) SendInputRoomEvents(
|
||||||
eventID = response.EventID
|
eventID = response.EventID
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendInvite writes the invite event to the roomserver input API.
|
|
||||||
// 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 (c *RoomserverProducer) SendInvite(
|
|
||||||
ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent,
|
|
||||||
) error {
|
|
||||||
request := api.InputRoomEventsRequest{
|
|
||||||
InputInviteEvents: []api.InputInviteEvent{{
|
|
||||||
Event: inviteEvent,
|
|
||||||
RoomVersion: inviteEvent.RoomVersion,
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
var response api.InputRoomEventsResponse
|
|
||||||
return c.InputAPI.InputRoomEvents(ctx, &request, &response)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func Invite(
|
||||||
|
|
||||||
var intermediate struct {
|
var intermediate struct {
|
||||||
Event json.RawMessage `json:"event"`
|
Event json.RawMessage `json:"event"`
|
||||||
InviteRoomState []json.RawMessage `json:"invite_room_state"`
|
InviteRoomState json.RawMessage `json:"invite_room_state"`
|
||||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,6 +88,12 @@ func Invite(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Populate the unsigned key with the invite room state.
|
||||||
|
if err = event.SetUnsignedField("invite_room_state", intermediate.InviteRoomState); err != nil {
|
||||||
|
util.GetLogger(httpReq.Context()).WithError(err).Error("event.SetUnsignedField failed")
|
||||||
|
return jsonerror.InternalServerError()
|
||||||
|
}
|
||||||
|
|
||||||
// Check that the event is signed by the server sending the request.
|
// Check that the event is signed by the server sending the request.
|
||||||
redacted := event.Redact()
|
redacted := event.Redact()
|
||||||
verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{
|
verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{
|
||||||
|
|
@ -114,11 +120,13 @@ func Invite(
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the invite event to the roomserver.
|
// Add the invite event to the roomserver.
|
||||||
if err = producer.SendInvite(
|
if _, err := producer.SendEvents(
|
||||||
httpReq.Context(),
|
httpReq.Context(),
|
||||||
signedEvent.Headered(intermediate.RoomVersion),
|
[]gomatrixserverlib.HeaderedEvent{signedEvent.Headered(intermediate.RoomVersion)},
|
||||||
|
signedEvent.Origin(),
|
||||||
|
nil,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed")
|
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendEvents failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,10 @@ func (s *OutputRoomEventConsumer) processInvite(oie api.OutputNewInviteEvent) er
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("FEDERATION SENDER IS PROCESSING INVITE")
|
||||||
|
fmt.Println("Event:", string(oie.Event.JSON()))
|
||||||
|
fmt.Println("Invite room state:", string(oie.InviteRoomState))
|
||||||
|
|
||||||
// Try to unmarshal the invite room state to pass to the destination queue.
|
// Try to unmarshal the invite room state to pass to the destination queue.
|
||||||
inviteRoomState := []gomatrixserverlib.InviteV2StrippedState{}
|
inviteRoomState := []gomatrixserverlib.InviteV2StrippedState{}
|
||||||
if err := json.Unmarshal(oie.InviteRoomState, &inviteRoomState); err != nil {
|
if err := json.Unmarshal(oie.InviteRoomState, &inviteRoomState); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
|
@ -83,19 +82,9 @@ type TransactionID struct {
|
||||||
TransactionID string `json:"id"`
|
TransactionID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputInviteEvent is a matrix invite event received over federation without
|
|
||||||
// the usual context a matrix room event would have. We usually do not have
|
|
||||||
// access to the events needed to check the event auth rules for the invite.
|
|
||||||
type InputInviteEvent struct {
|
|
||||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
|
||||||
Event gomatrixserverlib.HeaderedEvent `json:"event"`
|
|
||||||
InviteRoomState json.RawMessage `json:"invite_room_state"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// InputRoomEventsRequest is a request to InputRoomEvents
|
// InputRoomEventsRequest is a request to InputRoomEvents
|
||||||
type InputRoomEventsRequest struct {
|
type InputRoomEventsRequest struct {
|
||||||
InputRoomEvents []InputRoomEvent `json:"input_room_events"`
|
InputRoomEvents []InputRoomEvent `json:"input_room_events"`
|
||||||
InputInviteEvents []InputInviteEvent `json:"input_invite_events"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputRoomEventsResponse is a response to InputRoomEvents
|
// InputRoomEventsResponse is a response to InputRoomEvents
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,12 @@ package input
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common"
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
"github.com/matrix-org/dendrite/roomserver/state"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state/database"
|
"github.com/matrix-org/dendrite/roomserver/state/database"
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A RoomEventDatabase has the storage APIs needed to store a room event.
|
// A RoomEventDatabase has the storage APIs needed to store a room event.
|
||||||
|
|
@ -185,6 +181,7 @@ func calculateAndSetState(
|
||||||
return db.SetState(ctx, stateAtEvent.EventNID, stateAtEvent.BeforeStateSnapshotNID)
|
return db.SetState(ctx, stateAtEvent.EventNID, stateAtEvent.BeforeStateSnapshotNID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func processInviteEvent(
|
func processInviteEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
db RoomEventDatabase,
|
db RoomEventDatabase,
|
||||||
|
|
@ -251,6 +248,11 @@ func processInviteEvent(
|
||||||
event := input.Event.Unwrap()
|
event := input.Event.Unwrap()
|
||||||
inviteStrippedState := input.InviteRoomState
|
inviteStrippedState := input.InviteRoomState
|
||||||
|
|
||||||
|
fmt.Println("ROOM SERVER RECEIVED EVENT:")
|
||||||
|
j1, _ := json.MarshalIndent(event, "", " ")
|
||||||
|
j2, _ := json.MarshalIndent(inviteStrippedState, "", " ")
|
||||||
|
fmt.Printf("Event: %s\nInvite room state: %s\n", j1, j2)
|
||||||
|
|
||||||
// TODO: replace this with a proper origin check
|
// TODO: replace this with a proper origin check
|
||||||
if inviteStrippedState == nil {
|
if inviteStrippedState == nil {
|
||||||
// Otherwise, we should see if we know anything about the room state
|
// Otherwise, we should see if we know anything about the room state
|
||||||
|
|
@ -327,3 +329,4 @@ func buildInviteStrippedState(
|
||||||
}
|
}
|
||||||
return inviteStrippedState, nil
|
return inviteStrippedState, nil
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
||||||
|
|
@ -69,11 +69,6 @@ func (r *RoomserverInputAPI) InputRoomEvents(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range request.InputInviteEvents {
|
|
||||||
if err = processInviteEvent(ctx, r.DB, r, request.InputInviteEvents[i]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue