Delete our locally cached profile if we receive a membership event

This commit is contained in:
Till Faelligen 2022-06-14 08:20:59 +02:00
parent 016d451d90
commit 77a8e35b37
2 changed files with 12 additions and 1 deletions

View file

@ -128,7 +128,7 @@ func Setup(
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse { func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
return Send( return Send(
httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]), httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]),
cfg, rsAPI, keyAPI, keys, federation, mu, servers, producer, cfg, rsAPI, keyAPI, userAPI, keys, federation, mu, servers, producer,
) )
}, },
)).Methods(http.MethodPut, http.MethodOptions) )).Methods(http.MethodPut, http.MethodOptions)

View file

@ -31,6 +31,7 @@ import (
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
syncTypes "github.com/matrix-org/dendrite/syncapi/types" syncTypes "github.com/matrix-org/dendrite/syncapi/types"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@ -84,6 +85,7 @@ func Send(
cfg *config.FederationAPI, cfg *config.FederationAPI,
rsAPI api.FederationRoomserverAPI, rsAPI api.FederationRoomserverAPI,
keyAPI keyapi.FederationKeyAPI, keyAPI keyapi.FederationKeyAPI,
userAPI userapi.FederationUserAPI,
keys gomatrixserverlib.JSONVerifier, keys gomatrixserverlib.JSONVerifier,
federation federationAPI.FederationClient, federation federationAPI.FederationClient,
mu *internal.MutexByRoom, mu *internal.MutexByRoom,
@ -131,6 +133,7 @@ func Send(
roomsMu: mu, roomsMu: mu,
producer: producer, producer: producer,
inboundPresenceEnabled: cfg.Matrix.Presence.EnableInbound, inboundPresenceEnabled: cfg.Matrix.Presence.EnableInbound,
userAPI: userAPI,
} }
var txnEvents struct { var txnEvents struct {
@ -184,6 +187,7 @@ type txnReq struct {
gomatrixserverlib.Transaction gomatrixserverlib.Transaction
rsAPI api.FederationRoomserverAPI rsAPI api.FederationRoomserverAPI
keyAPI keyapi.FederationKeyAPI keyAPI keyapi.FederationKeyAPI
userAPI userapi.FederationUserAPI
ourServerName gomatrixserverlib.ServerName ourServerName gomatrixserverlib.ServerName
keys gomatrixserverlib.JSONVerifier keys gomatrixserverlib.JSONVerifier
federation txnFederationClient federation txnFederationClient
@ -275,6 +279,13 @@ func (t *txnReq) processTransaction(ctx context.Context) (*gomatrixserverlib.Res
continue continue
} }
// Clear our local user profile cache, if this is a membership event
if event.Type() == gomatrixserverlib.MRoomMember && event.StateKey() != nil {
if err = t.userAPI.DeleteProfile(ctx, &userapi.PerformDeleteProfileRequest{UserID: event.Sender()}, &struct{}{}); err != nil {
// non-fatal error, log and continue
util.GetLogger(ctx).WithError(err).Warnf("Transaction: couldn't delete user profile for %s", event.Sender())
}
}
// pass the event to the roomserver which will do auth checks // pass the event to the roomserver which will do auth checks
// If the event fail auth checks, gmsl.NotAllowed error will be returned which we be silently // If the event fail auth checks, gmsl.NotAllowed error will be returned which we be silently
// discarded by the caller of this function // discarded by the caller of this function