Use Membership, don't try more servers than needed

This commit is contained in:
Neil Alexander 2020-05-04 12:30:47 +01:00
parent 3b6a94f007
commit f5963308e0
2 changed files with 12 additions and 22 deletions

View file

@ -15,7 +15,6 @@
package routing
import (
"encoding/json"
"fmt"
"net/http"
"time"
@ -131,6 +130,9 @@ func MakeJoin(
}
// SendJoin implements the /send_join API
// TODO: Is there a way to break this function up in a way that actually
// makes sense?
// nolint:gocyclo
func SendJoin(
httpReq *http.Request,
request *gomatrixserverlib.FederationRequest,
@ -247,19 +249,13 @@ func SendJoin(
// there isn't much point in sending another join event into the room.
alreadyJoined := false
for _, se := range stateAndAuthChainResponse.StateEvents {
if se.Type() == gomatrixserverlib.MRoomMember {
if membership, merr := se.Membership(); merr == nil {
if se.StateKey() != nil && *se.StateKey() == *event.StateKey() {
var content map[string]interface{}
if err = json.Unmarshal(se.Content(), &content); err != nil {
continue
}
if membership, ok := content["membership"]; ok {
alreadyJoined = (membership == "join")
break
}
}
}
}
// Send the events to the room server.
// We are responsible for notifying other servers that the user has joined

View file

@ -2,7 +2,6 @@ package internal
import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
@ -52,7 +51,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByAlias(
// doesn't then we'll need to try a federated join.
var roomID string
if domain != r.Cfg.Matrix.ServerName {
// The alias isn't owned by us, so we will eed to try joining using
// The alias isn't owned by us, so we will need to try joining using
// a remote server.
dirReq := fsAPI.PerformDirectoryLookupRequest{
RoomAlias: req.RoomIDOrAlias, // the room alias to lookup
@ -144,19 +143,13 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
// a member of the room.
alreadyJoined := false
for _, se := range buildRes.StateEvents {
if se.Type() == gomatrixserverlib.MRoomMember {
if se.StateKey() != nil && *se.StateKey() == userID {
var content map[string]interface{}
if err = json.Unmarshal(se.Content(), &content); err != nil {
continue
}
if membership, ok := content["membership"]; ok {
if membership, merr := se.Membership(); merr == nil {
if se.StateKey() != nil && *se.StateKey() == *event.StateKey() {
alreadyJoined = (membership == "join")
break
}
}
}
}
// If we haven't already joined the room then send an event
// into the room changing our membership status.
@ -205,6 +198,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
continue
}
joined = true
break
}
// If we didn't successfully join the room using any of the supplied