From f4817d6a4caaa7995ab3a1f7bf1a095fddbcf417 Mon Sep 17 00:00:00 2001 From: S7evinK Date: Thu, 31 Mar 2022 10:10:49 +0200 Subject: [PATCH] Add presence config option --- clientapi/routing/presence.go | 8 ++++++++ clientapi/routing/routing.go | 2 +- dendrite-config.yaml | 3 +++ setup/config/config_global.go | 4 ++++ syncapi/sync/requestpool.go | 3 +++ syncapi/sync/requestpool_test.go | 1 + syncapi/syncapi.go | 2 +- 7 files changed, 21 insertions(+), 2 deletions(-) diff --git a/clientapi/routing/presence.go b/clientapi/routing/presence.go index 261797887..07d690bdb 100644 --- a/clientapi/routing/presence.go +++ b/clientapi/routing/presence.go @@ -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, diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 93d6ea01c..f2ac16066 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -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", diff --git a/dendrite-config.yaml b/dendrite-config.yaml index 6e2bc7be9..afe12f8dd 100644 --- a/dendrite-config.yaml +++ b/dendrite-config.yaml @@ -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 diff --git a/setup/config/config_global.go b/setup/config/config_global.go index b947f2076..61086a4dd 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -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 diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 63599b7d6..29407efd8 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -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" } diff --git a/syncapi/sync/requestpool_test.go b/syncapi/sync/requestpool_test.go index 1d11b9df3..a741dd0c6 100644 --- a/syncapi/sync/requestpool_test.go +++ b/syncapi/sync/requestpool_test.go @@ -86,6 +86,7 @@ func TestRequestPool_updatePresence(t *testing.T) { JetStream: config.JetStream{ TopicPrefix: "Dendrite", }, + DisablePresence: false, }, }, } diff --git a/syncapi/syncapi.go b/syncapi/syncapi.go index 1581149b2..42c570469 100644 --- a/syncapi/syncapi.go +++ b/syncapi/syncapi.go @@ -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, }