mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Reformat canonical alias stuff
This commit is contained in:
parent
4e68ce3a06
commit
d9ca7565b0
|
|
@ -169,6 +169,7 @@ func NotTrusted(serverName string) *MatrixError {
|
|||
Err: fmt.Sprintf("Untrusted server '%s'", serverName),
|
||||
}
|
||||
}
|
||||
|
||||
// BadAlias is an error which is returned when one or more aliases within a
|
||||
// m.room.canonical_alias event do not point to the room ID for which the state
|
||||
// event is to be sent to.
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
|
|
@ -223,17 +223,20 @@ func RemoveLocalAlias(
|
|||
}
|
||||
}
|
||||
|
||||
var updatedCanonicalAlias *eventutil.CanonicalAlias
|
||||
updated, resErr := getUpdatedCanonicalAliasState(req, device, queryRes.RoomID, alias, rsAPI, updatedCanonicalAlias)
|
||||
updatedCanonicalAlias := eventutil.CanonicalAlias{
|
||||
Alias: "",
|
||||
AltAliases: []string{""},
|
||||
}
|
||||
updated, resErr := getUpdatedCanonicalAliasState(req, queryRes.RoomID, alias, rsAPI, &updatedCanonicalAlias)
|
||||
if resErr != nil {
|
||||
return *resErr;
|
||||
return *resErr
|
||||
}
|
||||
// If the alias removed is one of the alt_aliases or the canonical one,
|
||||
// we need to also remove it from the canonical_alias event
|
||||
if updated {
|
||||
resErr := updateCanonicalAlias(req, device, queryRes.RoomID, cfg, rsAPI, updatedCanonicalAlias)
|
||||
resErr := updateCanonicalAlias(req, device, queryRes.RoomID, cfg, rsAPI, &updatedCanonicalAlias)
|
||||
if resErr != nil {
|
||||
return *resErr;
|
||||
return *resErr
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +248,6 @@ func RemoveLocalAlias(
|
|||
|
||||
func getUpdatedCanonicalAliasState(
|
||||
req *http.Request,
|
||||
device *api.Device,
|
||||
roomID string,
|
||||
alias string,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
|
|
@ -268,10 +270,6 @@ func getUpdatedCanonicalAliasState(
|
|||
return false, &resErr
|
||||
}
|
||||
|
||||
updatedCanonicalAlias = &eventutil.CanonicalAlias {
|
||||
Alias: "",
|
||||
AltAliases: []string{""},
|
||||
}
|
||||
// We try to get the current canonical_alias state, and if found compare its content
|
||||
// to the removed alias
|
||||
if canonicalAliasEvent, ok := stateRes.StateEvents[stateTuple]; ok {
|
||||
|
|
@ -279,6 +277,7 @@ func getUpdatedCanonicalAliasState(
|
|||
Alias: "",
|
||||
AltAliases: []string{""},
|
||||
}
|
||||
// TODO handle differently malformed event?
|
||||
err := json.Unmarshal(canonicalAliasEvent.Content(), &canonicalAliasContent)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("Get canonical_alias event content failed")
|
||||
|
|
@ -290,7 +289,7 @@ func getUpdatedCanonicalAliasState(
|
|||
} else {
|
||||
updatedCanonicalAlias.Alias = canonicalAliasContent.Alias
|
||||
}
|
||||
for _, s := range(canonicalAliasContent.AltAliases) {
|
||||
for _, s := range canonicalAliasContent.AltAliases {
|
||||
if alias == s {
|
||||
updated = true
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -263,14 +263,14 @@ func generateSendEvent(
|
|||
|
||||
//TODO: maybe do something like synapse where state is retrieved in order to only check new aliases
|
||||
for _, alias := range content.AltAliases {
|
||||
resErr = checkAlias(req.Context(), device, alias, queryRes.Aliases, federation, cfg)
|
||||
resErr = checkAlias(req.Context(), alias, queryRes.Aliases, federation, cfg)
|
||||
if resErr != nil {
|
||||
return nil, resErr
|
||||
}
|
||||
}
|
||||
|
||||
if content.Alias != "" {
|
||||
resErr = checkAlias(req.Context(), device, content.Alias, queryRes.Aliases, federation, cfg)
|
||||
resErr = checkAlias(req.Context(), content.Alias, queryRes.Aliases, federation, cfg)
|
||||
if resErr != nil {
|
||||
return nil, resErr
|
||||
}
|
||||
|
|
@ -281,7 +281,6 @@ func generateSendEvent(
|
|||
|
||||
func checkAlias(
|
||||
ctx context.Context,
|
||||
device *userapi.Device,
|
||||
alias string,
|
||||
roomAliases []string,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
|
|
|
|||
Loading…
Reference in a new issue