Fix consumers in sync API
This commit is contained in:
parent
52ff26a608
commit
ad7b93ef81
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/streams"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -42,7 +41,6 @@ type OutputKeyChangeEventConsumer struct {
|
|||
db storage.Database
|
||||
notifier *notifier.Notifier
|
||||
stream streams.StreamProvider
|
||||
serverName gomatrixserverlib.ServerName // our server name
|
||||
rsAPI roomserverAPI.SyncRoomserverAPI
|
||||
}
|
||||
|
||||
|
@ -64,7 +62,6 @@ func NewOutputKeyChangeEventConsumer(
|
|||
durable: cfg.Matrix.JetStream.Durable("SyncAPIKeyChangeConsumer"),
|
||||
topic: topic,
|
||||
db: store,
|
||||
serverName: cfg.Matrix.ServerName,
|
||||
rsAPI: rsAPI,
|
||||
notifier: notifier,
|
||||
stream: stream,
|
||||
|
|
|
@ -41,7 +41,6 @@ type OutputReceiptEventConsumer struct {
|
|||
db storage.Database
|
||||
stream streams.StreamProvider
|
||||
notifier *notifier.Notifier
|
||||
serverName gomatrixserverlib.ServerName
|
||||
}
|
||||
|
||||
// NewOutputReceiptEventConsumer creates a new OutputReceiptEventConsumer.
|
||||
|
@ -62,7 +61,6 @@ func NewOutputReceiptEventConsumer(
|
|||
db: store,
|
||||
notifier: notifier,
|
||||
stream: stream,
|
||||
serverName: cfg.Matrix.ServerName,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -364,13 +364,9 @@ func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *gom
|
|||
// TODO: check that it's a join and not a profile change (means unmarshalling prev_content)
|
||||
if membership == gomatrixserverlib.Join {
|
||||
// check it's a local join
|
||||
_, domain, err := gomatrixserverlib.SplitID('@', *ev.StateKey())
|
||||
if err != nil {
|
||||
if _, _, err := s.cfg.Matrix.SplitLocalID('@', *ev.StateKey()); err != nil {
|
||||
return sp, fmt.Errorf("gomatrixserverlib.SplitID: %w", err)
|
||||
}
|
||||
if domain != s.cfg.Matrix.ServerName {
|
||||
return sp, nil
|
||||
}
|
||||
|
||||
// cancel any peeks for it
|
||||
peekSP, peekErr := s.db.DeletePeeks(ctx, ev.RoomID(), *ev.StateKey())
|
||||
|
@ -390,9 +386,7 @@ func (s *OutputRoomEventConsumer) onNewInviteEvent(
|
|||
if msg.Event.StateKey() == nil {
|
||||
return
|
||||
}
|
||||
if _, serverName, err := gomatrixserverlib.SplitID('@', *msg.Event.StateKey()); err != nil {
|
||||
return
|
||||
} else if serverName != s.cfg.Matrix.ServerName {
|
||||
if _, _, err := s.cfg.Matrix.SplitLocalID('@', *msg.Event.StateKey()); err != nil {
|
||||
return
|
||||
}
|
||||
pduPos, err := s.db.AddInviteEvent(ctx, msg.Event)
|
||||
|
|
|
@ -43,7 +43,7 @@ type OutputSendToDeviceEventConsumer struct {
|
|||
topic string
|
||||
db storage.Database
|
||||
keyAPI keyapi.SyncKeyAPI
|
||||
serverName gomatrixserverlib.ServerName // our server name
|
||||
isLocalServerName func(gomatrixserverlib.ServerName) bool
|
||||
stream streams.StreamProvider
|
||||
notifier *notifier.Notifier
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func NewOutputSendToDeviceEventConsumer(
|
|||
durable: cfg.Matrix.JetStream.Durable("SyncAPISendToDeviceConsumer"),
|
||||
db: store,
|
||||
keyAPI: keyAPI,
|
||||
serverName: cfg.Matrix.ServerName,
|
||||
isLocalServerName: cfg.Matrix.IsLocalServerName,
|
||||
notifier: notifier,
|
||||
stream: stream,
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func (s *OutputSendToDeviceEventConsumer) onMessage(ctx context.Context, msgs []
|
|||
log.WithError(err).Errorf("send-to-device: failed to split user id, dropping message")
|
||||
return true
|
||||
}
|
||||
if domain != s.serverName {
|
||||
if !s.isLocalServerName(domain) {
|
||||
log.Tracef("ignoring send-to-device event with destination %s", domain)
|
||||
return true
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ func (s *OutputSendToDeviceEventConsumer) onMessage(ctx context.Context, msgs []
|
|||
if output.Type == "m.room_key_request" {
|
||||
requestingDeviceID := gjson.GetBytes(output.SendToDeviceEvent.Content, "requesting_device_id").Str
|
||||
_, senderDomain, _ := gomatrixserverlib.SplitID('@', output.Sender)
|
||||
if requestingDeviceID != "" && senderDomain != s.serverName {
|
||||
if requestingDeviceID != "" && !s.isLocalServerName(senderDomain) {
|
||||
// Mark the requesting device as stale, if we don't know about it.
|
||||
if err = s.keyAPI.PerformMarkAsStaleIfNeeded(ctx, &keyapi.PerformMarkAsStaleRequest{
|
||||
UserID: output.Sender, Domain: senderDomain, DeviceID: requestingDeviceID,
|
||||
|
|
Loading…
Reference in a new issue