mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-28 17:23:09 -06:00
Make separate API call for room membership
This commit is contained in:
parent
c396120c24
commit
6979de9844
|
|
@ -573,6 +573,23 @@ func (t *txnReq) processEvent(ctx context.Context, e *gomatrixserverlib.Event) e
|
|||
logger := util.GetLogger(ctx).WithField("event_id", e.EventID()).WithField("room_id", e.RoomID())
|
||||
t.work = "" // reset from previous event
|
||||
|
||||
// Ask the roomserver if we know about the room and/or if we're joined
|
||||
// to it. If we aren't then we won't bother processing the event.
|
||||
joinedReq := api.QueryServerJoinedToRoomRequest{
|
||||
RoomID: e.RoomID(),
|
||||
}
|
||||
var joinedRes api.QueryServerJoinedToRoomResponse
|
||||
if err := t.rsAPI.QueryServerJoinedToRoom(ctx, &joinedReq, &joinedRes); err != nil {
|
||||
return fmt.Errorf("t.rsAPI.QueryServerJoinedToRoom: %w", err)
|
||||
}
|
||||
|
||||
if !joinedRes.RoomExists || !joinedRes.IsInRoom {
|
||||
// We don't believe we're a member of this room, therefore there's
|
||||
// no point in wasting work trying to figure out what to do with
|
||||
// missing auth or prev events. Drop the event.
|
||||
return roomNotFoundError{e.RoomID()}
|
||||
}
|
||||
|
||||
// Work out if the roomserver knows everything it needs to know to auth
|
||||
// the event. This includes the prev_events and auth_events.
|
||||
// NOTE! This is going to include prev_events that have an empty state
|
||||
|
|
@ -589,23 +606,6 @@ func (t *txnReq) processEvent(ctx context.Context, e *gomatrixserverlib.Event) e
|
|||
return fmt.Errorf("t.rsAPI.QueryMissingAuthPrevEvents: %w", err)
|
||||
}
|
||||
|
||||
if !stateResp.RoomExists {
|
||||
// TODO: When synapse receives a message for a room it is not in it
|
||||
// asks the remote server for the state of the room so that it can
|
||||
// check if the remote server knows of a join "m.room.member" event
|
||||
// that this server is unaware of.
|
||||
// However generally speaking we should reject events for rooms we
|
||||
// aren't a member of.
|
||||
return roomNotFoundError{e.RoomID()}
|
||||
}
|
||||
|
||||
if !stateResp.RoomJoined {
|
||||
// We don't believe we're a member of this room anymore, therefore
|
||||
// there's no point in wasting work trying to figure out what to do
|
||||
// with missing auth or prev events. Silently drop the event.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Prepare a map of all the events we already had before this point, so
|
||||
// that we don't send them to the roomserver again.
|
||||
for _, eventID := range append(e.AuthEventIDs(), e.PrevEventIDs()...) {
|
||||
|
|
|
|||
|
|
@ -142,7 +142,6 @@ func (t *testRoomserverAPI) QueryMissingAuthPrevEvents(
|
|||
response.RoomVersion = testRoomVersion
|
||||
res := t.queryMissingAuthPrevEvents(request)
|
||||
response.RoomExists = res.RoomExists
|
||||
response.RoomJoined = true
|
||||
response.MissingAuthEventIDs = res.MissingAuthEventIDs
|
||||
response.MissingPrevEventIDs = res.MissingPrevEventIDs
|
||||
return nil
|
||||
|
|
@ -191,7 +190,9 @@ func (t *testRoomserverAPI) QueryServerJoinedToRoom(
|
|||
request *api.QueryServerJoinedToRoomRequest,
|
||||
response *api.QueryServerJoinedToRoomResponse,
|
||||
) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
response.RoomExists = true
|
||||
response.IsInRoom = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query whether a server is allowed to see an event
|
||||
|
|
|
|||
|
|
@ -96,8 +96,6 @@ type QueryMissingAuthPrevEventsResponse struct {
|
|||
// Does the room exist on this roomserver?
|
||||
// If the room doesn't exist all other fields will be empty.
|
||||
RoomExists bool `json:"room_exists"`
|
||||
// Are we joined to this room locally?
|
||||
RoomJoined bool `json:"room_joined"`
|
||||
// The room version of the room.
|
||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||
// The event IDs of the auth events that we don't know locally.
|
||||
|
|
@ -172,7 +170,8 @@ type QueryMembershipsForRoomResponse struct {
|
|||
|
||||
// QueryServerJoinedToRoomRequest is a request to QueryServerJoinedToRoom
|
||||
type QueryServerJoinedToRoomRequest struct {
|
||||
// Server name of the server to find
|
||||
// Server name of the server to find. If not specified, we will
|
||||
// default to checking if the local server is joined.
|
||||
ServerName gomatrixserverlib.ServerName `json:"server_name"`
|
||||
// ID of the room to see if we are still joined to
|
||||
RoomID string `json:"room_id"`
|
||||
|
|
|
|||
|
|
@ -142,14 +142,6 @@ func (r *Queryer) QueryMissingAuthPrevEvents(
|
|||
response.RoomExists = !info.IsStub
|
||||
response.RoomVersion = info.RoomVersion
|
||||
|
||||
if response.RoomExists {
|
||||
joined, err := r.DB.GetLocalServerInRoom(ctx, info.RoomNID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("r.DB.GetLocalServerInRoom: %w", err)
|
||||
}
|
||||
response.RoomJoined = joined
|
||||
}
|
||||
|
||||
for _, authEventID := range request.AuthEventIDs {
|
||||
if nids, err := r.DB.EventNIDs(ctx, []string{authEventID}); err != nil || len(nids) == 0 {
|
||||
response.MissingAuthEventIDs = append(response.MissingAuthEventIDs, authEventID)
|
||||
|
|
@ -337,7 +329,7 @@ func (r *Queryer) QueryServerJoinedToRoom(
|
|||
}
|
||||
response.RoomExists = true
|
||||
|
||||
if request.ServerName == r.ServerName {
|
||||
if request.ServerName == r.ServerName || request.ServerName == "" {
|
||||
var joined bool
|
||||
joined, err = r.DB.GetLocalServerInRoom(ctx, info.RoomNID)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue