mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 21:02:25 +03:00
refactor: update GMSL (#3058)
Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364 Read this commit by commit to avoid going insane.
This commit is contained in:
parent
9fa39263c0
commit
72285b2659
306 changed files with 2117 additions and 1934 deletions
|
@ -29,6 +29,7 @@ import (
|
|||
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -58,7 +59,7 @@ type TxnReq struct {
|
|||
gomatrixserverlib.Transaction
|
||||
rsAPI api.FederationRoomserverAPI
|
||||
userAPI userAPI.FederationUserAPI
|
||||
ourServerName gomatrixserverlib.ServerName
|
||||
ourServerName spec.ServerName
|
||||
keys gomatrixserverlib.JSONVerifier
|
||||
roomsMu *MutexByRoom
|
||||
producer *producers.SyncAPIProducer
|
||||
|
@ -68,16 +69,16 @@ type TxnReq struct {
|
|||
func NewTxnReq(
|
||||
rsAPI api.FederationRoomserverAPI,
|
||||
userAPI userAPI.FederationUserAPI,
|
||||
ourServerName gomatrixserverlib.ServerName,
|
||||
ourServerName spec.ServerName,
|
||||
keys gomatrixserverlib.JSONVerifier,
|
||||
roomsMu *MutexByRoom,
|
||||
producer *producers.SyncAPIProducer,
|
||||
inboundPresenceEnabled bool,
|
||||
pdus []json.RawMessage,
|
||||
edus []gomatrixserverlib.EDU,
|
||||
origin gomatrixserverlib.ServerName,
|
||||
origin spec.ServerName,
|
||||
transactionID gomatrixserverlib.TransactionID,
|
||||
destination gomatrixserverlib.ServerName,
|
||||
destination spec.ServerName,
|
||||
) TxnReq {
|
||||
t := TxnReq{
|
||||
rsAPI: rsAPI,
|
||||
|
@ -154,7 +155,7 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *ut
|
|||
util.GetLogger(ctx).WithError(err).Debugf("Transaction: Failed to parse event JSON of event %s", string(pdu))
|
||||
continue
|
||||
}
|
||||
if event.Type() == gomatrixserverlib.MRoomCreate && event.StateKeyEquals("") {
|
||||
if event.Type() == spec.MRoomCreate && event.StateKeyEquals("") {
|
||||
continue
|
||||
}
|
||||
if api.IsServerBannedFromRoom(ctx, t.rsAPI, event.RoomID(), t.Origin) {
|
||||
|
@ -207,7 +208,7 @@ func (t *TxnReq) processEDUs(ctx context.Context) {
|
|||
for _, e := range t.EDUs {
|
||||
EDUCountTotal.Inc()
|
||||
switch e.Type {
|
||||
case gomatrixserverlib.MTyping:
|
||||
case spec.MTyping:
|
||||
// https://matrix.org/docs/spec/server_server/latest#typing-notifications
|
||||
var typingPayload struct {
|
||||
RoomID string `json:"room_id"`
|
||||
|
@ -228,7 +229,7 @@ func (t *TxnReq) processEDUs(ctx context.Context) {
|
|||
if err := t.producer.SendTyping(ctx, typingPayload.UserID, typingPayload.RoomID, typingPayload.Typing, 30*1000); err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("Failed to send typing event to JetStream")
|
||||
}
|
||||
case gomatrixserverlib.MDirectToDevice:
|
||||
case spec.MDirectToDevice:
|
||||
// https://matrix.org/docs/spec/server_server/r0.1.3#m-direct-to-device-schema
|
||||
var directPayload gomatrixserverlib.ToDeviceMessage
|
||||
if err := json.Unmarshal(e.Content, &directPayload); err != nil {
|
||||
|
@ -255,12 +256,12 @@ func (t *TxnReq) processEDUs(ctx context.Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case gomatrixserverlib.MDeviceListUpdate:
|
||||
case spec.MDeviceListUpdate:
|
||||
if err := t.producer.SendDeviceListUpdate(ctx, e.Content, t.Origin); err != nil {
|
||||
sentry.CaptureException(err)
|
||||
util.GetLogger(ctx).WithError(err).Error("failed to InputDeviceListUpdate")
|
||||
}
|
||||
case gomatrixserverlib.MReceipt:
|
||||
case spec.MReceipt:
|
||||
// https://matrix.org/docs/spec/server_server/r0.1.4#receipts
|
||||
payload := map[string]types.FederationReceiptMRead{}
|
||||
|
||||
|
@ -296,7 +297,7 @@ func (t *TxnReq) processEDUs(ctx context.Context) {
|
|||
sentry.CaptureException(err)
|
||||
logrus.WithError(err).Errorf("Failed to process signing key update")
|
||||
}
|
||||
case gomatrixserverlib.MPresence:
|
||||
case spec.MPresence:
|
||||
if t.inboundPresenceEnabled {
|
||||
if err := t.processPresence(ctx, e); err != nil {
|
||||
logrus.WithError(err).Errorf("Failed to process presence update")
|
||||
|
@ -336,7 +337,7 @@ func (t *TxnReq) processPresence(ctx context.Context, e gomatrixserverlib.EDU) e
|
|||
// processReceiptEvent sends receipt events to JetStream
|
||||
func (t *TxnReq) processReceiptEvent(ctx context.Context,
|
||||
userID, roomID, receiptType string,
|
||||
timestamp gomatrixserverlib.Timestamp,
|
||||
timestamp spec.Timestamp,
|
||||
eventIDs []string,
|
||||
) error {
|
||||
if _, serverName, err := gomatrixserverlib.SplitID('@', userID); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue