Add presence config option

This commit is contained in:
S7evinK 2022-03-31 10:10:49 +02:00
parent 9e42b3acdc
commit f4817d6a4c
7 changed files with 21 additions and 2 deletions

View file

@ -24,6 +24,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/dendrite/userapi/api"
@ -40,10 +41,17 @@ type presenceReq struct {
func SetPresence(
req *http.Request,
cfg *config.ClientAPI,
device *api.Device,
producer *producers.SyncAPIProducer,
userID string,
) util.JSONResponse {
if cfg.Matrix.DisablePresence {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct{}{},
}
}
if device.UserID != userID {
return util.JSONResponse{
Code: http.StatusForbidden,

View file

@ -1292,7 +1292,7 @@ func Setup(
if err != nil {
return util.ErrorResponse(err)
}
return SetPresence(req, device, syncProducer, vars["userId"])
return SetPresence(req, cfg, device, syncProducer, vars["userId"])
}),
).Methods(http.MethodPut, http.MethodOptions)
v3mux.Handle("/presence/{userId}/status",

View file

@ -68,6 +68,9 @@ global:
# to other servers and the federation API will not be exposed.
disable_federation: false
# Disable presence. Dendrite will not handle presence events.
disable_presence: true
# Server notices allows server admins to send messages to all users.
server_notices:
enabled: false

View file

@ -41,6 +41,9 @@ type Global struct {
// to other servers and the federation API will not be exposed.
DisableFederation bool `yaml:"disable_federation"`
// Disable presence. Dendrite will not handle presence events.
DisablePresence bool `yaml:"disable_presence"`
// List of domains that the server will trust as identity servers to
// verify third-party identifiers.
// Defaults to an empty array.
@ -68,6 +71,7 @@ func (c *Global) Defaults(generate bool) {
c.PrivateKeyPath = "matrix_key.pem"
_, c.PrivateKey, _ = ed25519.GenerateKey(rand.New(rand.NewSource(0)))
c.KeyID = "ed25519:auto"
c.DisablePresence = false
}
c.KeyValidityPeriod = time.Hour * 24 * 7

View file

@ -107,6 +107,9 @@ func (rp *RequestPool) cleanPresence(cleanupTime time.Duration) {
// updatePresence sends presence updates to the SyncAPI and FederationAPI
func (rp *RequestPool) updatePresence(presence string, device *userapi.Device) {
if rp.cfg.Matrix.DisablePresence {
return
}
if presence == "" {
presence = "online"
}

View file

@ -86,6 +86,7 @@ func TestRequestPool_updatePresence(t *testing.T) {
JetStream: config.JetStream{
TopicPrefix: "Dendrite",
},
DisablePresence: false,
},
},
}

View file

@ -63,7 +63,7 @@ func AddPublicRoutes(
logrus.WithError(err).Panicf("failed to load notifier ")
}
federationPresenceProducer := producers.FederationAPIPresenceProducer{
federationPresenceProducer := &producers.FederationAPIPresenceProducer{
Topic: cfg.Matrix.JetStream.Prefixed(jetstream.OutputPresenceEvent),
JetStream: js,
}