mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-31 10:43:10 -06:00
Only create the account when starting
Only add routes if sever notices are enabled
This commit is contained in:
parent
92e93191e2
commit
c08a8db23e
|
|
@ -15,6 +15,7 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -117,40 +118,48 @@ func Setup(
|
||||||
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
synapseAdminRouter.Handle("/admin/v1/send_server_notice/{txnID}",
|
// server notifications
|
||||||
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
if cfg.Matrix.ServerNotices.Enabled {
|
||||||
// not specced, but ensure we're rate limiting requests to this endpoint
|
serverNotificationSender, err := getSenderDevice(context.Background(), userAPI, accountDB, cfg)
|
||||||
if r := rateLimits.Limit(req); r != nil {
|
if err != nil {
|
||||||
return *r
|
logrus.WithError(err).Fatal("unable to get account for sending sending server notices")
|
||||||
}
|
}
|
||||||
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
||||||
if err != nil {
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
txnID := vars["txnID"]
|
|
||||||
return SendServerNotice(
|
|
||||||
req, &cfg.Matrix.ServerNotices,
|
|
||||||
cfg, userAPI, rsAPI, accountDB, asAPI,
|
|
||||||
device,
|
|
||||||
&txnID, transactionsCache,
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
).Methods(http.MethodPut, http.MethodOptions)
|
|
||||||
|
|
||||||
synapseAdminRouter.Handle("/admin/v1/send_server_notice",
|
synapseAdminRouter.Handle("/admin/v1/send_server_notice/{txnID}",
|
||||||
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||||
// not specced, but ensure we're rate limiting requests to this endpoint
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
||||||
if r := rateLimits.Limit(req); r != nil {
|
if r := rateLimits.Limit(req); r != nil {
|
||||||
return *r
|
return *r
|
||||||
}
|
}
|
||||||
return SendServerNotice(
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
||||||
req, &cfg.Matrix.ServerNotices,
|
if err != nil {
|
||||||
cfg, userAPI, rsAPI, accountDB, asAPI,
|
return util.ErrorResponse(err)
|
||||||
device,
|
}
|
||||||
nil, transactionsCache,
|
txnID := vars["txnID"]
|
||||||
)
|
return SendServerNotice(
|
||||||
}),
|
req, &cfg.Matrix.ServerNotices,
|
||||||
).Methods(http.MethodPost, http.MethodOptions)
|
cfg, userAPI, rsAPI, accountDB, asAPI,
|
||||||
|
device, serverNotificationSender,
|
||||||
|
&txnID, transactionsCache,
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
).Methods(http.MethodPut, http.MethodOptions)
|
||||||
|
|
||||||
|
synapseAdminRouter.Handle("/admin/v1/send_server_notice",
|
||||||
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||||
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
||||||
|
if r := rateLimits.Limit(req); r != nil {
|
||||||
|
return *r
|
||||||
|
}
|
||||||
|
return SendServerNotice(
|
||||||
|
req, &cfg.Matrix.ServerNotices,
|
||||||
|
cfg, userAPI, rsAPI, accountDB, asAPI,
|
||||||
|
device, serverNotificationSender,
|
||||||
|
nil, transactionsCache,
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
).Methods(http.MethodPost, http.MethodOptions)
|
||||||
|
}
|
||||||
|
|
||||||
r0mux := publicAPIMux.PathPrefix("/r0").Subrouter()
|
r0mux := publicAPIMux.PathPrefix("/r0").Subrouter()
|
||||||
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ func SendServerNotice(
|
||||||
accountsDB accounts.Database,
|
accountsDB accounts.Database,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
|
senderDevice *userapi.Device,
|
||||||
txnID *string,
|
txnID *string,
|
||||||
txnCache *transactions.Cache,
|
txnCache *transactions.Cache,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
|
@ -139,15 +140,10 @@ func SendServerNotice(
|
||||||
roomVersion = gomatrixserverlib.RoomVersionV6
|
roomVersion = gomatrixserverlib.RoomVersionV6
|
||||||
)
|
)
|
||||||
|
|
||||||
senderDevice, err := getSenderDevice(ctx, userAPI, accountsDB, cfgClient)
|
|
||||||
if err != nil {
|
|
||||||
logrus.WithError(err).Error("unable to get device")
|
|
||||||
return util.ErrorResponse(err)
|
|
||||||
}
|
|
||||||
// create a new room for the user
|
// create a new room for the user
|
||||||
if len(commonRooms) == 0 {
|
if len(commonRooms) == 0 {
|
||||||
powerLevelContent := eventutil.InitialPowerLevelsContent(senderUserID)
|
powerLevelContent := eventutil.InitialPowerLevelsContent(senderUserID)
|
||||||
powerLevelContent.Users[r.UserID] = -10
|
powerLevelContent.Users[r.UserID] = -10 // taken from Synapse
|
||||||
pl, err := json.Marshal(powerLevelContent)
|
pl, err := json.Marshal(powerLevelContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue