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
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -131,6 +130,9 @@ func MakeJoin(
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendJoin implements the /send_join API
|
// 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(
|
func SendJoin(
|
||||||
httpReq *http.Request,
|
httpReq *http.Request,
|
||||||
request *gomatrixserverlib.FederationRequest,
|
request *gomatrixserverlib.FederationRequest,
|
||||||
|
|
@ -247,19 +249,13 @@ func SendJoin(
|
||||||
// there isn't much point in sending another join event into the room.
|
// there isn't much point in sending another join event into the room.
|
||||||
alreadyJoined := false
|
alreadyJoined := false
|
||||||
for _, se := range stateAndAuthChainResponse.StateEvents {
|
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() {
|
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")
|
alreadyJoined = (membership == "join")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Send the events to the room server.
|
// Send the events to the room server.
|
||||||
// We are responsible for notifying other servers that the user has joined
|
// We are responsible for notifying other servers that the user has joined
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -52,7 +51,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByAlias(
|
||||||
// doesn't then we'll need to try a federated join.
|
// doesn't then we'll need to try a federated join.
|
||||||
var roomID string
|
var roomID string
|
||||||
if domain != r.Cfg.Matrix.ServerName {
|
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.
|
// a remote server.
|
||||||
dirReq := fsAPI.PerformDirectoryLookupRequest{
|
dirReq := fsAPI.PerformDirectoryLookupRequest{
|
||||||
RoomAlias: req.RoomIDOrAlias, // the room alias to lookup
|
RoomAlias: req.RoomIDOrAlias, // the room alias to lookup
|
||||||
|
|
@ -144,19 +143,13 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
||||||
// a member of the room.
|
// a member of the room.
|
||||||
alreadyJoined := false
|
alreadyJoined := false
|
||||||
for _, se := range buildRes.StateEvents {
|
for _, se := range buildRes.StateEvents {
|
||||||
if se.Type() == gomatrixserverlib.MRoomMember {
|
if membership, merr := se.Membership(); merr == nil {
|
||||||
if se.StateKey() != nil && *se.StateKey() == userID {
|
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")
|
alreadyJoined = (membership == "join")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If we haven't already joined the room then send an event
|
// If we haven't already joined the room then send an event
|
||||||
// into the room changing our membership status.
|
// into the room changing our membership status.
|
||||||
|
|
@ -205,6 +198,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
joined = true
|
joined = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we didn't successfully join the room using any of the supplied
|
// If we didn't successfully join the room using any of the supplied
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue