mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Use Membership, don't try more servers than needed
This commit is contained in:
parent
3b6a94f007
commit
f5963308e0
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue