mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Add presence config option
This commit is contained in:
parent
9e42b3acdc
commit
f4817d6a4c
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
"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/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
|
|
@ -40,10 +41,17 @@ type presenceReq struct {
|
||||||
|
|
||||||
func SetPresence(
|
func SetPresence(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
|
cfg *config.ClientAPI,
|
||||||
device *api.Device,
|
device *api.Device,
|
||||||
producer *producers.SyncAPIProducer,
|
producer *producers.SyncAPIProducer,
|
||||||
userID string,
|
userID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
if cfg.Matrix.DisablePresence {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: struct{}{},
|
||||||
|
}
|
||||||
|
}
|
||||||
if device.UserID != userID {
|
if device.UserID != userID {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
|
|
|
||||||
|
|
@ -1292,7 +1292,7 @@ func Setup(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
return SetPresence(req, device, syncProducer, vars["userId"])
|
return SetPresence(req, cfg, device, syncProducer, vars["userId"])
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodPut, http.MethodOptions)
|
).Methods(http.MethodPut, http.MethodOptions)
|
||||||
v3mux.Handle("/presence/{userId}/status",
|
v3mux.Handle("/presence/{userId}/status",
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,9 @@ global:
|
||||||
# to other servers and the federation API will not be exposed.
|
# to other servers and the federation API will not be exposed.
|
||||||
disable_federation: false
|
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 allows server admins to send messages to all users.
|
||||||
server_notices:
|
server_notices:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ type Global struct {
|
||||||
// to other servers and the federation API will not be exposed.
|
// to other servers and the federation API will not be exposed.
|
||||||
DisableFederation bool `yaml:"disable_federation"`
|
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
|
// List of domains that the server will trust as identity servers to
|
||||||
// verify third-party identifiers.
|
// verify third-party identifiers.
|
||||||
// Defaults to an empty array.
|
// Defaults to an empty array.
|
||||||
|
|
@ -68,6 +71,7 @@ func (c *Global) Defaults(generate bool) {
|
||||||
c.PrivateKeyPath = "matrix_key.pem"
|
c.PrivateKeyPath = "matrix_key.pem"
|
||||||
_, c.PrivateKey, _ = ed25519.GenerateKey(rand.New(rand.NewSource(0)))
|
_, c.PrivateKey, _ = ed25519.GenerateKey(rand.New(rand.NewSource(0)))
|
||||||
c.KeyID = "ed25519:auto"
|
c.KeyID = "ed25519:auto"
|
||||||
|
c.DisablePresence = false
|
||||||
}
|
}
|
||||||
c.KeyValidityPeriod = time.Hour * 24 * 7
|
c.KeyValidityPeriod = time.Hour * 24 * 7
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,9 @@ func (rp *RequestPool) cleanPresence(cleanupTime time.Duration) {
|
||||||
|
|
||||||
// updatePresence sends presence updates to the SyncAPI and FederationAPI
|
// updatePresence sends presence updates to the SyncAPI and FederationAPI
|
||||||
func (rp *RequestPool) updatePresence(presence string, device *userapi.Device) {
|
func (rp *RequestPool) updatePresence(presence string, device *userapi.Device) {
|
||||||
|
if rp.cfg.Matrix.DisablePresence {
|
||||||
|
return
|
||||||
|
}
|
||||||
if presence == "" {
|
if presence == "" {
|
||||||
presence = "online"
|
presence = "online"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ func TestRequestPool_updatePresence(t *testing.T) {
|
||||||
JetStream: config.JetStream{
|
JetStream: config.JetStream{
|
||||||
TopicPrefix: "Dendrite",
|
TopicPrefix: "Dendrite",
|
||||||
},
|
},
|
||||||
|
DisablePresence: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func AddPublicRoutes(
|
||||||
logrus.WithError(err).Panicf("failed to load notifier ")
|
logrus.WithError(err).Panicf("failed to load notifier ")
|
||||||
}
|
}
|
||||||
|
|
||||||
federationPresenceProducer := producers.FederationAPIPresenceProducer{
|
federationPresenceProducer := &producers.FederationAPIPresenceProducer{
|
||||||
Topic: cfg.Matrix.JetStream.Prefixed(jetstream.OutputPresenceEvent),
|
Topic: cfg.Matrix.JetStream.Prefixed(jetstream.OutputPresenceEvent),
|
||||||
JetStream: js,
|
JetStream: js,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue