Update gmsl to use new validated RoomID on PDUs (#3200)
GMSL returns a `spec.RoomID` when calling `PDU.RoomID()`
This commit is contained in:
parent
058081e68e
commit
8245b24100
|
@ -128,7 +128,7 @@ func (s *OutputRoomEventConsumer) onMessage(
|
||||||
if len(output.NewRoomEvent.AddsStateEventIDs) > 0 {
|
if len(output.NewRoomEvent.AddsStateEventIDs) > 0 {
|
||||||
newEventID := output.NewRoomEvent.Event.EventID()
|
newEventID := output.NewRoomEvent.Event.EventID()
|
||||||
eventsReq := &api.QueryEventsByIDRequest{
|
eventsReq := &api.QueryEventsByIDRequest{
|
||||||
RoomID: output.NewRoomEvent.Event.RoomID(),
|
RoomID: output.NewRoomEvent.Event.RoomID().String(),
|
||||||
EventIDs: make([]string, 0, len(output.NewRoomEvent.AddsStateEventIDs)),
|
EventIDs: make([]string, 0, len(output.NewRoomEvent.AddsStateEventIDs)),
|
||||||
}
|
}
|
||||||
eventsRes := &api.QueryEventsByIDResponse{}
|
eventsRes := &api.QueryEventsByIDResponse{}
|
||||||
|
@ -236,11 +236,7 @@ func (s *appserviceState) backoffAndPause(err error) error {
|
||||||
// TODO: This should be cached, see https://github.com/matrix-org/dendrite/issues/1682
|
// TODO: This should be cached, see https://github.com/matrix-org/dendrite/issues/1682
|
||||||
func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Context, event *types.HeaderedEvent, appservice *config.ApplicationService) bool {
|
func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Context, event *types.HeaderedEvent, appservice *config.ApplicationService) bool {
|
||||||
user := ""
|
user := ""
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
userID, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
user = userID.String()
|
user = userID.String()
|
||||||
}
|
}
|
||||||
|
@ -250,7 +246,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
|
||||||
return false
|
return false
|
||||||
case appservice.IsInterestedInUserID(user):
|
case appservice.IsInterestedInUserID(user):
|
||||||
return true
|
return true
|
||||||
case appservice.IsInterestedInRoomID(event.RoomID()):
|
case appservice.IsInterestedInRoomID(event.RoomID().String()):
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +257,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all known room aliases of the room the event came from
|
// Check all known room aliases of the room the event came from
|
||||||
queryReq := api.GetAliasesForRoomIDRequest{RoomID: event.RoomID()}
|
queryReq := api.GetAliasesForRoomIDRequest{RoomID: event.RoomID().String()}
|
||||||
var queryRes api.GetAliasesForRoomIDResponse
|
var queryRes api.GetAliasesForRoomIDResponse
|
||||||
if err := s.rsAPI.GetAliasesForRoomID(ctx, &queryReq, &queryRes); err == nil {
|
if err := s.rsAPI.GetAliasesForRoomID(ctx, &queryReq, &queryRes); err == nil {
|
||||||
for _, alias := range queryRes.Aliases {
|
for _, alias := range queryRes.Aliases {
|
||||||
|
@ -272,7 +268,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
|
||||||
} else {
|
} else {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"appservice": appservice.ID,
|
"appservice": appservice.ID,
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
}).WithError(err).Errorf("Unable to get aliases for room")
|
}).WithError(err).Errorf("Unable to get aliases for room")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +284,7 @@ func (s *OutputRoomEventConsumer) appserviceJoinedAtEvent(ctx context.Context, e
|
||||||
// until we have a lighter way of checking the state before the event that
|
// until we have a lighter way of checking the state before the event that
|
||||||
// doesn't involve state res, then this is probably OK.
|
// doesn't involve state res, then this is probably OK.
|
||||||
membershipReq := &api.QueryMembershipsForRoomRequest{
|
membershipReq := &api.QueryMembershipsForRoomRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
JoinedOnly: true,
|
JoinedOnly: true,
|
||||||
}
|
}
|
||||||
membershipRes := &api.QueryMembershipsForRoomResponse{}
|
membershipRes := &api.QueryMembershipsForRoomResponse{}
|
||||||
|
@ -317,7 +313,7 @@ func (s *OutputRoomEventConsumer) appserviceJoinedAtEvent(ctx context.Context, e
|
||||||
} else {
|
} else {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"appservice": appservice.ID,
|
"appservice": appservice.ID,
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
}).WithError(err).Errorf("Unable to get membership for room")
|
}).WithError(err).Errorf("Unable to get membership for room")
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -98,7 +98,7 @@ func SendRedaction(
|
||||||
JSON: spec.NotFound("unknown event ID"), // TODO: is it ok to leak existence?
|
JSON: spec.NotFound("unknown event ID"), // TODO: is it ok to leak existence?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ev.RoomID() != roomID {
|
if ev.RoomID().String() != roomID {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 400,
|
Code: 400,
|
||||||
JSON: spec.NotFound("cannot redact event in another room"),
|
JSON: spec.NotFound("cannot redact event in another room"),
|
||||||
|
|
|
@ -437,7 +437,7 @@ func generateSendEvent(
|
||||||
JSON: spec.BadJSON("Cannot unmarshal the event content."),
|
JSON: spec.BadJSON("Cannot unmarshal the event content."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if content["replacement_room"] == e.RoomID() {
|
if content["replacement_room"] == e.RoomID().String() {
|
||||||
return nil, &util.JSONResponse{
|
return nil, &util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: spec.InvalidParam("Cannot send tombstone event that points to the same room."),
|
JSON: spec.InvalidParam("Cannot send tombstone event that points to the same room."),
|
||||||
|
|
|
@ -173,19 +173,14 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
|
||||||
}
|
}
|
||||||
for _, ev := range stateAfterRes.StateEvents {
|
for _, ev := range stateAfterRes.StateEvents {
|
||||||
sender := spec.UserID{}
|
sender := spec.UserID{}
|
||||||
evRoomID, err := spec.NewRoomID(ev.RoomID())
|
userID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
|
||||||
if err != nil {
|
|
||||||
util.GetLogger(ctx).WithError(err).Error("Event roomID is invalid")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
userID, err := rsAPI.QueryUserIDForSender(ctx, *evRoomID, ev.SenderID())
|
|
||||||
if err == nil && userID != nil {
|
if err == nil && userID != nil {
|
||||||
sender = *userID
|
sender = *userID
|
||||||
}
|
}
|
||||||
|
|
||||||
sk := ev.StateKey()
|
sk := ev.StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
skUserID, err := rsAPI.QueryUserIDForSender(ctx, *evRoomID, spec.SenderID(*ev.StateKey()))
|
skUserID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*ev.StateKey()))
|
||||||
if err == nil && skUserID != nil {
|
if err == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
|
|
@ -176,7 +176,7 @@ func (s *OutputRoomEventConsumer) processMessage(ore api.OutputNewRoomEvent, rew
|
||||||
// Finally, work out if there are any more events missing.
|
// Finally, work out if there are any more events missing.
|
||||||
if len(missingEventIDs) > 0 {
|
if len(missingEventIDs) > 0 {
|
||||||
eventsReq := &api.QueryEventsByIDRequest{
|
eventsReq := &api.QueryEventsByIDRequest{
|
||||||
RoomID: ore.Event.RoomID(),
|
RoomID: ore.Event.RoomID().String(),
|
||||||
EventIDs: missingEventIDs,
|
EventIDs: missingEventIDs,
|
||||||
}
|
}
|
||||||
eventsRes := &api.QueryEventsByIDResponse{}
|
eventsRes := &api.QueryEventsByIDResponse{}
|
||||||
|
@ -205,7 +205,7 @@ func (s *OutputRoomEventConsumer) processMessage(ore api.OutputNewRoomEvent, rew
|
||||||
// talking to the roomserver
|
// talking to the roomserver
|
||||||
oldJoinedHosts, err := s.db.UpdateRoom(
|
oldJoinedHosts, err := s.db.UpdateRoom(
|
||||||
s.ctx,
|
s.ctx,
|
||||||
ore.Event.RoomID(),
|
ore.Event.RoomID().String(),
|
||||||
addsJoinedHosts,
|
addsJoinedHosts,
|
||||||
ore.RemovesStateEventIDs,
|
ore.RemovesStateEventIDs,
|
||||||
rewritesState, // if we're re-writing state, nuke all joined hosts before adding
|
rewritesState, // if we're re-writing state, nuke all joined hosts before adding
|
||||||
|
@ -218,7 +218,7 @@ func (s *OutputRoomEventConsumer) processMessage(ore api.OutputNewRoomEvent, rew
|
||||||
if s.cfg.Matrix.Presence.EnableOutbound && len(addsJoinedHosts) > 0 && ore.Event.Type() == spec.MRoomMember && ore.Event.StateKey() != nil {
|
if s.cfg.Matrix.Presence.EnableOutbound && len(addsJoinedHosts) > 0 && ore.Event.Type() == spec.MRoomMember && ore.Event.StateKey() != nil {
|
||||||
membership, _ := ore.Event.Membership()
|
membership, _ := ore.Event.Membership()
|
||||||
if membership == spec.Join {
|
if membership == spec.Join {
|
||||||
s.sendPresence(ore.Event.RoomID(), addsJoinedHosts)
|
s.sendPresence(ore.Event.RoomID().String(), addsJoinedHosts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ func (s *OutputRoomEventConsumer) joinedHostsAtEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle peeking hosts
|
// handle peeking hosts
|
||||||
inboundPeeks, err := s.db.GetInboundPeeks(s.ctx, ore.Event.PDU.RoomID())
|
inboundPeeks, err := s.db.GetInboundPeeks(s.ctx, ore.Event.PDU.RoomID().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -409,12 +409,8 @@ func JoinedHostsFromEvents(ctx context.Context, evs []gomatrixserverlib.PDU, rsA
|
||||||
if membership != spec.Join {
|
if membership != spec.Join {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var domain spec.ServerName
|
var domain spec.ServerName
|
||||||
userID, err := rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*ev.StateKey()))
|
userID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*ev.StateKey()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.As(err, new(base64.CorruptInputError)) {
|
if errors.As(err, new(base64.CorruptInputError)) {
|
||||||
// Fallback to using the "old" way of getting the user domain, avoids
|
// Fallback to using the "old" way of getting the user domain, avoids
|
||||||
|
@ -510,7 +506,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
|
||||||
// At this point the missing events are neither the event itself nor are
|
// At this point the missing events are neither the event itself nor are
|
||||||
// they present in our local database. Our only option is to fetch them
|
// they present in our local database. Our only option is to fetch them
|
||||||
// from the roomserver using the query API.
|
// from the roomserver using the query API.
|
||||||
eventReq := api.QueryEventsByIDRequest{EventIDs: missing, RoomID: event.RoomID()}
|
eventReq := api.QueryEventsByIDRequest{EventIDs: missing, RoomID: event.RoomID().String()}
|
||||||
var eventResp api.QueryEventsByIDResponse
|
var eventResp api.QueryEventsByIDResponse
|
||||||
if err := s.rsAPI.QueryEventsByID(s.ctx, &eventReq, &eventResp); err != nil {
|
if err := s.rsAPI.QueryEventsByID(s.ctx, &eventReq, &eventResp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -146,7 +146,7 @@ func (f *fedClient) SendJoin(ctx context.Context, origin, s spec.ServerName, eve
|
||||||
f.fedClientMutex.Lock()
|
f.fedClientMutex.Lock()
|
||||||
defer f.fedClientMutex.Unlock()
|
defer f.fedClientMutex.Unlock()
|
||||||
for _, r := range f.allowJoins {
|
for _, r := range f.allowJoins {
|
||||||
if r.ID == event.RoomID() {
|
if r.ID == event.RoomID().String() {
|
||||||
r.InsertEvent(f.t, &types.HeaderedEvent{PDU: event})
|
r.InsertEvent(f.t, &types.HeaderedEvent{PDU: event})
|
||||||
f.t.Logf("Join event: %v", event.EventID())
|
f.t.Logf("Join event: %v", event.EventID())
|
||||||
res.StateEvents = types.NewEventJSONsFromHeaderedEvents(r.CurrentState())
|
res.StateEvents = types.NewEventJSONsFromHeaderedEvents(r.CurrentState())
|
||||||
|
|
|
@ -548,11 +548,7 @@ func (r *FederationInternalAPI) SendInvite(
|
||||||
event gomatrixserverlib.PDU,
|
event gomatrixserverlib.PDU,
|
||||||
strippedState []gomatrixserverlib.InviteStrippedState,
|
strippedState []gomatrixserverlib.InviteStrippedState,
|
||||||
) (gomatrixserverlib.PDU, error) {
|
) (gomatrixserverlib.PDU, error) {
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
inviter, err := r.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
inviter, err := r.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -575,7 +571,7 @@ func (r *FederationInternalAPI) SendInvite(
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"user_id": *event.StateKey(),
|
"user_id": *event.StateKey(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
"room_version": event.Version(),
|
"room_version": event.Version(),
|
||||||
"destination": destination,
|
"destination": destination,
|
||||||
}).Info("Sending invite")
|
}).Info("Sending invite")
|
||||||
|
|
|
@ -218,7 +218,7 @@ func (oqs *OutgoingQueues) SendEvent(
|
||||||
if api.IsServerBannedFromRoom(
|
if api.IsServerBannedFromRoom(
|
||||||
oqs.process.Context(),
|
oqs.process.Context(),
|
||||||
oqs.rsAPI,
|
oqs.rsAPI,
|
||||||
ev.RoomID(),
|
ev.RoomID().String(),
|
||||||
destination,
|
destination,
|
||||||
) {
|
) {
|
||||||
delete(destmap, destination)
|
delete(destmap, destination)
|
||||||
|
|
|
@ -104,7 +104,7 @@ func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u
|
||||||
|
|
||||||
func mustCreatePDU(t *testing.T) *types.HeaderedEvent {
|
func mustCreatePDU(t *testing.T) *types.HeaderedEvent {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
content := `{"type":"m.room.message"}`
|
content := `{"type":"m.room.message", "room_id":"!room:a"}`
|
||||||
ev, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV10).NewEventFromTrustedJSON([]byte(content), false)
|
ev, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV10).NewEventFromTrustedJSON([]byte(content), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create event: %v", err)
|
t.Fatalf("failed to create event: %v", err)
|
||||||
|
|
|
@ -109,7 +109,7 @@ func Backfill(
|
||||||
|
|
||||||
var ev *types.HeaderedEvent
|
var ev *types.HeaderedEvent
|
||||||
for _, ev = range res.Events {
|
for _, ev = range res.Events {
|
||||||
if ev.RoomID() == roomID {
|
if ev.RoomID().String() == roomID {
|
||||||
evs = append(evs, ev.PDU)
|
evs = append(evs, ev.PDU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,10 @@ func GetEventAuth(
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.RoomID() != roomID {
|
if event.RoomID().String() != roomID {
|
||||||
return util.JSONResponse{Code: http.StatusNotFound, JSON: spec.NotFound("event does not belong to this room")}
|
return util.JSONResponse{Code: http.StatusNotFound, JSON: spec.NotFound("event does not belong to this room")}
|
||||||
}
|
}
|
||||||
resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID())
|
resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID().String())
|
||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func GetEvent(
|
||||||
return *err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID())
|
err = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,7 @@ func SendLeave(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the room ID is correct.
|
// Check that the room ID is correct.
|
||||||
if event.RoomID() != roomID {
|
if event.RoomID().String() != roomID {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: spec.BadJSON("The room ID in the request path must match the room ID in the leave event JSON"),
|
JSON: spec.BadJSON("The room ID in the request path must match the room ID in the leave event JSON"),
|
||||||
|
@ -242,14 +242,7 @@ func SendLeave(
|
||||||
// Check that the sender belongs to the server that is sending us
|
// Check that the sender belongs to the server that is sending us
|
||||||
// the request. By this point we've already asserted that the sender
|
// the request. By this point we've already asserted that the sender
|
||||||
// and the state key are equal so we don't need to check both.
|
// and the state key are equal so we don't need to check both.
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
sender, err := rsAPI.QueryUserIDForSender(httpReq.Context(), event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusBadRequest,
|
|
||||||
JSON: spec.BadJSON("Room ID is invalid."),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sender, err := rsAPI.QueryUserIDForSender(httpReq.Context(), *validRoomID, event.SenderID())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
|
|
|
@ -87,7 +87,7 @@ func filterEvents(
|
||||||
) []*types.HeaderedEvent {
|
) []*types.HeaderedEvent {
|
||||||
ref := events[:0]
|
ref := events[:0]
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
if ev.RoomID() == roomID {
|
if ev.RoomID().String() == roomID {
|
||||||
ref = append(ref, ev)
|
ref = append(ref, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,10 +113,10 @@ func getState(
|
||||||
return nil, nil, resErr
|
return nil, nil, resErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.RoomID() != roomID {
|
if event.RoomID().String() != roomID {
|
||||||
return nil, nil, &util.JSONResponse{Code: http.StatusNotFound, JSON: spec.NotFound("event does not belong to this room")}
|
return nil, nil, &util.JSONResponse{Code: http.StatusNotFound, JSON: spec.NotFound("event does not belong to this room")}
|
||||||
}
|
}
|
||||||
resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID())
|
resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID().String())
|
||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
return nil, nil, resErr
|
return nil, nil, resErr
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -22,7 +22,7 @@ require (
|
||||||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230908150629-47bceffecd9e
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230915142004-095d10f3a87a
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7
|
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
||||||
github.com/mattn/go-sqlite3 v1.14.17
|
github.com/mattn/go-sqlite3 v1.14.17
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -208,8 +208,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
|
||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230908150629-47bceffecd9e h1:WSqq/Pk+4Tna2F7zxEXMPrlZUAfBep3Y2gFbPhKgJHs=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230915142004-095d10f3a87a h1:+RC9Ddmt5v4y58qmdz5WuEEWCJ9gBWuYLyndnWkGfXU=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230908150629-47bceffecd9e/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230915142004-095d10f3a87a/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 h1:6t8kJr8i1/1I5nNttw6nn1ryQJgzVlBmSGgPiiaTdw4=
|
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 h1:6t8kJr8i1/1I5nNttw6nn1ryQJgzVlBmSGgPiiaTdw4=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg=
|
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg=
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
||||||
|
|
|
@ -176,11 +176,7 @@ func RedactEvent(ctx context.Context, redactionEvent, redactedEvent gomatrixserv
|
||||||
return fmt.Errorf("RedactEvent: redactionEvent isn't a redaction event, is '%s'", redactionEvent.Type())
|
return fmt.Errorf("RedactEvent: redactionEvent isn't a redaction event, is '%s'", redactionEvent.Type())
|
||||||
}
|
}
|
||||||
redactedEvent.Redact()
|
redactedEvent.Redact()
|
||||||
validRoomID, err := spec.NewRoomID(redactionEvent.RoomID())
|
senderID, err := querier.QueryUserIDForSender(ctx, redactedEvent.RoomID(), redactionEvent.SenderID())
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
senderID, err := querier.QueryUserIDForSender(ctx, *validRoomID, redactionEvent.SenderID())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,15 +111,11 @@ func ruleMatches(rule *Rule, kind Kind, event gomatrixserverlib.PDU, ec Evaluati
|
||||||
return patternMatches("content.body", *rule.Pattern, event)
|
return patternMatches("content.body", *rule.Pattern, event)
|
||||||
|
|
||||||
case RoomKind:
|
case RoomKind:
|
||||||
return rule.RuleID == event.RoomID(), nil
|
return rule.RuleID == event.RoomID().String(), nil
|
||||||
|
|
||||||
case SenderKind:
|
case SenderKind:
|
||||||
userID := ""
|
userID := ""
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
sender, err := userIDForSender(event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
sender, err := userIDForSender(*validRoomID, event.SenderID())
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userID = sender.String()
|
userID = sender.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ func UserIDForSender(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRuleSetEvaluatorMatchEvent(t *testing.T) {
|
func TestRuleSetEvaluatorMatchEvent(t *testing.T) {
|
||||||
ev := mustEventFromJSON(t, `{}`)
|
ev := mustEventFromJSON(t, `{"room_id":"!room:a"}`)
|
||||||
defaultEnabled := &Rule{
|
defaultEnabled := &Rule{
|
||||||
RuleID: ".default.enabled",
|
RuleID: ".default.enabled",
|
||||||
Default: true,
|
Default: true,
|
||||||
|
@ -44,8 +44,8 @@ func TestRuleSetEvaluatorMatchEvent(t *testing.T) {
|
||||||
{"overrideRoom", RuleSet{Override: []*Rule{userEnabled}, Room: []*Rule{userEnabled2}}, userEnabled, ev},
|
{"overrideRoom", RuleSet{Override: []*Rule{userEnabled}, Room: []*Rule{userEnabled2}}, userEnabled, ev},
|
||||||
{"overrideSender", RuleSet{Override: []*Rule{userEnabled}, Sender: []*Rule{userEnabled2}}, userEnabled, ev},
|
{"overrideSender", RuleSet{Override: []*Rule{userEnabled}, Sender: []*Rule{userEnabled2}}, userEnabled, ev},
|
||||||
{"overrideUnderride", RuleSet{Override: []*Rule{userEnabled}, Underride: []*Rule{userEnabled2}}, userEnabled, ev},
|
{"overrideUnderride", RuleSet{Override: []*Rule{userEnabled}, Underride: []*Rule{userEnabled2}}, userEnabled, ev},
|
||||||
{"reactions don't notify", *defaultRuleset, &mRuleReactionDefinition, mustEventFromJSON(t, `{"type":"m.reaction"}`)},
|
{"reactions don't notify", *defaultRuleset, &mRuleReactionDefinition, mustEventFromJSON(t, `{"room_id":"!room:a","type":"m.reaction"}`)},
|
||||||
{"receipts don't notify", *defaultRuleset, nil, mustEventFromJSON(t, `{"type":"m.receipt"}`)},
|
{"receipts don't notify", *defaultRuleset, nil, mustEventFromJSON(t, `{"room_id":"!room:a","type":"m.receipt"}`)},
|
||||||
}
|
}
|
||||||
for _, tst := range tsts {
|
for _, tst := range tsts {
|
||||||
t.Run(tst.Name, func(t *testing.T) {
|
t.Run(tst.Name, func(t *testing.T) {
|
||||||
|
@ -70,28 +70,27 @@ func TestRuleMatches(t *testing.T) {
|
||||||
EventJSON string
|
EventJSON string
|
||||||
Want bool
|
Want bool
|
||||||
}{
|
}{
|
||||||
{"emptyOverride", OverrideKind, emptyRule, `{}`, true},
|
{"emptyOverride", OverrideKind, emptyRule, `{"room_id":"!room:example.com"}`, true},
|
||||||
{"emptyContent", ContentKind, emptyRule, `{}`, false},
|
{"emptyContent", ContentKind, emptyRule, `{"room_id":"!room:example.com"}`, false},
|
||||||
{"emptyRoom", RoomKind, emptyRule, `{}`, true},
|
|
||||||
{"emptySender", SenderKind, emptyRule, `{"room_id":"!room:example.com"}`, true},
|
{"emptySender", SenderKind, emptyRule, `{"room_id":"!room:example.com"}`, true},
|
||||||
{"emptyUnderride", UnderrideKind, emptyRule, `{}`, true},
|
{"emptyUnderride", UnderrideKind, emptyRule, `{"room_id":"!room:example.com"}`, true},
|
||||||
|
|
||||||
{"disabled", OverrideKind, Rule{}, `{}`, false},
|
{"disabled", OverrideKind, Rule{}, `{"room_id":"!room:example.com"}`, false},
|
||||||
|
|
||||||
{"overrideConditionMatch", OverrideKind, Rule{Enabled: true}, `{}`, true},
|
{"overrideConditionMatch", OverrideKind, Rule{Enabled: true}, `{"room_id":"!room:example.com"}`, true},
|
||||||
{"overrideConditionNoMatch", OverrideKind, Rule{Enabled: true, Conditions: []*Condition{{}}}, `{}`, false},
|
{"overrideConditionNoMatch", OverrideKind, Rule{Enabled: true, Conditions: []*Condition{{}}}, `{"room_id":"!room:example.com"}`, false},
|
||||||
|
|
||||||
{"underrideConditionMatch", UnderrideKind, Rule{Enabled: true}, `{}`, true},
|
{"underrideConditionMatch", UnderrideKind, Rule{Enabled: true}, `{"room_id":"!room:example.com"}`, true},
|
||||||
{"underrideConditionNoMatch", UnderrideKind, Rule{Enabled: true, Conditions: []*Condition{{}}}, `{}`, false},
|
{"underrideConditionNoMatch", UnderrideKind, Rule{Enabled: true, Conditions: []*Condition{{}}}, `{"room_id":"!room:example.com"}`, false},
|
||||||
|
|
||||||
{"contentMatch", ContentKind, Rule{Enabled: true, Pattern: pointer("b")}, `{"content":{"body":"abc"}}`, true},
|
{"contentMatch", ContentKind, Rule{Enabled: true, Pattern: pointer("b")}, `{"room_id":"!room:example.com","content":{"body":"abc"}}`, true},
|
||||||
{"contentNoMatch", ContentKind, Rule{Enabled: true, Pattern: pointer("d")}, `{"content":{"body":"abc"}}`, false},
|
{"contentNoMatch", ContentKind, Rule{Enabled: true, Pattern: pointer("d")}, `{"room_id":"!room:example.com","content":{"body":"abc"}}`, false},
|
||||||
|
|
||||||
{"roomMatch", RoomKind, Rule{Enabled: true, RuleID: "!room:example.com"}, `{"room_id":"!room:example.com"}`, true},
|
{"roomMatch", RoomKind, Rule{Enabled: true, RuleID: "!room:example.com"}, `{"room_id":"!room:example.com"}`, true},
|
||||||
{"roomNoMatch", RoomKind, Rule{Enabled: true, RuleID: "!room:example.com"}, `{"room_id":"!otherroom:example.com"}`, false},
|
{"roomNoMatch", RoomKind, Rule{Enabled: true, RuleID: "!room:example.com"}, `{"room_id":"!otherroom:example.com"}`, false},
|
||||||
|
|
||||||
{"senderMatch", SenderKind, Rule{Enabled: true, RuleID: "@user:example.com"}, `{"sender":"@user:example.com","room_id":"!room:example.com"}`, true},
|
{"senderMatch", SenderKind, Rule{Enabled: true, RuleID: "@user:example.com"}, `{"room_id":"!room:example.com","sender":"@user:example.com","room_id":"!room:example.com"}`, true},
|
||||||
{"senderNoMatch", SenderKind, Rule{Enabled: true, RuleID: "@user:example.com"}, `{"sender":"@otheruser:example.com","room_id":"!room:example.com"}`, false},
|
{"senderNoMatch", SenderKind, Rule{Enabled: true, RuleID: "@user:example.com"}, `{"room_id":"!room:example.com","sender":"@otheruser:example.com","room_id":"!room:example.com"}`, false},
|
||||||
}
|
}
|
||||||
for _, tst := range tsts {
|
for _, tst := range tsts {
|
||||||
t.Run(tst.Name, func(t *testing.T) {
|
t.Run(tst.Name, func(t *testing.T) {
|
||||||
|
@ -114,32 +113,32 @@ func TestConditionMatches(t *testing.T) {
|
||||||
WantMatch bool
|
WantMatch bool
|
||||||
WantErr bool
|
WantErr bool
|
||||||
}{
|
}{
|
||||||
{Name: "empty", Cond: Condition{}, EventJSON: `{}`, WantMatch: false, WantErr: false},
|
{Name: "empty", Cond: Condition{}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "empty", Cond: Condition{Kind: "unknownstring"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
|
{Name: "empty", Cond: Condition{Kind: "unknownstring"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
|
|
||||||
// Neither of these should match because `content` is not a full string match,
|
// Neither of these should match because `content` is not a full string match,
|
||||||
// and `content.body` is not a string value.
|
// and `content.body` is not a string value.
|
||||||
{Name: "eventMatch", Cond: Condition{Kind: EventMatchCondition, Key: "content", Pattern: pointer("")}, EventJSON: `{"content":{}}`, WantMatch: false, WantErr: false},
|
{Name: "eventMatch", Cond: Condition{Kind: EventMatchCondition, Key: "content", Pattern: pointer("")}, EventJSON: `{"room_id":"!room:example.com","content":{}}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "eventBodyMatch", Cond: Condition{Kind: EventMatchCondition, Key: "content.body", Is: "3", Pattern: pointer("")}, EventJSON: `{"content":{"body": "3"}}`, WantMatch: false, WantErr: false},
|
{Name: "eventBodyMatch", Cond: Condition{Kind: EventMatchCondition, Key: "content.body", Is: "3", Pattern: pointer("")}, EventJSON: `{"room_id":"!room:example.com","content":{"body": "3"}}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "eventBodyMatch matches", Cond: Condition{Kind: EventMatchCondition, Key: "content.body", Pattern: pointer("world")}, EventJSON: `{"content":{"body": "hello world!"}}`, WantMatch: true, WantErr: false},
|
{Name: "eventBodyMatch matches", Cond: Condition{Kind: EventMatchCondition, Key: "content.body", Pattern: pointer("world")}, EventJSON: `{"room_id":"!room:example.com","content":{"body": "hello world!"}}`, WantMatch: true, WantErr: false},
|
||||||
{Name: "EventMatch missing pattern", Cond: Condition{Kind: EventMatchCondition, Key: "content.body"}, EventJSON: `{"content":{"body": "hello world!"}}`, WantMatch: false, WantErr: true},
|
{Name: "EventMatch missing pattern", Cond: Condition{Kind: EventMatchCondition, Key: "content.body"}, EventJSON: `{"room_id":"!room:example.com","content":{"body": "hello world!"}}`, WantMatch: false, WantErr: true},
|
||||||
|
|
||||||
{Name: "displayNameNoMatch", Cond: Condition{Kind: ContainsDisplayNameCondition}, EventJSON: `{"content":{"body":"something without displayname"}}`, WantMatch: false, WantErr: false},
|
{Name: "displayNameNoMatch", Cond: Condition{Kind: ContainsDisplayNameCondition}, EventJSON: `{"room_id":"!room:example.com","content":{"body":"something without displayname"}}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "displayNameMatch", Cond: Condition{Kind: ContainsDisplayNameCondition}, EventJSON: `{"content":{"body":"hello Dear User, how are you?"}}`, WantMatch: true, WantErr: false},
|
{Name: "displayNameMatch", Cond: Condition{Kind: ContainsDisplayNameCondition}, EventJSON: `{"room_id":"!room:example.com","content":{"body":"hello Dear User, how are you?"}}`, WantMatch: true, WantErr: false},
|
||||||
|
|
||||||
{Name: "roomMemberCountLessNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<2"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
|
{Name: "roomMemberCountLessNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<2"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "roomMemberCountLessMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<3"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
|
{Name: "roomMemberCountLessMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<3"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: true, WantErr: false},
|
||||||
{Name: "roomMemberCountLessEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<=1"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
|
{Name: "roomMemberCountLessEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<=1"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "roomMemberCountLessEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<=2"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
|
{Name: "roomMemberCountLessEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<=2"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: true, WantErr: false},
|
||||||
{Name: "roomMemberCountEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "==1"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
|
{Name: "roomMemberCountEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "==1"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "roomMemberCountEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "==2"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
|
{Name: "roomMemberCountEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "==2"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: true, WantErr: false},
|
||||||
{Name: "roomMemberCountGreaterEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">=3"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
|
{Name: "roomMemberCountGreaterEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">=3"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "roomMemberCountGreaterEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">=2"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
|
{Name: "roomMemberCountGreaterEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">=2"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: true, WantErr: false},
|
||||||
{Name: "roomMemberCountGreaterNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">2"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
|
{Name: "roomMemberCountGreaterNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">2"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
{Name: "roomMemberCountGreaterMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">1"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
|
{Name: "roomMemberCountGreaterMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">1"}, EventJSON: `{"room_id":"!room:example.com"}`, WantMatch: true, WantErr: false},
|
||||||
|
|
||||||
{Name: "senderNotificationPermissionMatch", Cond: Condition{Kind: SenderNotificationPermissionCondition, Key: "powerlevel"}, EventJSON: `{"sender":"@poweruser:example.com"}`, WantMatch: true, WantErr: false},
|
{Name: "senderNotificationPermissionMatch", Cond: Condition{Kind: SenderNotificationPermissionCondition, Key: "powerlevel"}, EventJSON: `{"room_id":"!room:example.com","sender":"@poweruser:example.com"}`, WantMatch: true, WantErr: false},
|
||||||
{Name: "senderNotificationPermissionNoMatch", Cond: Condition{Kind: SenderNotificationPermissionCondition, Key: "powerlevel"}, EventJSON: `{"sender":"@nobody:example.com"}`, WantMatch: false, WantErr: false},
|
{Name: "senderNotificationPermissionNoMatch", Cond: Condition{Kind: SenderNotificationPermissionCondition, Key: "powerlevel"}, EventJSON: `{"room_id":"!room:example.com","sender":"@nobody:example.com"}`, WantMatch: false, WantErr: false},
|
||||||
}
|
}
|
||||||
for _, tst := range tsts {
|
for _, tst := range tsts {
|
||||||
t.Run(tst.Name, func(t *testing.T) {
|
t.Run(tst.Name, func(t *testing.T) {
|
||||||
|
@ -170,15 +169,15 @@ func TestPatternMatches(t *testing.T) {
|
||||||
EventJSON string
|
EventJSON string
|
||||||
Want bool
|
Want bool
|
||||||
}{
|
}{
|
||||||
{"empty", "", "", `{}`, false},
|
{"empty", "", "", `{"room_id":"!room:a"}`, false},
|
||||||
|
|
||||||
{"patternEmpty", "content", "", `{"content":{}}`, false},
|
{"patternEmpty", "content", "", `{"room_id":"!room:a","content":{}}`, false},
|
||||||
|
|
||||||
{"literal", "content.creator", "acreator", `{"content":{"creator":"acreator"}}`, true},
|
{"literal", "content.creator", "acreator", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
|
||||||
{"substring", "content.creator", "reat", `{"content":{"creator":"acreator"}}`, true},
|
{"substring", "content.creator", "reat", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
|
||||||
{"singlePattern", "content.creator", "acr?ator", `{"content":{"creator":"acreator"}}`, true},
|
{"singlePattern", "content.creator", "acr?ator", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
|
||||||
{"multiPattern", "content.creator", "a*ea*r", `{"content":{"creator":"acreator"}}`, true},
|
{"multiPattern", "content.creator", "a*ea*r", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
|
||||||
{"patternNoSubstring", "content.creator", "r*t", `{"content":{"creator":"acreator"}}`, false},
|
{"patternNoSubstring", "content.creator", "r*t", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, false},
|
||||||
}
|
}
|
||||||
for _, tst := range tsts {
|
for _, tst := range tsts {
|
||||||
t.Run(tst.Name, func(t *testing.T) {
|
t.Run(tst.Name, func(t *testing.T) {
|
||||||
|
|
|
@ -161,7 +161,7 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *ut
|
||||||
if event.Type() == spec.MRoomCreate && event.StateKeyEquals("") {
|
if event.Type() == spec.MRoomCreate && event.StateKeyEquals("") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if api.IsServerBannedFromRoom(ctx, t.rsAPI, event.RoomID(), t.Origin) {
|
if api.IsServerBannedFromRoom(ctx, t.rsAPI, event.RoomID().String(), t.Origin) {
|
||||||
results[event.EventID()] = fclient.PDUResult{
|
results[event.EventID()] = fclient.PDUResult{
|
||||||
Error: "Forbidden by server ACLs",
|
Error: "Forbidden by server ACLs",
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ func (s *ServerACLs) OnServerACLUpdate(state gomatrixserverlib.PDU) {
|
||||||
}).Debugf("Updating server ACLs for %q", state.RoomID())
|
}).Debugf("Updating server ACLs for %q", state.RoomID())
|
||||||
s.aclsMutex.Lock()
|
s.aclsMutex.Lock()
|
||||||
defer s.aclsMutex.Unlock()
|
defer s.aclsMutex.Unlock()
|
||||||
s.acls[state.RoomID()] = acls
|
s.acls[state.RoomID().String()] = acls
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerACLs) IsServerBannedFromRoom(serverName spec.ServerName, roomID string) bool {
|
func (s *ServerACLs) IsServerBannedFromRoom(serverName spec.ServerName, roomID string) bool {
|
||||||
|
|
|
@ -75,7 +75,7 @@ func SendEventWithState(
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.WithContext(ctx).WithFields(logrus.Fields{
|
logrus.WithContext(ctx).WithFields(logrus.Fields{
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"outliers": len(ires),
|
"outliers": len(ires),
|
||||||
"state_ids": len(stateEventIDs),
|
"state_ids": len(stateEventIDs),
|
||||||
|
|
|
@ -85,11 +85,7 @@ func IsAnyUserOnServerWithMembership(ctx context.Context, querier api.QuerySende
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
userID, err := querier.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*stateKey))
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
userID, err := querier.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*stateKey))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(ctx context.Context, senderID sp
|
||||||
|
|
||||||
proto := &gomatrixserverlib.ProtoEvent{
|
proto := &gomatrixserverlib.ProtoEvent{
|
||||||
SenderID: string(canonicalSenderID),
|
SenderID: string(canonicalSenderID),
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID().String(),
|
||||||
Type: ev.Type(),
|
Type: ev.Type(),
|
||||||
StateKey: ev.StateKey(),
|
StateKey: ev.StateKey(),
|
||||||
Content: res,
|
Content: res,
|
||||||
|
|
|
@ -239,7 +239,7 @@ func (r *RoomserverInternalAPI) HandleInvite(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return r.OutputProducer.ProduceRoomEvents(inviteEvent.RoomID(), outputEvents)
|
return r.OutputProducer.ProduceRoomEvents(inviteEvent.RoomID().String(), outputEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoomserverInternalAPI) PerformCreateRoom(
|
func (r *RoomserverInternalAPI) PerformCreateRoom(
|
||||||
|
|
|
@ -218,9 +218,9 @@ func loadAuthEvents(
|
||||||
roomID := ""
|
roomID := ""
|
||||||
for _, ev := range result.events {
|
for _, ev := range result.events {
|
||||||
if roomID == "" {
|
if roomID == "" {
|
||||||
roomID = ev.RoomID()
|
roomID = ev.RoomID().String()
|
||||||
}
|
}
|
||||||
if ev.RoomID() != roomID {
|
if ev.RoomID().String() != roomID {
|
||||||
result.valid = false
|
result.valid = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ func UpdateToInviteMembership(
|
||||||
Type: api.OutputTypeRetireInviteEvent,
|
Type: api.OutputTypeRetireInviteEvent,
|
||||||
RetireInviteEvent: &api.OutputRetireInviteEvent{
|
RetireInviteEvent: &api.OutputRetireInviteEvent{
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
RoomID: add.RoomID(),
|
RoomID: add.RoomID().String(),
|
||||||
Membership: spec.Join,
|
Membership: spec.Join,
|
||||||
RetiredByEventID: add.EventID(),
|
RetiredByEventID: add.EventID(),
|
||||||
TargetSenderID: spec.SenderID(*add.StateKey()),
|
TargetSenderID: spec.SenderID(*add.StateKey()),
|
||||||
|
@ -396,7 +396,7 @@ BFSLoop:
|
||||||
// It's nasty that we have to extract the room ID from an event, but many federation requests
|
// It's nasty that we have to extract the room ID from an event, but many federation requests
|
||||||
// only talk in event IDs, no room IDs at all (!!!)
|
// only talk in event IDs, no room IDs at all (!!!)
|
||||||
ev := events[0]
|
ev := events[0]
|
||||||
isServerInRoom, err = IsServerCurrentlyInRoom(ctx, db, querier, serverName, ev.RoomID())
|
isServerInRoom, err = IsServerCurrentlyInRoom(ctx, db, querier, serverName, ev.RoomID().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Error("Failed to check if server is currently in room, assuming not.")
|
util.GetLogger(ctx).WithError(err).Error("Failed to check if server is currently in room, assuming not.")
|
||||||
}
|
}
|
||||||
|
@ -419,7 +419,7 @@ BFSLoop:
|
||||||
// hasn't been seen before.
|
// hasn't been seen before.
|
||||||
if !visited[pre] {
|
if !visited[pre] {
|
||||||
visited[pre] = true
|
visited[pre] = true
|
||||||
allowed, err = CheckServerAllowedToSeeEvent(ctx, db, info, ev.RoomID(), pre, serverName, isServerInRoom, querier)
|
allowed, err = CheckServerAllowedToSeeEvent(ctx, db, info, ev.RoomID().String(), pre, serverName, isServerInRoom, querier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(ctx).WithField("server", serverName).WithField("event_id", pre).WithError(err).Error(
|
util.GetLogger(ctx).WithField("server", serverName).WithField("event_id", pre).WithError(err).Error(
|
||||||
"Error checking if allowed to see event",
|
"Error checking if allowed to see event",
|
||||||
|
|
|
@ -358,7 +358,7 @@ func (r *Inputer) queueInputRoomEvents(
|
||||||
// For each event, marshal the input room event and then
|
// For each event, marshal the input room event and then
|
||||||
// send it into the input queue.
|
// send it into the input queue.
|
||||||
for _, e := range request.InputRoomEvents {
|
for _, e := range request.InputRoomEvents {
|
||||||
roomID := e.Event.RoomID()
|
roomID := e.Event.RoomID().String()
|
||||||
subj := r.Cfg.Matrix.JetStream.Prefixed(jetstream.InputRoomEventSubj(roomID))
|
subj := r.Cfg.Matrix.JetStream.Prefixed(jetstream.InputRoomEventSubj(roomID))
|
||||||
msg := &nats.Msg{
|
msg := &nats.Msg{
|
||||||
Subject: subj,
|
Subject: subj,
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
trace, ctx := internal.StartRegion(ctx, "processRoomEvent")
|
trace, ctx := internal.StartRegion(ctx, "processRoomEvent")
|
||||||
trace.SetTag("room_id", input.Event.RoomID())
|
trace.SetTag("room_id", input.Event.RoomID().String())
|
||||||
trace.SetTag("event_id", input.Event.EventID())
|
trace.SetTag("event_id", input.Event.EventID())
|
||||||
defer trace.EndRegion()
|
defer trace.EndRegion()
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
defer func() {
|
defer func() {
|
||||||
timetaken := time.Since(started)
|
timetaken := time.Since(started)
|
||||||
processRoomEventDuration.With(prometheus.Labels{
|
processRoomEventDuration.With(prometheus.Labels{
|
||||||
"room_id": input.Event.RoomID(),
|
"room_id": input.Event.RoomID().String(),
|
||||||
}).Observe(float64(timetaken.Milliseconds()))
|
}).Observe(float64(timetaken.Milliseconds()))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
event := headered.PDU
|
event := headered.PDU
|
||||||
logger := util.GetLogger(ctx).WithFields(logrus.Fields{
|
logger := util.GetLogger(ctx).WithFields(logrus.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
"kind": input.Kind,
|
"kind": input.Kind,
|
||||||
"origin": input.Origin,
|
"origin": input.Origin,
|
||||||
"type": event.Type(),
|
"type": event.Type(),
|
||||||
|
@ -120,19 +120,15 @@ func (r *Inputer) processRoomEvent(
|
||||||
// Don't waste time processing the event if the room doesn't exist.
|
// Don't waste time processing the event if the room doesn't exist.
|
||||||
// A room entry locally will only be created in response to a create
|
// A room entry locally will only be created in response to a create
|
||||||
// event.
|
// event.
|
||||||
roomInfo, rerr := r.DB.RoomInfo(ctx, event.RoomID())
|
roomInfo, rerr := r.DB.RoomInfo(ctx, event.RoomID().String())
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
return fmt.Errorf("r.DB.RoomInfo: %w", rerr)
|
return fmt.Errorf("r.DB.RoomInfo: %w", rerr)
|
||||||
}
|
}
|
||||||
isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
|
isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
|
||||||
if roomInfo == nil && !isCreateEvent {
|
if roomInfo == nil && !isCreateEvent {
|
||||||
return fmt.Errorf("room %s does not exist for event %s", event.RoomID(), event.EventID())
|
return fmt.Errorf("room %s does not exist for event %s", event.RoomID().String(), event.EventID())
|
||||||
}
|
}
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
sender, err := r.Queryer.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
sender, err := r.Queryer.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed getting userID for sender %q. %w", event.SenderID(), err)
|
return fmt.Errorf("failed getting userID for sender %q. %w", event.SenderID(), err)
|
||||||
}
|
}
|
||||||
|
@ -179,7 +175,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
// If we have missing events (auth or prev), we build a list of servers to ask
|
// If we have missing events (auth or prev), we build a list of servers to ask
|
||||||
if missingAuth || missingPrev {
|
if missingAuth || missingPrev {
|
||||||
serverReq := &fedapi.QueryJoinedHostServerNamesInRoomRequest{
|
serverReq := &fedapi.QueryJoinedHostServerNamesInRoomRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
ExcludeSelf: true,
|
ExcludeSelf: true,
|
||||||
ExcludeBlacklisted: true,
|
ExcludeBlacklisted: true,
|
||||||
}
|
}
|
||||||
|
@ -395,12 +391,12 @@ func (r *Inputer) processRoomEvent(
|
||||||
|
|
||||||
// Request the room info again — it's possible that the room has been
|
// Request the room info again — it's possible that the room has been
|
||||||
// created by now if it didn't exist already.
|
// created by now if it didn't exist already.
|
||||||
roomInfo, err = r.DB.RoomInfo(ctx, event.RoomID())
|
roomInfo, err = r.DB.RoomInfo(ctx, event.RoomID().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("updater.RoomInfo: %w", err)
|
return fmt.Errorf("updater.RoomInfo: %w", err)
|
||||||
}
|
}
|
||||||
if roomInfo == nil {
|
if roomInfo == nil {
|
||||||
return fmt.Errorf("updater.RoomInfo missing for room %s", event.RoomID())
|
return fmt.Errorf("updater.RoomInfo missing for room %s", event.RoomID().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.HasState || (!missingPrev && stateAtEvent.BeforeStateSnapshotNID == 0) {
|
if input.HasState || (!missingPrev && stateAtEvent.BeforeStateSnapshotNID == 0) {
|
||||||
|
@ -459,7 +455,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
if userErr != nil {
|
if userErr != nil {
|
||||||
return userErr
|
return userErr
|
||||||
}
|
}
|
||||||
err = r.RSAPI.StoreUserRoomPublicKey(ctx, mapping.MXIDMapping.UserRoomKey, *storeUserID, *validRoomID)
|
err = r.RSAPI.StoreUserRoomPublicKey(ctx, mapping.MXIDMapping.UserRoomKey, *storeUserID, event.RoomID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed storing user room public key: %w", err)
|
return fmt.Errorf("failed storing user room public key: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -481,7 +477,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
return fmt.Errorf("r.updateLatestEvents: %w", err)
|
return fmt.Errorf("r.updateLatestEvents: %w", err)
|
||||||
}
|
}
|
||||||
case api.KindOld:
|
case api.KindOld:
|
||||||
err = r.OutputProducer.ProduceRoomEvents(event.RoomID(), []api.OutputEvent{
|
err = r.OutputProducer.ProduceRoomEvents(event.RoomID().String(), []api.OutputEvent{
|
||||||
{
|
{
|
||||||
Type: api.OutputTypeOldRoomEvent,
|
Type: api.OutputTypeOldRoomEvent,
|
||||||
OldRoomEvent: &api.OutputOldRoomEvent{
|
OldRoomEvent: &api.OutputOldRoomEvent{
|
||||||
|
@ -507,7 +503,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
// so notify downstream components to redact this event - they should have it if they've
|
// so notify downstream components to redact this event - they should have it if they've
|
||||||
// been tracking our output log.
|
// been tracking our output log.
|
||||||
if redactedEventID != "" {
|
if redactedEventID != "" {
|
||||||
err = r.OutputProducer.ProduceRoomEvents(event.RoomID(), []api.OutputEvent{
|
err = r.OutputProducer.ProduceRoomEvents(event.RoomID().String(), []api.OutputEvent{
|
||||||
{
|
{
|
||||||
Type: api.OutputTypeRedactedEvent,
|
Type: api.OutputTypeRedactedEvent,
|
||||||
RedactedEvent: &api.OutputRedactedEvent{
|
RedactedEvent: &api.OutputRedactedEvent{
|
||||||
|
@ -536,7 +532,7 @@ func (r *Inputer) processRoomEvent(
|
||||||
|
|
||||||
// handleRemoteRoomUpgrade updates published rooms and room aliases
|
// handleRemoteRoomUpgrade updates published rooms and room aliases
|
||||||
func (r *Inputer) handleRemoteRoomUpgrade(ctx context.Context, event gomatrixserverlib.PDU) error {
|
func (r *Inputer) handleRemoteRoomUpgrade(ctx context.Context, event gomatrixserverlib.PDU) error {
|
||||||
oldRoomID := event.RoomID()
|
oldRoomID := event.RoomID().String()
|
||||||
newRoomID := gjson.GetBytes(event.Content(), "replacement_room").Str
|
newRoomID := gjson.GetBytes(event.Content(), "replacement_room").Str
|
||||||
return r.DB.UpgradeRoom(ctx, oldRoomID, newRoomID, string(event.SenderID()))
|
return r.DB.UpgradeRoom(ctx, oldRoomID, newRoomID, string(event.SenderID()))
|
||||||
}
|
}
|
||||||
|
@ -596,7 +592,7 @@ func (r *Inputer) processStateBefore(
|
||||||
StateKey: "",
|
StateKey: "",
|
||||||
})
|
})
|
||||||
stateBeforeReq := &api.QueryStateAfterEventsRequest{
|
stateBeforeReq := &api.QueryStateAfterEventsRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
PrevEventIDs: event.PrevEventIDs(),
|
PrevEventIDs: event.PrevEventIDs(),
|
||||||
StateToFetch: tuplesNeeded,
|
StateToFetch: tuplesNeeded,
|
||||||
}
|
}
|
||||||
|
@ -606,7 +602,7 @@ func (r *Inputer) processStateBefore(
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case !stateBeforeRes.RoomExists:
|
case !stateBeforeRes.RoomExists:
|
||||||
rejectionErr = fmt.Errorf("room %q does not exist", event.RoomID())
|
rejectionErr = fmt.Errorf("room %q does not exist", event.RoomID().String())
|
||||||
return
|
return
|
||||||
case !stateBeforeRes.PrevEventsExist:
|
case !stateBeforeRes.PrevEventsExist:
|
||||||
rejectionErr = fmt.Errorf("prev events of %q are not known", event.EventID())
|
rejectionErr = fmt.Errorf("prev events of %q are not known", event.EventID())
|
||||||
|
@ -707,7 +703,7 @@ func (r *Inputer) fetchAuthEvents(
|
||||||
// Request the entire auth chain for the event in question. This should
|
// Request the entire auth chain for the event in question. This should
|
||||||
// contain all of the auth events — including ones that we already know —
|
// contain all of the auth events — including ones that we already know —
|
||||||
// so we'll need to filter through those in the next section.
|
// so we'll need to filter through those in the next section.
|
||||||
res, err = r.FSAPI.GetEventAuth(ctx, virtualHost, serverName, event.Version(), event.RoomID(), event.EventID())
|
res, err = r.FSAPI.GetEventAuth(ctx, virtualHost, serverName, event.Version(), event.RoomID().String(), event.EventID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithError(err).Warnf("Failed to get event auth from federation for %q: %s", event.EventID(), err)
|
logger.WithError(err).Warnf("Failed to get event auth from federation for %q: %s", event.EventID(), err)
|
||||||
continue
|
continue
|
||||||
|
@ -866,25 +862,20 @@ func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, r
|
||||||
|
|
||||||
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
|
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
|
||||||
latestReq := &api.QueryLatestEventsAndStateRequest{
|
latestReq := &api.QueryLatestEventsAndStateRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
}
|
}
|
||||||
latestRes := &api.QueryLatestEventsAndStateResponse{}
|
latestRes := &api.QueryLatestEventsAndStateResponse{}
|
||||||
if err = r.Queryer.QueryLatestEventsAndState(ctx, latestReq, latestRes); err != nil {
|
if err = r.Queryer.QueryLatestEventsAndState(ctx, latestReq, latestRes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
prevEvents := latestRes.LatestEvents
|
prevEvents := latestRes.LatestEvents
|
||||||
for _, memberEvent := range memberEvents {
|
for _, memberEvent := range memberEvents {
|
||||||
if memberEvent.StateKey() == nil {
|
if memberEvent.StateKey() == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
memberUserID, err := r.Queryer.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*memberEvent.StateKey()))
|
memberUserID, err := r.Queryer.QueryUserIDForSender(ctx, event.RoomID(), spec.SenderID(*memberEvent.StateKey()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -912,7 +903,7 @@ func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, r
|
||||||
|
|
||||||
stateKey := *memberEvent.StateKey()
|
stateKey := *memberEvent.StateKey()
|
||||||
fledglingEvent := &gomatrixserverlib.ProtoEvent{
|
fledglingEvent := &gomatrixserverlib.ProtoEvent{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
Type: spec.MRoomMember,
|
Type: spec.MRoomMember,
|
||||||
StateKey: &stateKey,
|
StateKey: &stateKey,
|
||||||
SenderID: stateKey,
|
SenderID: stateKey,
|
||||||
|
@ -928,12 +919,7 @@ func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, r
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
signingIdentity, err := r.SigningIdentity(ctx, event.RoomID(), *memberUserID)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
signingIdentity, err := r.SigningIdentity(ctx, *validRoomID, *memberUserID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ func (u *latestEventsUpdater) doUpdateLatestEvents() error {
|
||||||
// send the event asynchronously but we would need to ensure that 1) the events are written to the log in
|
// send the event asynchronously but we would need to ensure that 1) the events are written to the log in
|
||||||
// the correct order, 2) that pending writes are resent across restarts. In order to avoid writing all the
|
// the correct order, 2) that pending writes are resent across restarts. In order to avoid writing all the
|
||||||
// necessary bookkeeping we'll keep the event sending synchronous for now.
|
// necessary bookkeeping we'll keep the event sending synchronous for now.
|
||||||
if err = u.api.OutputProducer.ProduceRoomEvents(u.event.RoomID(), updates); err != nil {
|
if err = u.api.OutputProducer.ProduceRoomEvents(u.event.RoomID().String(), updates); err != nil {
|
||||||
return fmt.Errorf("u.api.WriteOutputEvents: %w", err)
|
return fmt.Errorf("u.api.WriteOutputEvents: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ func (u *latestEventsUpdater) latestState() error {
|
||||||
if removed := len(u.removed) - len(u.added); !u.rewritesState && removed > 0 {
|
if removed := len(u.removed) - len(u.added); !u.rewritesState && removed > 0 {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"event_id": u.event.EventID(),
|
"event_id": u.event.EventID(),
|
||||||
"room_id": u.event.RoomID(),
|
"room_id": u.event.RoomID().String(),
|
||||||
"old_state_nid": u.oldStateNID,
|
"old_state_nid": u.oldStateNID,
|
||||||
"new_state_nid": u.newStateNID,
|
"new_state_nid": u.newStateNID,
|
||||||
"old_latest": u.oldLatest.EventIDs(),
|
"old_latest": u.oldLatest.EventIDs(),
|
||||||
|
|
|
@ -139,11 +139,7 @@ func (r *Inputer) updateMembership(
|
||||||
func (r *Inputer) isLocalTarget(ctx context.Context, event *types.Event) bool {
|
func (r *Inputer) isLocalTarget(ctx context.Context, event *types.Event) bool {
|
||||||
isTargetLocalUser := false
|
isTargetLocalUser := false
|
||||||
if statekey := event.StateKey(); statekey != nil {
|
if statekey := event.StateKey(); statekey != nil {
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
userID, err := r.Queryer.QueryUserIDForSender(ctx, event.RoomID(), spec.SenderID(*statekey))
|
||||||
if err != nil {
|
|
||||||
return isTargetLocalUser
|
|
||||||
}
|
|
||||||
userID, err := r.Queryer.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*statekey))
|
|
||||||
if err != nil || userID == nil {
|
if err != nil || userID == nil {
|
||||||
return isTargetLocalUser
|
return isTargetLocalUser
|
||||||
}
|
}
|
||||||
|
@ -168,7 +164,7 @@ func updateToJoinMembership(
|
||||||
Type: api.OutputTypeRetireInviteEvent,
|
Type: api.OutputTypeRetireInviteEvent,
|
||||||
RetireInviteEvent: &api.OutputRetireInviteEvent{
|
RetireInviteEvent: &api.OutputRetireInviteEvent{
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
RoomID: add.RoomID(),
|
RoomID: add.RoomID().String(),
|
||||||
Membership: spec.Join,
|
Membership: spec.Join,
|
||||||
RetiredByEventID: add.EventID(),
|
RetiredByEventID: add.EventID(),
|
||||||
TargetSenderID: spec.SenderID(*add.StateKey()),
|
TargetSenderID: spec.SenderID(*add.StateKey()),
|
||||||
|
@ -195,7 +191,7 @@ func updateToLeaveMembership(
|
||||||
Type: api.OutputTypeRetireInviteEvent,
|
Type: api.OutputTypeRetireInviteEvent,
|
||||||
RetireInviteEvent: &api.OutputRetireInviteEvent{
|
RetireInviteEvent: &api.OutputRetireInviteEvent{
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
RoomID: add.RoomID(),
|
RoomID: add.RoomID().String(),
|
||||||
Membership: newMembership,
|
Membership: newMembership,
|
||||||
RetiredByEventID: add.EventID(),
|
RetiredByEventID: add.EventID(),
|
||||||
TargetSenderID: spec.SenderID(*add.StateKey()),
|
TargetSenderID: spec.SenderID(*add.StateKey()),
|
||||||
|
|
|
@ -84,7 +84,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
||||||
// need to fallback to /state.
|
// need to fallback to /state.
|
||||||
t.log = util.GetLogger(ctx).WithFields(map[string]interface{}{
|
t.log = util.GetLogger(ctx).WithFields(map[string]interface{}{
|
||||||
"txn_event": e.EventID(),
|
"txn_event": e.EventID(),
|
||||||
"room_id": e.RoomID(),
|
"room_id": e.RoomID().String(),
|
||||||
"txn_prev_events": e.PrevEventIDs(),
|
"txn_prev_events": e.PrevEventIDs(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ func (t *missingStateReq) lookupResolvedStateBeforeEvent(ctx context.Context, e
|
||||||
// Look up what the state is after the backward extremity. This will either
|
// Look up what the state is after the backward extremity. This will either
|
||||||
// come from the roomserver, if we know all the required events, or it will
|
// come from the roomserver, if we know all the required events, or it will
|
||||||
// come from a remote server via /state_ids if not.
|
// come from a remote server via /state_ids if not.
|
||||||
prevState, trustworthy, err := t.lookupStateAfterEvent(ctx, roomVersion, e.RoomID(), prevEventID)
|
prevState, trustworthy, err := t.lookupStateAfterEvent(ctx, roomVersion, e.RoomID().String(), prevEventID)
|
||||||
switch err2 := err.(type) {
|
switch err2 := err.(type) {
|
||||||
case gomatrixserverlib.EventValidationError:
|
case gomatrixserverlib.EventValidationError:
|
||||||
if !err2.Persistable {
|
if !err2.Persistable {
|
||||||
|
@ -316,9 +316,9 @@ func (t *missingStateReq) lookupResolvedStateBeforeEvent(ctx context.Context, e
|
||||||
}
|
}
|
||||||
// There's more than one previous state - run them all through state res
|
// There's more than one previous state - run them all through state res
|
||||||
var err error
|
var err error
|
||||||
t.roomsMu.Lock(e.RoomID())
|
t.roomsMu.Lock(e.RoomID().String())
|
||||||
resolvedState, err = t.resolveStatesAndCheck(ctx, roomVersion, respStates, e)
|
resolvedState, err = t.resolveStatesAndCheck(ctx, roomVersion, respStates, e)
|
||||||
t.roomsMu.Unlock(e.RoomID())
|
t.roomsMu.Unlock(e.RoomID().String())
|
||||||
switch err2 := err.(type) {
|
switch err2 := err.(type) {
|
||||||
case gomatrixserverlib.EventValidationError:
|
case gomatrixserverlib.EventValidationError:
|
||||||
if !err2.Persistable {
|
if !err2.Persistable {
|
||||||
|
@ -510,7 +510,7 @@ retryAllowedState:
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
switch missing := err.(type) {
|
switch missing := err.(type) {
|
||||||
case gomatrixserverlib.MissingAuthEventError:
|
case gomatrixserverlib.MissingAuthEventError:
|
||||||
h, err2 := t.lookupEvent(ctx, roomVersion, backwardsExtremity.RoomID(), missing.AuthEventID, true)
|
h, err2 := t.lookupEvent(ctx, roomVersion, backwardsExtremity.RoomID().String(), missing.AuthEventID, true)
|
||||||
switch e := err2.(type) {
|
switch e := err2.(type) {
|
||||||
case gomatrixserverlib.EventValidationError:
|
case gomatrixserverlib.EventValidationError:
|
||||||
if !e.Persistable {
|
if !e.Persistable {
|
||||||
|
@ -546,7 +546,7 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e gomatrixserver
|
||||||
trace, ctx := internal.StartRegion(ctx, "getMissingEvents")
|
trace, ctx := internal.StartRegion(ctx, "getMissingEvents")
|
||||||
defer trace.EndRegion()
|
defer trace.EndRegion()
|
||||||
|
|
||||||
logger := t.log.WithField("event_id", e.EventID()).WithField("room_id", e.RoomID())
|
logger := t.log.WithField("event_id", e.EventID()).WithField("room_id", e.RoomID().String())
|
||||||
latest, _, _, err := t.db.LatestEventIDs(ctx, t.roomInfo.RoomNID)
|
latest, _, _, err := t.db.LatestEventIDs(ctx, t.roomInfo.RoomNID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, false, fmt.Errorf("t.DB.LatestEventIDs: %w", err)
|
return nil, false, false, fmt.Errorf("t.DB.LatestEventIDs: %w", err)
|
||||||
|
@ -560,7 +560,7 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e gomatrixserver
|
||||||
var missingResp *fclient.RespMissingEvents
|
var missingResp *fclient.RespMissingEvents
|
||||||
for _, server := range t.servers {
|
for _, server := range t.servers {
|
||||||
var m fclient.RespMissingEvents
|
var m fclient.RespMissingEvents
|
||||||
if m, err = t.federation.LookupMissingEvents(ctx, t.virtualHost, server, e.RoomID(), fclient.MissingEvents{
|
if m, err = t.federation.LookupMissingEvents(ctx, t.virtualHost, server, e.RoomID().String(), fclient.MissingEvents{
|
||||||
Limit: 20,
|
Limit: 20,
|
||||||
// The latest event IDs that the sender already has. These are skipped when retrieving the previous events of latest_events.
|
// The latest event IDs that the sender already has. These are skipped when retrieving the previous events of latest_events.
|
||||||
EarliestEvents: latestEvents,
|
EarliestEvents: latestEvents,
|
||||||
|
|
|
@ -301,7 +301,7 @@ func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent
|
||||||
return ids, nil
|
return ids, nil
|
||||||
}
|
}
|
||||||
if len(targetEvent.PrevEventIDs()) == 0 && targetEvent.Type() == "m.room.create" && targetEvent.StateKeyEquals("") {
|
if len(targetEvent.PrevEventIDs()) == 0 && targetEvent.Type() == "m.room.create" && targetEvent.StateKeyEquals("") {
|
||||||
util.GetLogger(ctx).WithField("room_id", targetEvent.RoomID()).Info("Backfilled to the beginning of the room")
|
util.GetLogger(ctx).WithField("room_id", targetEvent.RoomID().String()).Info("Backfilled to the beginning of the room")
|
||||||
b.eventIDToBeforeStateIDs[targetEvent.EventID()] = []string{}
|
b.eventIDToBeforeStateIDs[targetEvent.EventID()] = []string{}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -494,11 +494,7 @@ FindSuccessor:
|
||||||
// Store the server names in a temporary map to avoid duplicates.
|
// Store the server names in a temporary map to avoid duplicates.
|
||||||
serverSet := make(map[spec.ServerName]bool)
|
serverSet := make(map[spec.ServerName]bool)
|
||||||
for _, event := range memberEvents {
|
for _, event := range memberEvents {
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
if sender, err := b.querier.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID()); err == nil {
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if sender, err := b.querier.QueryUserIDForSender(ctx, *validRoomID, event.SenderID()); err == nil {
|
|
||||||
serverSet[sender.Domain()] = true
|
serverSet[sender.Domain()] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,16 +100,12 @@ func (r *Inviter) ProcessInviteMembership(
|
||||||
var outputUpdates []api.OutputEvent
|
var outputUpdates []api.OutputEvent
|
||||||
var updater *shared.MembershipUpdater
|
var updater *shared.MembershipUpdater
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(inviteEvent.RoomID())
|
userID, err := r.RSAPI.QueryUserIDForSender(ctx, inviteEvent.RoomID(), spec.SenderID(*inviteEvent.StateKey()))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
userID, err := r.RSAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*inviteEvent.StateKey()))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, api.ErrInvalidID{Err: fmt.Errorf("the user ID %s is invalid", *inviteEvent.StateKey())}
|
return nil, api.ErrInvalidID{Err: fmt.Errorf("the user ID %s is invalid", *inviteEvent.StateKey())}
|
||||||
}
|
}
|
||||||
isTargetLocal := r.Cfg.Matrix.IsLocalServerName(userID.Domain())
|
isTargetLocal := r.Cfg.Matrix.IsLocalServerName(userID.Domain())
|
||||||
if updater, err = r.DB.MembershipUpdater(ctx, inviteEvent.RoomID(), *inviteEvent.StateKey(), isTargetLocal, inviteEvent.Version()); err != nil {
|
if updater, err = r.DB.MembershipUpdater(ctx, inviteEvent.RoomID().String(), *inviteEvent.StateKey(), isTargetLocal, inviteEvent.Version()); err != nil {
|
||||||
return nil, fmt.Errorf("r.DB.MembershipUpdater: %w", err)
|
return nil, fmt.Errorf("r.DB.MembershipUpdater: %w", err)
|
||||||
}
|
}
|
||||||
outputUpdates, err = helpers.UpdateToInviteMembership(updater, &types.Event{
|
outputUpdates, err = helpers.UpdateToInviteMembership(updater, &types.Event{
|
||||||
|
|
|
@ -513,14 +513,14 @@ func restrictedJoinRuleAllowedRooms(ctx context.Context, joinRuleEv *types.Heade
|
||||||
}
|
}
|
||||||
var jrContent gomatrixserverlib.JoinRuleContent
|
var jrContent gomatrixserverlib.JoinRuleContent
|
||||||
if err := json.Unmarshal(joinRuleEv.Content(), &jrContent); err != nil {
|
if err := json.Unmarshal(joinRuleEv.Content(), &jrContent); err != nil {
|
||||||
util.GetLogger(ctx).Warnf("failed to check join_rule on room %s: %s", joinRuleEv.RoomID(), err)
|
util.GetLogger(ctx).Warnf("failed to check join_rule on room %s: %s", joinRuleEv.RoomID().String(), err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, allow := range jrContent.Allow {
|
for _, allow := range jrContent.Allow {
|
||||||
if allow.Type == spec.MRoomMembership {
|
if allow.Type == spec.MRoomMembership {
|
||||||
allowedRoomID, err := spec.NewRoomID(allow.RoomID)
|
allowedRoomID, err := spec.NewRoomID(allow.RoomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(ctx).Warnf("invalid room ID '%s' found in join_rule on room %s: %s", allow.RoomID, joinRuleEv.RoomID(), err)
|
util.GetLogger(ctx).Warnf("invalid room ID '%s' found in join_rule on room %s: %s", allow.RoomID, joinRuleEv.RoomID().String(), err)
|
||||||
} else {
|
} else {
|
||||||
allows = append(allows, *allowedRoomID)
|
allows = append(allows, *allowedRoomID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ func (db *getEventDB) addFakeEvent(eventID string, authIDs []string) error {
|
||||||
}
|
}
|
||||||
builder := map[string]interface{}{
|
builder := map[string]interface{}{
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
|
"room_id": "!room:a",
|
||||||
"auth_events": authEvents,
|
"auth_events": authEvents,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -696,8 +696,8 @@ func (d *Database) GetOrCreateRoomInfo(ctx context.Context, event gomatrixserver
|
||||||
return nil, fmt.Errorf("extractRoomVersionFromCreateEvent: %w", err)
|
return nil, fmt.Errorf("extractRoomVersionFromCreateEvent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
roomNID, nidOK := d.Cache.GetRoomServerRoomNID(event.RoomID())
|
roomNID, nidOK := d.Cache.GetRoomServerRoomNID(event.RoomID().String())
|
||||||
cachedRoomVersion, versionOK := d.Cache.GetRoomVersion(event.RoomID())
|
cachedRoomVersion, versionOK := d.Cache.GetRoomVersion(event.RoomID().String())
|
||||||
// if we found both, the roomNID and version in our cache, no need to query the database
|
// if we found both, the roomNID and version in our cache, no need to query the database
|
||||||
if nidOK && versionOK {
|
if nidOK && versionOK {
|
||||||
return &types.RoomInfo{
|
return &types.RoomInfo{
|
||||||
|
@ -707,14 +707,14 @@ func (d *Database) GetOrCreateRoomInfo(ctx context.Context, event gomatrixserver
|
||||||
}
|
}
|
||||||
|
|
||||||
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
roomNID, err = d.assignRoomNID(ctx, txn, event.RoomID(), roomVersion)
|
roomNID, err = d.assignRoomNID(ctx, txn, event.RoomID().String(), roomVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if roomVersion != "" {
|
if roomVersion != "" {
|
||||||
d.Cache.StoreRoomVersion(event.RoomID(), roomVersion)
|
d.Cache.StoreRoomVersion(event.RoomID().String(), roomVersion)
|
||||||
}
|
}
|
||||||
return &types.RoomInfo{
|
return &types.RoomInfo{
|
||||||
RoomVersion: roomVersion,
|
RoomVersion: roomVersion,
|
||||||
|
@ -1026,24 +1026,19 @@ func (d *EventDatabase) MaybeRedactEvent(
|
||||||
case validated || redactedEvent == nil || redactionEvent == nil:
|
case validated || redactedEvent == nil || redactionEvent == nil:
|
||||||
// we've seen this redaction before or there is nothing to redact
|
// we've seen this redaction before or there is nothing to redact
|
||||||
return nil
|
return nil
|
||||||
case redactedEvent.RoomID() != redactionEvent.RoomID():
|
case redactedEvent.RoomID().String() != redactionEvent.RoomID().String():
|
||||||
// redactions across rooms aren't allowed
|
// redactions across rooms aren't allowed
|
||||||
ignoreRedaction = true
|
ignoreRedaction = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var validRoomID *spec.RoomID
|
|
||||||
validRoomID, err = spec.NewRoomID(redactedEvent.RoomID())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
sender1Domain := ""
|
sender1Domain := ""
|
||||||
sender1, err1 := querier.QueryUserIDForSender(ctx, *validRoomID, redactedEvent.SenderID())
|
sender1, err1 := querier.QueryUserIDForSender(ctx, redactedEvent.RoomID(), redactedEvent.SenderID())
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
sender1Domain = string(sender1.Domain())
|
sender1Domain = string(sender1.Domain())
|
||||||
}
|
}
|
||||||
sender2Domain := ""
|
sender2Domain := ""
|
||||||
sender2, err2 := querier.QueryUserIDForSender(ctx, *validRoomID, redactionEvent.SenderID())
|
sender2, err2 := querier.QueryUserIDForSender(ctx, redactedEvent.RoomID(), redactionEvent.SenderID())
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
sender2Domain = string(sender2.Domain())
|
sender2Domain = string(sender2.Domain())
|
||||||
}
|
}
|
||||||
|
@ -1522,7 +1517,7 @@ func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tu
|
||||||
}
|
}
|
||||||
result[i] = tables.StrippedEvent{
|
result[i] = tables.StrippedEvent{
|
||||||
EventType: ev.Type(),
|
EventType: ev.Type(),
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID().String(),
|
||||||
StateKey: *ev.StateKey(),
|
StateKey: *ev.StateKey(),
|
||||||
ContentValue: tables.ExtractContentValue(&types.HeaderedEvent{PDU: ev}),
|
ContentValue: tables.ExtractContentValue(&types.HeaderedEvent{PDU: ev}),
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
|
||||||
event = rc.fetchUnknownEvent(rc.req.EventID, rc.req.RoomID)
|
event = rc.fetchUnknownEvent(rc.req.EventID, rc.req.RoomID)
|
||||||
}
|
}
|
||||||
if rc.req.RoomID == "" && event != nil {
|
if rc.req.RoomID == "" && event != nil {
|
||||||
rc.req.RoomID = event.RoomID()
|
rc.req.RoomID = event.RoomID().String()
|
||||||
}
|
}
|
||||||
if event == nil || !rc.authorisedToSeeEvent(event) {
|
if event == nil || !rc.authorisedToSeeEvent(event) {
|
||||||
return nil, &util.JSONResponse{
|
return nil, &util.JSONResponse{
|
||||||
|
@ -526,7 +526,7 @@ func (rc *reqCtx) authorisedToSeeEvent(event *types.HeaderedEvent) bool {
|
||||||
// make sure the server is in this room
|
// make sure the server is in this room
|
||||||
var res fs.QueryJoinedHostServerNamesInRoomResponse
|
var res fs.QueryJoinedHostServerNamesInRoomResponse
|
||||||
err := rc.fsAPI.QueryJoinedHostServerNamesInRoom(rc.ctx, &fs.QueryJoinedHostServerNamesInRoomRequest{
|
err := rc.fsAPI.QueryJoinedHostServerNamesInRoom(rc.ctx, &fs.QueryJoinedHostServerNamesInRoomRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
}, &res)
|
}, &res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(rc.ctx).WithError(err).Error("authorisedToSeeEvent: failed to QueryJoinedHostServerNamesInRoom")
|
util.GetLogger(rc.ctx).WithError(err).Error("authorisedToSeeEvent: failed to QueryJoinedHostServerNamesInRoom")
|
||||||
|
@ -545,7 +545,7 @@ func (rc *reqCtx) authorisedToSeeEvent(event *types.HeaderedEvent) bool {
|
||||||
// TODO: This does not honour m.room.create content
|
// TODO: This does not honour m.room.create content
|
||||||
var queryMembershipRes roomserver.QueryMembershipForUserResponse
|
var queryMembershipRes roomserver.QueryMembershipForUserResponse
|
||||||
err := rc.rsAPI.QueryMembershipForUser(rc.ctx, &roomserver.QueryMembershipForUserRequest{
|
err := rc.rsAPI.QueryMembershipForUser(rc.ctx, &roomserver.QueryMembershipForUserRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
UserID: rc.userID,
|
UserID: rc.userID,
|
||||||
}, &queryMembershipRes)
|
}, &queryMembershipRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -612,7 +612,7 @@ func (rc *reqCtx) lookForEvent(eventID string) *types.HeaderedEvent {
|
||||||
// inject all the events into the roomserver then return the event in question
|
// inject all the events into the roomserver then return the event in question
|
||||||
rc.injectResponseToRoomserver(queryRes)
|
rc.injectResponseToRoomserver(queryRes)
|
||||||
for _, ev := range queryRes.ParsedEvents {
|
for _, ev := range queryRes.ParsedEvents {
|
||||||
if ev.EventID() == eventID && rc.req.RoomID == ev.RoomID() {
|
if ev.EventID() == eventID && rc.req.RoomID == ev.RoomID().String() {
|
||||||
return &types.HeaderedEvent{PDU: ev}
|
return &types.HeaderedEvent{PDU: ev}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -629,7 +629,7 @@ func (rc *reqCtx) lookForEvent(eventID string) *types.HeaderedEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rc.req.RoomID == event.RoomID() {
|
if rc.req.RoomID == event.RoomID().String() {
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -239,7 +239,7 @@ func (p *DB) StoreRelation(ctx context.Context, ev *types.HeaderedEvent) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
util.GetLogger(ctx).Infof("StoreRelation child=%s parent=%s rel_type=%s", child, parent, relType)
|
util.GetLogger(ctx).Infof("StoreRelation child=%s parent=%s rel_type=%s", child, parent, relType)
|
||||||
_, err = txn.Stmt(p.insertNodeStmt).ExecContext(ctx, ev.EventID(), ev.OriginServerTS(), ev.RoomID(), count, base64.RawStdEncoding.EncodeToString(hash), 0)
|
_, err = txn.Stmt(p.insertNodeStmt).ExecContext(ctx, ev.EventID(), ev.OriginServerTS(), ev.RoomID().String(), count, base64.RawStdEncoding.EncodeToString(hash), 0)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ func (s *OutputClientDataConsumer) Start() error {
|
||||||
id = streamPos
|
id = streamPos
|
||||||
e := fulltext.IndexElement{
|
e := fulltext.IndexElement{
|
||||||
EventID: ev.EventID(),
|
EventID: ev.EventID(),
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID().String(),
|
||||||
StreamPosition: streamPos,
|
StreamPosition: streamPos,
|
||||||
}
|
}
|
||||||
e.SetContentType(ev.Type())
|
e.SetContentType(ev.Type())
|
||||||
|
|
|
@ -166,9 +166,9 @@ func (s *OutputRoomEventConsumer) onRedactEvent(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = s.db.RedactRelations(ctx, msg.RedactedBecause.RoomID(), msg.RedactedEventID); err != nil {
|
if err = s.db.RedactRelations(ctx, msg.RedactedBecause.RoomID().String(), msg.RedactedEventID); err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"room_id": msg.RedactedBecause.RoomID(),
|
"room_id": msg.RedactedBecause.RoomID().String(),
|
||||||
"event_id": msg.RedactedBecause.EventID(),
|
"event_id": msg.RedactedBecause.EventID(),
|
||||||
"redacted_event_id": msg.RedactedEventID,
|
"redacted_event_id": msg.RedactedEventID,
|
||||||
}).WithError(err).Warn("Failed to redact relations")
|
}).WithError(err).Warn("Failed to redact relations")
|
||||||
|
@ -222,7 +222,7 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
||||||
// Finally, work out if there are any more events missing.
|
// Finally, work out if there are any more events missing.
|
||||||
if len(missingEventIDs) > 0 {
|
if len(missingEventIDs) > 0 {
|
||||||
eventsReq := &api.QueryEventsByIDRequest{
|
eventsReq := &api.QueryEventsByIDRequest{
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID().String(),
|
||||||
EventIDs: missingEventIDs,
|
EventIDs: missingEventIDs,
|
||||||
}
|
}
|
||||||
eventsRes := &api.QueryEventsByIDResponse{}
|
eventsRes := &api.QueryEventsByIDResponse{}
|
||||||
|
@ -257,17 +257,12 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.RewritesState {
|
if msg.RewritesState {
|
||||||
if err = s.db.PurgeRoomState(ctx, ev.RoomID()); err != nil {
|
if err = s.db.PurgeRoomState(ctx, ev.RoomID().String()); err != nil {
|
||||||
return fmt.Errorf("s.db.PurgeRoom: %w", err)
|
return fmt.Errorf("s.db.PurgeRoom: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
userID, err := s.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, ev.SenderID())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -307,7 +302,7 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pduStream.Advance(pduPos)
|
s.pduStream.Advance(pduPos)
|
||||||
s.notifier.OnNewEvent(ev, ev.RoomID(), nil, types.StreamingToken{PDUPosition: pduPos})
|
s.notifier.OnNewEvent(ev, ev.RoomID().String(), nil, types.StreamingToken{PDUPosition: pduPos})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -324,12 +319,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
|
||||||
// old events in the sync API, this should at least prevent us
|
// old events in the sync API, this should at least prevent us
|
||||||
// from confusing clients into thinking they've joined/left rooms.
|
// from confusing clients into thinking they've joined/left rooms.
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
userID, err := s.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, ev.SenderID())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -355,7 +345,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
|
||||||
|
|
||||||
if err = s.db.UpdateRelations(ctx, ev); err != nil {
|
if err = s.db.UpdateRelations(ctx, ev); err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"room_id": ev.RoomID(),
|
"room_id": ev.RoomID().String(),
|
||||||
"event_id": ev.EventID(),
|
"event_id": ev.EventID(),
|
||||||
"type": ev.Type(),
|
"type": ev.Type(),
|
||||||
}).WithError(err).Warn("Failed to update relations")
|
}).WithError(err).Warn("Failed to update relations")
|
||||||
|
@ -368,7 +358,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pduStream.Advance(pduPos)
|
s.pduStream.Advance(pduPos)
|
||||||
s.notifier.OnNewEvent(ev, ev.RoomID(), nil, types.StreamingToken{PDUPosition: pduPos})
|
s.notifier.OnNewEvent(ev, ev.RoomID().String(), nil, types.StreamingToken{PDUPosition: pduPos})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -388,11 +378,7 @@ func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *rst
|
||||||
return sp, fmt.Errorf("unexpected nil state_key")
|
return sp, fmt.Errorf("unexpected nil state_key")
|
||||||
}
|
}
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
userID, err := s.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*ev.StateKey()))
|
||||||
if err != nil {
|
|
||||||
return sp, err
|
|
||||||
}
|
|
||||||
userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*ev.StateKey()))
|
|
||||||
if err != nil || userID == nil {
|
if err != nil || userID == nil {
|
||||||
return sp, fmt.Errorf("failed getting userID for sender: %w", err)
|
return sp, fmt.Errorf("failed getting userID for sender: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -401,7 +387,7 @@ func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *rst
|
||||||
}
|
}
|
||||||
|
|
||||||
// cancel any peeks for it
|
// cancel any peeks for it
|
||||||
peekSP, peekErr := s.db.DeletePeeks(ctx, ev.RoomID(), *ev.StateKey())
|
peekSP, peekErr := s.db.DeletePeeks(ctx, ev.RoomID().String(), *ev.StateKey())
|
||||||
if peekErr != nil {
|
if peekErr != nil {
|
||||||
return sp, fmt.Errorf("s.db.DeletePeeks: %w", peekErr)
|
return sp, fmt.Errorf("s.db.DeletePeeks: %w", peekErr)
|
||||||
}
|
}
|
||||||
|
@ -419,11 +405,7 @@ func (s *OutputRoomEventConsumer) onNewInviteEvent(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(msg.Event.RoomID())
|
userID, err := s.rsAPI.QueryUserIDForSender(ctx, msg.Event.RoomID(), spec.SenderID(*msg.Event.StateKey()))
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*msg.Event.StateKey()))
|
|
||||||
if err != nil || userID == nil {
|
if err != nil || userID == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -560,15 +542,10 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *rstypes.HeaderedEvent)
|
||||||
var succeeded bool
|
var succeeded bool
|
||||||
defer sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err)
|
defer sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err)
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
|
||||||
if err != nil {
|
|
||||||
return event, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sKeyUser := ""
|
sKeyUser := ""
|
||||||
if stateKey != "" {
|
if stateKey != "" {
|
||||||
var sku *spec.UserID
|
var sku *spec.UserID
|
||||||
sku, err = s.rsAPI.QueryUserIDForSender(s.ctx, *validRoomID, spec.SenderID(stateKey))
|
sku, err = s.rsAPI.QueryUserIDForSender(s.ctx, event.RoomID(), spec.SenderID(stateKey))
|
||||||
if err == nil && sku != nil {
|
if err == nil && sku != nil {
|
||||||
sKeyUser = sku.String()
|
sKeyUser = sku.String()
|
||||||
event.StateKeyResolved = &sKeyUser
|
event.StateKeyResolved = &sKeyUser
|
||||||
|
@ -576,13 +553,13 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *rstypes.HeaderedEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
prevEvent, err := snapshot.GetStateEvent(
|
prevEvent, err := snapshot.GetStateEvent(
|
||||||
s.ctx, event.RoomID(), event.Type(), sKeyUser,
|
s.ctx, event.RoomID().String(), event.Type(), sKeyUser,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return event, err
|
return event, err
|
||||||
}
|
}
|
||||||
|
|
||||||
userID, err := s.rsAPI.QueryUserIDForSender(s.ctx, *validRoomID, event.SenderID())
|
userID, err := s.rsAPI.QueryUserIDForSender(s.ctx, event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return event, err
|
return event, err
|
||||||
}
|
}
|
||||||
|
@ -610,7 +587,7 @@ func (s *OutputRoomEventConsumer) writeFTS(ev *rstypes.HeaderedEvent, pduPositio
|
||||||
}
|
}
|
||||||
e := fulltext.IndexElement{
|
e := fulltext.IndexElement{
|
||||||
EventID: ev.EventID(),
|
EventID: ev.EventID(),
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID().String(),
|
||||||
StreamPosition: int64(pduPosition),
|
StreamPosition: int64(pduPosition),
|
||||||
}
|
}
|
||||||
e.SetContentType(ev.Type())
|
e.SetContentType(ev.Type())
|
||||||
|
|
|
@ -118,26 +118,23 @@ func ApplyHistoryVisibilityFilter(
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
// try to get the current membership of the user
|
// try to get the current membership of the user
|
||||||
membershipCurrent, _, err := syncDB.SelectMembershipForUser(ctx, events[0].RoomID(), userID.String(), math.MaxInt64)
|
membershipCurrent, _, err := syncDB.SelectMembershipForUser(ctx, events[0].RoomID().String(), userID.String(), math.MaxInt64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the mapping from eventID -> eventVisibility
|
// Get the mapping from eventID -> eventVisibility
|
||||||
eventsFiltered := make([]*types.HeaderedEvent, 0, len(events))
|
eventsFiltered := make([]*types.HeaderedEvent, 0, len(events))
|
||||||
firstEvRoomID, err := spec.NewRoomID(events[0].RoomID())
|
firstEvRoomID := events[0].RoomID()
|
||||||
|
senderID, err := rsAPI.QuerySenderIDForUser(ctx, firstEvRoomID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
senderID, err := rsAPI.QuerySenderIDForUser(ctx, *firstEvRoomID, userID)
|
visibilities := visibilityForEvents(ctx, rsAPI, events, senderID, firstEvRoomID)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
visibilities := visibilityForEvents(ctx, rsAPI, events, senderID, *firstEvRoomID)
|
|
||||||
|
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
// Validate same room assumption
|
// Validate same room assumption
|
||||||
if ev.RoomID() != firstEvRoomID.String() {
|
if ev.RoomID().String() != firstEvRoomID.String() {
|
||||||
return nil, fmt.Errorf("events from different rooms supplied to ApplyHistoryVisibilityFilter")
|
return nil, fmt.Errorf("events from different rooms supplied to ApplyHistoryVisibilityFilter")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,20 +101,13 @@ func (n *Notifier) OnNewEvent(
|
||||||
n._removeEmptyUserStreams()
|
n._removeEmptyUserStreams()
|
||||||
|
|
||||||
if ev != nil {
|
if ev != nil {
|
||||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).WithField("event_id", ev.EventID()).Errorf(
|
|
||||||
"Notifier.OnNewEvent: RoomID is invalid",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Map this event's room_id to a list of joined users, and wake them up.
|
// Map this event's room_id to a list of joined users, and wake them up.
|
||||||
usersToNotify := n._joinedUsers(ev.RoomID())
|
usersToNotify := n._joinedUsers(ev.RoomID().String())
|
||||||
// Map this event's room_id to a list of peeking devices, and wake them up.
|
// Map this event's room_id to a list of peeking devices, and wake them up.
|
||||||
peekingDevicesToNotify := n._peekingDevices(ev.RoomID())
|
peekingDevicesToNotify := n._peekingDevices(ev.RoomID().String())
|
||||||
// If this is an invite, also add in the invitee to this list.
|
// If this is an invite, also add in the invitee to this list.
|
||||||
if ev.Type() == "m.room.member" && ev.StateKey() != nil {
|
if ev.Type() == "m.room.member" && ev.StateKey() != nil {
|
||||||
targetUserID, err := n.rsAPI.QueryUserIDForSender(context.Background(), *validRoomID, spec.SenderID(*ev.StateKey()))
|
targetUserID, err := n.rsAPI.QueryUserIDForSender(context.Background(), ev.RoomID(), spec.SenderID(*ev.StateKey()))
|
||||||
if err != nil || targetUserID == nil {
|
if err != nil || targetUserID == nil {
|
||||||
log.WithError(err).WithField("event_id", ev.EventID()).Errorf(
|
log.WithError(err).WithField("event_id", ev.EventID()).Errorf(
|
||||||
"Notifier.OnNewEvent: Failed to find the userID for this event",
|
"Notifier.OnNewEvent: Failed to find the userID for this event",
|
||||||
|
@ -134,11 +127,11 @@ func (n *Notifier) OnNewEvent(
|
||||||
// Manually append the new user's ID so they get notified
|
// Manually append the new user's ID so they get notified
|
||||||
// along all members in the room
|
// along all members in the room
|
||||||
usersToNotify = append(usersToNotify, targetUserID.String())
|
usersToNotify = append(usersToNotify, targetUserID.String())
|
||||||
n._addJoinedUser(ev.RoomID(), targetUserID.String())
|
n._addJoinedUser(ev.RoomID().String(), targetUserID.String())
|
||||||
case spec.Leave:
|
case spec.Leave:
|
||||||
fallthrough
|
fallthrough
|
||||||
case spec.Ban:
|
case spec.Ban:
|
||||||
n._removeJoinedUser(ev.RoomID(), targetUserID.String())
|
n._removeJoinedUser(ev.RoomID().String(), targetUserID.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,14 +129,7 @@ func GetEvent(
|
||||||
|
|
||||||
sk := events[0].StateKey()
|
sk := events[0].StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
evRoomID, err := spec.NewRoomID(events[0].RoomID())
|
skUserID, err := rsAPI.QueryUserIDForSender(ctx, events[0].RoomID(), spec.SenderID(*events[0].StateKey()))
|
||||||
if err != nil {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusBadRequest,
|
|
||||||
JSON: spec.BadJSON("roomID is invalid"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
skUserID, err := rsAPI.QueryUserIDForSender(ctx, *evRoomID, spec.SenderID(*events[0].StateKey()))
|
|
||||||
if err == nil && skUserID != nil {
|
if err == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
|
|
@ -152,15 +152,7 @@ func GetMemberships(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
userID, err := rsAPI.QueryUserIDForSender(req.Context(), ev.RoomID(), ev.SenderID())
|
||||||
if err != nil {
|
|
||||||
util.GetLogger(req.Context()).WithError(err).Error("roomID is invalid")
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusInternalServerError,
|
|
||||||
JSON: spec.InternalServerError{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userID, err := rsAPI.QueryUserIDForSender(req.Context(), *validRoomID, ev.SenderID())
|
|
||||||
if err != nil || userID == nil {
|
if err != nil || userID == nil {
|
||||||
util.GetLogger(req.Context()).WithError(err).Error("rsAPI.QueryUserIDForSender failed")
|
util.GetLogger(req.Context()).WithError(err).Error("rsAPI.QueryUserIDForSender failed")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
|
|
|
@ -205,12 +205,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
|
|
||||||
profileInfos := make(map[string]ProfileInfoResponse)
|
profileInfos := make(map[string]ProfileInfoResponse)
|
||||||
for _, ev := range append(eventsBefore, eventsAfter...) {
|
for _, ev := range append(eventsBefore, eventsAfter...) {
|
||||||
validRoomID, roomErr := spec.NewRoomID(ev.RoomID())
|
userID, queryErr := rsAPI.QueryUserIDForSender(req.Context(), ev.RoomID(), ev.SenderID())
|
||||||
if err != nil {
|
|
||||||
logrus.WithError(roomErr).WithField("room_id", ev.RoomID()).Warn("failed to query userprofile")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
userID, queryErr := rsAPI.QueryUserIDForSender(req.Context(), *validRoomID, ev.SenderID())
|
|
||||||
if queryErr != nil {
|
if queryErr != nil {
|
||||||
logrus.WithError(queryErr).WithField("sender_id", ev.SenderID()).Warn("failed to query userprofile")
|
logrus.WithError(queryErr).WithField("sender_id", ev.SenderID()).Warn("failed to query userprofile")
|
||||||
continue
|
continue
|
||||||
|
@ -218,7 +213,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
|
|
||||||
profile, ok := knownUsersProfiles[userID.String()]
|
profile, ok := knownUsersProfiles[userID.String()]
|
||||||
if !ok {
|
if !ok {
|
||||||
stateEvent, stateErr := snapshot.GetStateEvent(ctx, ev.RoomID(), spec.MRoomMember, string(ev.SenderID()))
|
stateEvent, stateErr := snapshot.GetStateEvent(ctx, ev.RoomID().String(), spec.MRoomMember, string(ev.SenderID()))
|
||||||
if stateErr != nil {
|
if stateErr != nil {
|
||||||
logrus.WithError(stateErr).WithField("sender_id", event.SenderID()).Warn("failed to query userprofile")
|
logrus.WithError(stateErr).WithField("sender_id", event.SenderID()).Warn("failed to query userprofile")
|
||||||
continue
|
continue
|
||||||
|
@ -236,19 +231,14 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
}
|
}
|
||||||
|
|
||||||
sender := spec.UserID{}
|
sender := spec.UserID{}
|
||||||
validRoomID, roomErr := spec.NewRoomID(event.RoomID())
|
userID, err := rsAPI.QueryUserIDForSender(req.Context(), event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
logrus.WithError(roomErr).WithField("room_id", event.RoomID()).Warn("failed to query userprofile")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
userID, err := rsAPI.QueryUserIDForSender(req.Context(), *validRoomID, event.SenderID())
|
|
||||||
if err == nil && userID != nil {
|
if err == nil && userID != nil {
|
||||||
sender = *userID
|
sender = *userID
|
||||||
}
|
}
|
||||||
|
|
||||||
sk := event.StateKey()
|
sk := event.StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
skUserID, err := rsAPI.QueryUserIDForSender(req.Context(), *validRoomID, spec.SenderID(*event.StateKey()))
|
skUserID, err := rsAPI.QueryUserIDForSender(req.Context(), event.RoomID(), spec.SenderID(*event.StateKey()))
|
||||||
if err == nil && skUserID != nil {
|
if err == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
@ -269,12 +259,12 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
Rank: eventScore[event.EventID()].Score,
|
Rank: eventScore[event.EventID()].Score,
|
||||||
Result: synctypes.ToClientEvent(event, synctypes.FormatAll, sender.String(), sk, event.Unsigned()),
|
Result: synctypes.ToClientEvent(event, synctypes.FormatAll, sender.String(), sk, event.Unsigned()),
|
||||||
})
|
})
|
||||||
roomGroup := groups[event.RoomID()]
|
roomGroup := groups[event.RoomID().String()]
|
||||||
roomGroup.Results = append(roomGroup.Results, event.EventID())
|
roomGroup.Results = append(roomGroup.Results, event.EventID())
|
||||||
groups[event.RoomID()] = roomGroup
|
groups[event.RoomID().String()] = roomGroup
|
||||||
if _, ok := stateForRooms[event.RoomID()]; searchReq.SearchCategories.RoomEvents.IncludeState && !ok {
|
if _, ok := stateForRooms[event.RoomID().String()]; searchReq.SearchCategories.RoomEvents.IncludeState && !ok {
|
||||||
stateFilter := synctypes.DefaultStateFilter()
|
stateFilter := synctypes.DefaultStateFilter()
|
||||||
state, err := snapshot.CurrentState(ctx, event.RoomID(), &stateFilter, nil)
|
state, err := snapshot.CurrentState(ctx, event.RoomID().String(), &stateFilter, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("unable to get current state")
|
logrus.WithError(err).Error("unable to get current state")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
|
@ -282,7 +272,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
JSON: spec.InternalServerError{},
|
JSON: spec.InternalServerError{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stateForRooms[event.RoomID()] = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(state), synctypes.FormatSync, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
stateForRooms[event.RoomID().String()] = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(state), synctypes.FormatSync, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||||
return rsAPI.QueryUserIDForSender(req.Context(), roomID, senderID)
|
return rsAPI.QueryUserIDForSender(req.Context(), roomID, senderID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -328,19 +318,19 @@ func contextEvents(
|
||||||
roomFilter *synctypes.RoomEventFilter,
|
roomFilter *synctypes.RoomEventFilter,
|
||||||
searchReq SearchRequest,
|
searchReq SearchRequest,
|
||||||
) ([]*types.HeaderedEvent, []*types.HeaderedEvent, error) {
|
) ([]*types.HeaderedEvent, []*types.HeaderedEvent, error) {
|
||||||
id, _, err := snapshot.SelectContextEvent(ctx, event.RoomID(), event.EventID())
|
id, _, err := snapshot.SelectContextEvent(ctx, event.RoomID().String(), event.EventID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("failed to query context event")
|
logrus.WithError(err).Error("failed to query context event")
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
roomFilter.Limit = searchReq.SearchCategories.RoomEvents.EventContext.BeforeLimit
|
roomFilter.Limit = searchReq.SearchCategories.RoomEvents.EventContext.BeforeLimit
|
||||||
eventsBefore, err := snapshot.SelectContextBeforeEvent(ctx, id, event.RoomID(), roomFilter)
|
eventsBefore, err := snapshot.SelectContextBeforeEvent(ctx, id, event.RoomID().String(), roomFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("failed to query before context event")
|
logrus.WithError(err).Error("failed to query before context event")
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
roomFilter.Limit = searchReq.SearchCategories.RoomEvents.EventContext.AfterLimit
|
roomFilter.Limit = searchReq.SearchCategories.RoomEvents.EventContext.AfterLimit
|
||||||
_, eventsAfter, err := snapshot.SelectContextAfterEvent(ctx, id, event.RoomID(), roomFilter)
|
_, eventsAfter, err := snapshot.SelectContextAfterEvent(ctx, id, event.RoomID().String(), roomFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("failed to query after context event")
|
logrus.WithError(err).Error("failed to query after context event")
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|
|
@ -238,7 +238,7 @@ func TestSearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
elements = append(elements, fulltext.IndexElement{
|
elements = append(elements, fulltext.IndexElement{
|
||||||
EventID: x.EventID(),
|
EventID: x.EventID(),
|
||||||
RoomID: x.RoomID(),
|
RoomID: x.RoomID().String(),
|
||||||
Content: string(x.Content()),
|
Content: string(x.Content()),
|
||||||
ContentType: x.Type(),
|
ContentType: x.Type(),
|
||||||
StreamPosition: int64(sp),
|
StreamPosition: int64(sp),
|
||||||
|
|
|
@ -340,7 +340,7 @@ func (s *currentRoomStateStatements) UpsertRoomState(
|
||||||
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
|
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
|
||||||
_, err = stmt.ExecContext(
|
_, err = stmt.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
event.RoomID(),
|
event.RoomID().String(),
|
||||||
event.EventID(),
|
event.EventID(),
|
||||||
event.Type(),
|
event.Type(),
|
||||||
event.UserID.String(),
|
event.UserID.String(),
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (s *inviteEventsStatements) InsertInviteEvent(
|
||||||
|
|
||||||
err = sqlutil.TxStmt(txn, s.insertInviteEventStmt).QueryRowContext(
|
err = sqlutil.TxStmt(txn, s.insertInviteEventStmt).QueryRowContext(
|
||||||
ctx,
|
ctx,
|
||||||
inviteEvent.RoomID(),
|
inviteEvent.RoomID().String(),
|
||||||
inviteEvent.EventID(),
|
inviteEvent.EventID(),
|
||||||
inviteEvent.UserID.String(),
|
inviteEvent.UserID.String(),
|
||||||
headeredJSON,
|
headeredJSON,
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (s *membershipsStatements) UpsertMembership(
|
||||||
}
|
}
|
||||||
_, err = sqlutil.TxStmt(txn, s.upsertMembershipStmt).ExecContext(
|
_, err = sqlutil.TxStmt(txn, s.upsertMembershipStmt).ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
event.RoomID(),
|
event.RoomID().String(),
|
||||||
event.StateKeyResolved,
|
event.StateKeyResolved,
|
||||||
membership,
|
membership,
|
||||||
event.EventID(),
|
event.EventID(),
|
||||||
|
|
|
@ -334,7 +334,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
|
||||||
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
needSet := stateNeeded[ev.RoomID()]
|
needSet := stateNeeded[ev.RoomID().String()]
|
||||||
if needSet == nil { // make set if required
|
if needSet == nil { // make set if required
|
||||||
needSet = make(map[string]bool)
|
needSet = make(map[string]bool)
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
|
||||||
for _, id := range addIDs {
|
for _, id := range addIDs {
|
||||||
needSet[id] = true
|
needSet[id] = true
|
||||||
}
|
}
|
||||||
stateNeeded[ev.RoomID()] = needSet
|
stateNeeded[ev.RoomID().String()] = needSet
|
||||||
ev.Visibility = historyVisibility
|
ev.Visibility = historyVisibility
|
||||||
|
|
||||||
eventIDToEvent[eventID] = types.StreamEvent{
|
eventIDToEvent[eventID] = types.StreamEvent{
|
||||||
|
@ -403,7 +403,7 @@ func (s *outputRoomEventsStatements) InsertEvent(
|
||||||
stmt := sqlutil.TxStmt(txn, s.insertEventStmt)
|
stmt := sqlutil.TxStmt(txn, s.insertEventStmt)
|
||||||
err = stmt.QueryRowContext(
|
err = stmt.QueryRowContext(
|
||||||
ctx,
|
ctx,
|
||||||
event.RoomID(),
|
event.RoomID().String(),
|
||||||
event.EventID(),
|
event.EventID(),
|
||||||
headeredJSON,
|
headeredJSON,
|
||||||
event.Type(),
|
event.Type(),
|
||||||
|
|
|
@ -107,7 +107,7 @@ func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
|
||||||
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
|
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
|
||||||
) (topoPos types.StreamPosition, err error) {
|
) (topoPos types.StreamPosition, err error) {
|
||||||
err = sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).QueryRowContext(
|
err = sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).QueryRowContext(
|
||||||
ctx, event.EventID(), event.Depth(), event.RoomID(), pos,
|
ctx, event.EventID(), event.Depth(), event.RoomID().String(), pos,
|
||||||
).Scan(&topoPos)
|
).Scan(&topoPos)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,14 +114,7 @@ func (d *Database) StreamEventsToEvents(ctx context.Context, device *userapi.Dev
|
||||||
}).WithError(err).Warnf("Failed to add transaction ID to event")
|
}).WithError(err).Warnf("Failed to add transaction ID to event")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
roomID, err := spec.NewRoomID(in[i].RoomID())
|
deviceSenderID, err := rsAPI.QuerySenderIDForUser(ctx, in[i].RoomID(), *userID)
|
||||||
if err != nil {
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"event_id": out[i].EventID(),
|
|
||||||
}).WithError(err).Warnf("Room ID is invalid")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
deviceSenderID, err := rsAPI.QuerySenderIDForUser(ctx, *roomID, *userID)
|
|
||||||
if err != nil || deviceSenderID == nil {
|
if err != nil || deviceSenderID == nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"event_id": out[i].EventID(),
|
"event_id": out[i].EventID(),
|
||||||
|
@ -236,7 +229,7 @@ func (d *Database) UpsertAccountData(
|
||||||
// to account for the fact that the given event is no longer a backwards extremity, but may be marked as such.
|
// to account for the fact that the given event is no longer a backwards extremity, but may be marked as such.
|
||||||
// This function should always be called within a sqlutil.Writer for safety in SQLite.
|
// This function should always be called within a sqlutil.Writer for safety in SQLite.
|
||||||
func (d *Database) handleBackwardExtremities(ctx context.Context, txn *sql.Tx, ev *rstypes.HeaderedEvent) error {
|
func (d *Database) handleBackwardExtremities(ctx context.Context, txn *sql.Tx, ev *rstypes.HeaderedEvent) error {
|
||||||
if err := d.BackwardExtremities.DeleteBackwardExtremity(ctx, txn, ev.RoomID(), ev.EventID()); err != nil {
|
if err := d.BackwardExtremities.DeleteBackwardExtremity(ctx, txn, ev.RoomID().String(), ev.EventID()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +250,7 @@ func (d *Database) handleBackwardExtremities(ctx context.Context, txn *sql.Tx, e
|
||||||
|
|
||||||
// If the event is missing, consider it a backward extremity.
|
// If the event is missing, consider it a backward extremity.
|
||||||
if !found {
|
if !found {
|
||||||
if err = d.BackwardExtremities.InsertsBackwardExtremity(ctx, txn, ev.RoomID(), ev.EventID(), eID); err != nil {
|
if err = d.BackwardExtremities.InsertsBackwardExtremity(ctx, txn, ev.RoomID().String(), ev.EventID(), eID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,7 +419,7 @@ func (d *Database) fetchStateEvents(
|
||||||
}
|
}
|
||||||
// we know we got them all otherwise an error would've been returned, so just loop the events
|
// we know we got them all otherwise an error would've been returned, so just loop the events
|
||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
roomID := ev.RoomID()
|
roomID := ev.RoomID().String()
|
||||||
stateBetween[roomID] = append(stateBetween[roomID], ev)
|
stateBetween[roomID] = append(stateBetween[roomID], ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -522,11 +515,7 @@ func getMembershipFromEvent(ctx context.Context, ev gomatrixserverlib.PDU, userI
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
roomID, err := spec.NewRoomID(ev.RoomID())
|
senderID, err := rsAPI.QuerySenderIDForUser(ctx, ev.RoomID(), *fullUser)
|
||||||
if err != nil {
|
|
||||||
return "", ""
|
|
||||||
}
|
|
||||||
senderID, err := rsAPI.QuerySenderIDForUser(ctx, *roomID, *fullUser)
|
|
||||||
if err != nil || senderID == nil {
|
if err != nil || senderID == nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
@ -626,7 +615,7 @@ func (d *Database) UpdateRelations(ctx context.Context, event *rstypes.HeaderedE
|
||||||
default:
|
default:
|
||||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.Relations.InsertRelation(
|
return d.Relations.InsertRelation(
|
||||||
ctx, txn, event.RoomID(), content.Relations.EventID,
|
ctx, txn, event.RoomID().String(), content.Relations.EventID,
|
||||||
event.EventID(), event.Type(), content.Relations.RelationType,
|
event.EventID(), event.Type(), content.Relations.RelationType,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -339,7 +339,7 @@ func (s *currentRoomStateStatements) UpsertRoomState(
|
||||||
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
|
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
|
||||||
_, err = stmt.ExecContext(
|
_, err = stmt.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
event.RoomID(),
|
event.RoomID().String(),
|
||||||
event.EventID(),
|
event.EventID(),
|
||||||
event.Type(),
|
event.Type(),
|
||||||
event.UserID.String(),
|
event.UserID.String(),
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (s *inviteEventsStatements) InsertInviteEvent(
|
||||||
_, err = stmt.ExecContext(
|
_, err = stmt.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
streamPos,
|
streamPos,
|
||||||
inviteEvent.RoomID(),
|
inviteEvent.RoomID().String(),
|
||||||
inviteEvent.EventID(),
|
inviteEvent.EventID(),
|
||||||
inviteEvent.UserID.String(),
|
inviteEvent.UserID.String(),
|
||||||
headeredJSON,
|
headeredJSON,
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (s *membershipsStatements) UpsertMembership(
|
||||||
}
|
}
|
||||||
_, err = sqlutil.TxStmt(txn, s.upsertMembershipStmt).ExecContext(
|
_, err = sqlutil.TxStmt(txn, s.upsertMembershipStmt).ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
event.RoomID(),
|
event.RoomID().String(),
|
||||||
event.StateKeyResolved,
|
event.StateKeyResolved,
|
||||||
membership,
|
membership,
|
||||||
event.EventID(),
|
event.EventID(),
|
||||||
|
|
|
@ -254,7 +254,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
|
||||||
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
needSet := stateNeeded[ev.RoomID()]
|
needSet := stateNeeded[ev.RoomID().String()]
|
||||||
if needSet == nil { // make set if required
|
if needSet == nil { // make set if required
|
||||||
needSet = make(map[string]bool)
|
needSet = make(map[string]bool)
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
|
||||||
for _, id := range addIDs {
|
for _, id := range addIDs {
|
||||||
needSet[id] = true
|
needSet[id] = true
|
||||||
}
|
}
|
||||||
stateNeeded[ev.RoomID()] = needSet
|
stateNeeded[ev.RoomID().String()] = needSet
|
||||||
ev.Visibility = historyVisibility
|
ev.Visibility = historyVisibility
|
||||||
|
|
||||||
eventIDToEvent[eventID] = types.StreamEvent{
|
eventIDToEvent[eventID] = types.StreamEvent{
|
||||||
|
@ -344,7 +344,7 @@ func (s *outputRoomEventsStatements) InsertEvent(
|
||||||
_, err = insertStmt.ExecContext(
|
_, err = insertStmt.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
streamPos,
|
streamPos,
|
||||||
event.RoomID(),
|
event.RoomID().String(),
|
||||||
event.EventID(),
|
event.EventID(),
|
||||||
headeredJSON,
|
headeredJSON,
|
||||||
event.Type(),
|
event.Type(),
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
|
||||||
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
|
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
|
||||||
) (types.StreamPosition, error) {
|
) (types.StreamPosition, error) {
|
||||||
_, err := sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).ExecContext(
|
_, err := sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).ExecContext(
|
||||||
ctx, event.EventID(), event.Depth(), event.RoomID(), pos,
|
ctx, event.EventID(), event.Depth(), event.RoomID().String(), pos,
|
||||||
)
|
)
|
||||||
return types.StreamPosition(event.Depth()), err
|
return types.StreamPosition(event.Depth()), err
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,18 +70,14 @@ func (p *InviteStreamProvider) IncrementalSync(
|
||||||
|
|
||||||
for roomID, inviteEvent := range invites {
|
for roomID, inviteEvent := range invites {
|
||||||
user := spec.UserID{}
|
user := spec.UserID{}
|
||||||
validRoomID, err := spec.NewRoomID(inviteEvent.RoomID())
|
sender, err := p.rsAPI.QueryUserIDForSender(ctx, inviteEvent.RoomID(), inviteEvent.SenderID())
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sender, err := p.rsAPI.QueryUserIDForSender(ctx, *validRoomID, inviteEvent.SenderID())
|
|
||||||
if err == nil && sender != nil {
|
if err == nil && sender != nil {
|
||||||
user = *sender
|
user = *sender
|
||||||
}
|
}
|
||||||
|
|
||||||
sk := inviteEvent.StateKey()
|
sk := inviteEvent.StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
skUserID, err := p.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*inviteEvent.StateKey()))
|
skUserID, err := p.rsAPI.QueryUserIDForSender(ctx, inviteEvent.RoomID(), spec.SenderID(*inviteEvent.StateKey()))
|
||||||
if err == nil && skUserID != nil {
|
if err == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
|
|
@ -476,9 +476,8 @@ func (p *PDUStreamProvider) updatePowerLevelEvent(ctx context.Context, ev *rstyp
|
||||||
newPls := make(map[string]int64)
|
newPls := make(map[string]int64)
|
||||||
var userID *spec.UserID
|
var userID *spec.UserID
|
||||||
for user, level := range pls.Users {
|
for user, level := range pls.Users {
|
||||||
validRoomID, _ := spec.NewRoomID(ev.RoomID())
|
|
||||||
if eventFormat != synctypes.FormatSyncFederation {
|
if eventFormat != synctypes.FormatSyncFederation {
|
||||||
userID, err = p.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(user))
|
userID, err = p.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(user))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -515,9 +514,8 @@ func (p *PDUStreamProvider) updatePowerLevelEvent(ctx context.Context, ev *rstyp
|
||||||
|
|
||||||
newPls = make(map[string]int64)
|
newPls = make(map[string]int64)
|
||||||
for user, level := range pls.Users {
|
for user, level := range pls.Users {
|
||||||
validRoomID, _ := spec.NewRoomID(ev.RoomID())
|
|
||||||
if eventFormat != synctypes.FormatSyncFederation {
|
if eventFormat != synctypes.FormatSyncFederation {
|
||||||
userID, err = p.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(user))
|
userID, err = p.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(user))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1401,7 +1401,7 @@ func toNATSMsgs(t *testing.T, cfg *config.Dendrite, input ...*rstypes.HeaderedEv
|
||||||
if ev.StateKey() != nil {
|
if ev.StateKey() != nil {
|
||||||
addsStateIDs = append(addsStateIDs, ev.EventID())
|
addsStateIDs = append(addsStateIDs, ev.EventID())
|
||||||
}
|
}
|
||||||
result[i] = testrig.NewOutputEventMsg(t, cfg, ev.RoomID(), api.OutputEvent{
|
result[i] = testrig.NewOutputEventMsg(t, cfg, ev.RoomID().String(), api.OutputEvent{
|
||||||
Type: rsapi.OutputTypeNewRoomEvent,
|
Type: rsapi.OutputTypeNewRoomEvent,
|
||||||
NewRoomEvent: &rsapi.OutputNewRoomEvent{
|
NewRoomEvent: &rsapi.OutputNewRoomEvent{
|
||||||
Event: ev,
|
Event: ev,
|
||||||
|
|
|
@ -84,18 +84,14 @@ func ToClientEvents(serverEvs []gomatrixserverlib.PDU, format ClientEventFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
sender := spec.UserID{}
|
sender := spec.UserID{}
|
||||||
validRoomID, err := spec.NewRoomID(se.RoomID())
|
userID, err := userIDForSender(se.RoomID(), se.SenderID())
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
userID, err := userIDForSender(*validRoomID, se.SenderID())
|
|
||||||
if err == nil && userID != nil {
|
if err == nil && userID != nil {
|
||||||
sender = *userID
|
sender = *userID
|
||||||
}
|
}
|
||||||
|
|
||||||
sk := se.StateKey()
|
sk := se.StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
skUserID, err := userIDForSender(*validRoomID, spec.SenderID(*sk))
|
skUserID, err := userIDForSender(se.RoomID(), spec.SenderID(*sk))
|
||||||
if err == nil && skUserID != nil {
|
if err == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
@ -105,7 +101,7 @@ func ToClientEvents(serverEvs []gomatrixserverlib.PDU, format ClientEventFormat,
|
||||||
unsigned := se.Unsigned()
|
unsigned := se.Unsigned()
|
||||||
var prev PrevEventRef
|
var prev PrevEventRef
|
||||||
if err := json.Unmarshal(se.Unsigned(), &prev); err == nil && prev.PrevSenderID != "" {
|
if err := json.Unmarshal(se.Unsigned(), &prev); err == nil && prev.PrevSenderID != "" {
|
||||||
prevUserID, err := userIDForSender(*validRoomID, spec.SenderID(prev.PrevSenderID))
|
prevUserID, err := userIDForSender(se.RoomID(), spec.SenderID(prev.PrevSenderID))
|
||||||
if err == nil && userID != nil {
|
if err == nil && userID != nil {
|
||||||
prev.PrevSenderID = prevUserID.String()
|
prev.PrevSenderID = prevUserID.String()
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,10 +138,10 @@ func ToClientEvent(se gomatrixserverlib.PDU, format ClientEventFormat, sender st
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case FormatAll:
|
case FormatAll:
|
||||||
ce.RoomID = se.RoomID()
|
ce.RoomID = se.RoomID().String()
|
||||||
case FormatSync:
|
case FormatSync:
|
||||||
case FormatSyncFederation:
|
case FormatSyncFederation:
|
||||||
ce.RoomID = se.RoomID()
|
ce.RoomID = se.RoomID().String()
|
||||||
ce.AuthEvents = se.AuthEventIDs()
|
ce.AuthEvents = se.AuthEventIDs()
|
||||||
ce.PrevEvents = se.PrevEventIDs()
|
ce.PrevEvents = se.PrevEventIDs()
|
||||||
ce.Depth = se.Depth()
|
ce.Depth = se.Depth()
|
||||||
|
@ -164,18 +160,14 @@ func ToClientEvent(se gomatrixserverlib.PDU, format ClientEventFormat, sender st
|
||||||
// It provides default logic for event.SenderID & event.StateKey -> userID conversions.
|
// It provides default logic for event.SenderID & event.StateKey -> userID conversions.
|
||||||
func ToClientEventDefault(userIDQuery spec.UserIDForSender, event gomatrixserverlib.PDU) ClientEvent {
|
func ToClientEventDefault(userIDQuery spec.UserIDForSender, event gomatrixserverlib.PDU) ClientEvent {
|
||||||
sender := spec.UserID{}
|
sender := spec.UserID{}
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
userID, err := userIDQuery(event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return ClientEvent{}
|
|
||||||
}
|
|
||||||
userID, err := userIDQuery(*validRoomID, event.SenderID())
|
|
||||||
if err == nil && userID != nil {
|
if err == nil && userID != nil {
|
||||||
sender = *userID
|
sender = *userID
|
||||||
}
|
}
|
||||||
|
|
||||||
sk := event.StateKey()
|
sk := event.StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
skUserID, err := userIDQuery(*validRoomID, spec.SenderID(*event.StateKey()))
|
skUserID, err := userIDQuery(event.RoomID(), spec.SenderID(*event.StateKey()))
|
||||||
if err == nil && skUserID != nil {
|
if err == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msgs []*nats.Ms
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.cfg.Matrix.ReportStats.Enabled {
|
if s.cfg.Matrix.ReportStats.Enabled {
|
||||||
go s.storeMessageStats(ctx, event.Type(), string(event.SenderID()), event.RoomID())
|
go s.storeMessageStats(ctx, event.Type(), string(event.SenderID()), event.RoomID().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
@ -294,7 +294,7 @@ func (s *OutputRoomEventConsumer) copyTags(ctx context.Context, oldRoomID, newRo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rstypes.HeaderedEvent, streamPos uint64) error {
|
func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rstypes.HeaderedEvent, streamPos uint64) error {
|
||||||
members, roomSize, err := s.localRoomMembers(ctx, event.RoomID())
|
members, roomSize, err := s.localRoomMembers(ctx, event.RoomID().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("s.localRoomMembers: %w", err)
|
return fmt.Errorf("s.localRoomMembers: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -302,18 +302,14 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rst
|
||||||
switch {
|
switch {
|
||||||
case event.Type() == spec.MRoomMember:
|
case event.Type() == spec.MRoomMember:
|
||||||
sender := spec.UserID{}
|
sender := spec.UserID{}
|
||||||
validRoomID, roomErr := spec.NewRoomID(event.RoomID())
|
userID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
|
||||||
if roomErr != nil {
|
|
||||||
return roomErr
|
|
||||||
}
|
|
||||||
userID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
|
|
||||||
if queryErr == nil && userID != nil {
|
if queryErr == nil && userID != nil {
|
||||||
sender = *userID
|
sender = *userID
|
||||||
}
|
}
|
||||||
|
|
||||||
sk := event.StateKey()
|
sk := event.StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
skUserID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*sk))
|
skUserID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), spec.SenderID(*sk))
|
||||||
if queryErr == nil && skUserID != nil {
|
if queryErr == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
@ -334,7 +330,7 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rst
|
||||||
}
|
}
|
||||||
case event.Type() == "m.room.tombstone" && event.StateKeyEquals(""):
|
case event.Type() == "m.room.tombstone" && event.StateKeyEquals(""):
|
||||||
// Handle room upgrades
|
// Handle room upgrades
|
||||||
oldRoomID := event.RoomID()
|
oldRoomID := event.RoomID().String()
|
||||||
newRoomID := gjson.GetBytes(event.Content(), "replacement_room").Str
|
newRoomID := gjson.GetBytes(event.Content(), "replacement_room").Str
|
||||||
if err = s.handleRoomUpgrade(ctx, oldRoomID, newRoomID, members, roomSize); err != nil {
|
if err = s.handleRoomUpgrade(ctx, oldRoomID, newRoomID, members, roomSize); err != nil {
|
||||||
// while inconvenient, this shouldn't stop us from sending push notifications
|
// while inconvenient, this shouldn't stop us from sending push notifications
|
||||||
|
@ -351,7 +347,7 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rst
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
"num_members": len(members),
|
"num_members": len(members),
|
||||||
"room_size": roomSize,
|
"room_size": roomSize,
|
||||||
}).Tracef("Notifying members")
|
}).Tracef("Notifying members")
|
||||||
|
@ -464,7 +460,7 @@ func (s *OutputRoomEventConsumer) roomName(ctx context.Context, event *rstypes.H
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &rsapi.QueryCurrentStateRequest{
|
req := &rsapi.QueryCurrentStateRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
StateTuples: []gomatrixserverlib.StateKeyTuple{roomNameTuple, canonicalAliasTuple},
|
StateTuples: []gomatrixserverlib.StateKeyTuple{roomNameTuple, canonicalAliasTuple},
|
||||||
}
|
}
|
||||||
var res rsapi.QueryCurrentStateResponse
|
var res rsapi.QueryCurrentStateResponse
|
||||||
|
@ -532,7 +528,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
|
||||||
if a != pushrules.NotifyAction && a != pushrules.CoalesceAction {
|
if a != pushrules.NotifyAction && a != pushrules.CoalesceAction {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
"localpart": mem.Localpart,
|
"localpart": mem.Localpart,
|
||||||
}).Tracef("Push rule evaluation rejected the event")
|
}).Tracef("Push rule evaluation rejected the event")
|
||||||
return nil
|
return nil
|
||||||
|
@ -544,18 +540,14 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
|
||||||
}
|
}
|
||||||
|
|
||||||
sender := spec.UserID{}
|
sender := spec.UserID{}
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
userID, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
|
|
||||||
if err == nil && userID != nil {
|
if err == nil && userID != nil {
|
||||||
sender = *userID
|
sender = *userID
|
||||||
}
|
}
|
||||||
|
|
||||||
sk := event.StateKey()
|
sk := event.StateKey()
|
||||||
if sk != nil && *sk != "" {
|
if sk != nil && *sk != "" {
|
||||||
skUserID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*event.StateKey()))
|
skUserID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), spec.SenderID(*event.StateKey()))
|
||||||
if queryErr == nil && skUserID != nil {
|
if queryErr == nil && skUserID != nil {
|
||||||
skString := skUserID.String()
|
skString := skUserID.String()
|
||||||
sk = &skString
|
sk = &skString
|
||||||
|
@ -572,14 +564,14 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
|
||||||
// make sense. What is this supposed to be? Sytests require it
|
// make sense. What is this supposed to be? Sytests require it
|
||||||
// to "work", but they only use a single device.
|
// to "work", but they only use a single device.
|
||||||
ProfileTag: profileTag,
|
ProfileTag: profileTag,
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
TS: spec.AsTimestamp(time.Now()),
|
TS: spec.AsTimestamp(time.Now()),
|
||||||
}
|
}
|
||||||
if err = s.db.InsertNotification(ctx, mem.Localpart, mem.Domain, event.EventID(), streamPos, tweaks, n); err != nil {
|
if err = s.db.InsertNotification(ctx, mem.Localpart, mem.Domain, event.EventID(), streamPos, tweaks, n); err != nil {
|
||||||
return fmt.Errorf("s.db.InsertNotification: %w", err)
|
return fmt.Errorf("s.db.InsertNotification: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = s.syncProducer.GetAndSendNotificationData(ctx, mem.UserID, event.RoomID()); err != nil {
|
if err = s.syncProducer.GetAndSendNotificationData(ctx, mem.UserID, event.RoomID().String()); err != nil {
|
||||||
return fmt.Errorf("s.syncProducer.GetAndSendNotificationData: %w", err)
|
return fmt.Errorf("s.syncProducer.GetAndSendNotificationData: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,7 +583,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
"localpart": mem.Localpart,
|
"localpart": mem.Localpart,
|
||||||
"num_urls": len(devicesByURLAndFormat),
|
"num_urls": len(devicesByURLAndFormat),
|
||||||
"num_unread": userNumUnreadNotifs,
|
"num_unread": userNumUnreadNotifs,
|
||||||
|
@ -648,11 +640,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
|
||||||
// user. Returns actions (including dont_notify).
|
// user. Returns actions (including dont_notify).
|
||||||
func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *rstypes.HeaderedEvent, mem *localMembership, roomSize int) ([]*pushrules.Action, error) {
|
func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *rstypes.HeaderedEvent, mem *localMembership, roomSize int) ([]*pushrules.Action, error) {
|
||||||
user := ""
|
user := ""
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
sender, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sender, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
user = sender.String()
|
user = sender.String()
|
||||||
}
|
}
|
||||||
|
@ -686,7 +674,7 @@ func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
rsAPI: s.rsAPI,
|
rsAPI: s.rsAPI,
|
||||||
mem: mem,
|
mem: mem,
|
||||||
roomID: event.RoomID(),
|
roomID: event.RoomID().String(),
|
||||||
roomSize: roomSize,
|
roomSize: roomSize,
|
||||||
}
|
}
|
||||||
eval := pushrules.NewRuleSetEvaluator(ec, &ruleSets.Global)
|
eval := pushrules.NewRuleSetEvaluator(ec, &ruleSets.Global)
|
||||||
|
@ -704,7 +692,7 @@ func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID().String(),
|
||||||
"localpart": mem.Localpart,
|
"localpart": mem.Localpart,
|
||||||
"rule_id": rule.RuleID,
|
"rule_id": rule.RuleID,
|
||||||
}).Trace("Matched a push rule")
|
}).Trace("Matched a push rule")
|
||||||
|
@ -793,16 +781,12 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *rstypes
|
||||||
},
|
},
|
||||||
Devices: devices,
|
Devices: devices,
|
||||||
EventID: event.EventID(),
|
EventID: event.EventID(),
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
validRoomID, err := spec.NewRoomID(event.RoomID())
|
sender, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sender, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithError(err).Errorf("Failed to get userID for sender %s", event.SenderID())
|
logger.WithError(err).Errorf("Failed to get userID for sender %s", event.SenderID())
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -816,7 +800,7 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *rstypes
|
||||||
Devices: devices,
|
Devices: devices,
|
||||||
EventID: event.EventID(),
|
EventID: event.EventID(),
|
||||||
ID: event.EventID(),
|
ID: event.EventID(),
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID().String(),
|
||||||
RoomName: roomName,
|
RoomName: roomName,
|
||||||
Sender: sender.String(),
|
Sender: sender.String(),
|
||||||
Type: event.Type(),
|
Type: event.Type(),
|
||||||
|
@ -830,19 +814,13 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *rstypes
|
||||||
logger.WithError(err).Errorf("Failed to convert local user to userID %s", localpart)
|
logger.WithError(err).Errorf("Failed to convert local user to userID %s", localpart)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
roomID, err := spec.NewRoomID(event.RoomID())
|
localSender, err := s.rsAPI.QuerySenderIDForUser(ctx, event.RoomID(), *userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithError(err).Errorf("event roomID is invalid %s", event.RoomID())
|
logger.WithError(err).Errorf("Failed to get local user senderID for room %s: %s", userID.String(), event.RoomID().String())
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
localSender, err := s.rsAPI.QuerySenderIDForUser(ctx, *roomID, *userID)
|
|
||||||
if err != nil {
|
|
||||||
logger.WithError(err).Errorf("Failed to get local user senderID for room %s: %s", userID.String(), event.RoomID())
|
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if localSender == nil {
|
} else if localSender == nil {
|
||||||
logger.WithError(err).Errorf("Failed to get local user senderID for room %s: %s", userID.String(), event.RoomID())
|
logger.WithError(err).Errorf("Failed to get local user senderID for room %s: %s", userID.String(), event.RoomID().String())
|
||||||
return nil, fmt.Errorf("no sender ID for user %s in %s", userID.String(), roomID.String())
|
return nil, fmt.Errorf("no sender ID for user %s in %s", userID.String(), event.RoomID().String())
|
||||||
}
|
}
|
||||||
if event.StateKey() != nil && *event.StateKey() == string(*localSender) {
|
if event.StateKey() != nil && *event.StateKey() == string(*localSender) {
|
||||||
req.Notification.UserIsTarget = true
|
req.Notification.UserIsTarget = true
|
||||||
|
|
Loading…
Reference in a new issue