aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordevonh <devon.dmytro@gmail.com>2023-09-15 14:39:06 +0000
committerGitHub <noreply@github.com>2023-09-15 14:39:06 +0000
commit8245b24100b0afaa046bb3fe52f0994f906c8ab1 (patch)
treef8d65fd4c27e208e5829f5ca0f66d79c639fabdb
parent058081e68e4e23400645c6206cedddba8a31507e (diff)
Update gmsl to use new validated RoomID on PDUs (#3200)
GMSL returns a `spec.RoomID` when calling `PDU.RoomID()`
-rw-r--r--appservice/consumers/roomserver.go18
-rw-r--r--clientapi/routing/redaction.go2
-rw-r--r--clientapi/routing/sendevent.go2
-rw-r--r--clientapi/routing/state.go9
-rw-r--r--federationapi/consumers/roomserver.go16
-rw-r--r--federationapi/federationapi_test.go2
-rw-r--r--federationapi/internal/perform.go8
-rw-r--r--federationapi/queue/queue.go2
-rw-r--r--federationapi/queue/queue_test.go2
-rw-r--r--federationapi/routing/backfill.go2
-rw-r--r--federationapi/routing/eventauth.go4
-rw-r--r--federationapi/routing/events.go2
-rw-r--r--federationapi/routing/leave.go11
-rw-r--r--federationapi/routing/missingevents.go2
-rw-r--r--federationapi/routing/state.go4
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--internal/eventutil/events.go6
-rw-r--r--internal/pushrules/evaluate.go8
-rw-r--r--internal/pushrules/evaluate_test.go91
-rw-r--r--internal/transactionrequest.go2
-rw-r--r--roomserver/acls/acls.go2
-rw-r--r--roomserver/api/wrapper.go2
-rw-r--r--roomserver/auth/auth.go6
-rw-r--r--roomserver/internal/alias.go2
-rw-r--r--roomserver/internal/api.go2
-rw-r--r--roomserver/internal/helpers/auth.go4
-rw-r--r--roomserver/internal/helpers/helpers.go6
-rw-r--r--roomserver/internal/input/input.go2
-rw-r--r--roomserver/internal/input/input_events.go54
-rw-r--r--roomserver/internal/input/input_latest_events.go4
-rw-r--r--roomserver/internal/input/input_membership.go10
-rw-r--r--roomserver/internal/input/input_missing.go14
-rw-r--r--roomserver/internal/perform/perform_backfill.go8
-rw-r--r--roomserver/internal/perform/perform_invite.go8
-rw-r--r--roomserver/internal/query/query_room_hierarchy.go4
-rw-r--r--roomserver/internal/query/query_test.go1
-rw-r--r--roomserver/storage/shared/storage.go21
-rw-r--r--setup/mscs/msc2836/msc2836.go10
-rw-r--r--setup/mscs/msc2836/storage.go2
-rw-r--r--syncapi/consumers/clientapi.go2
-rw-r--r--syncapi/consumers/roomserver.go55
-rw-r--r--syncapi/internal/history_visibility.go13
-rw-r--r--syncapi/notifier/notifier.go17
-rw-r--r--syncapi/routing/getevent.go9
-rw-r--r--syncapi/routing/memberships.go10
-rw-r--r--syncapi/routing/search.go34
-rw-r--r--syncapi/routing/search_test.go2
-rw-r--r--syncapi/storage/postgres/current_room_state_table.go2
-rw-r--r--syncapi/storage/postgres/invites_table.go2
-rw-r--r--syncapi/storage/postgres/memberships_table.go2
-rw-r--r--syncapi/storage/postgres/output_room_events_table.go6
-rw-r--r--syncapi/storage/postgres/output_room_events_topology_table.go2
-rw-r--r--syncapi/storage/shared/storage_consumer.go23
-rw-r--r--syncapi/storage/sqlite3/current_room_state_table.go2
-rw-r--r--syncapi/storage/sqlite3/invites_table.go2
-rw-r--r--syncapi/storage/sqlite3/memberships_table.go2
-rw-r--r--syncapi/storage/sqlite3/output_room_events_table.go6
-rw-r--r--syncapi/storage/sqlite3/output_room_events_topology_table.go2
-rw-r--r--syncapi/streams/stream_invite.go8
-rw-r--r--syncapi/streams/stream_pdu.go6
-rw-r--r--syncapi/syncapi_test.go2
-rw-r--r--syncapi/synctypes/clientevent.go22
-rw-r--r--userapi/consumers/roomserver.go68
64 files changed, 244 insertions, 416 deletions
diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go
index 1877de37..e8b9211c 100644
--- a/appservice/consumers/roomserver.go
+++ b/appservice/consumers/roomserver.go
@@ -128,7 +128,7 @@ func (s *OutputRoomEventConsumer) onMessage(
if len(output.NewRoomEvent.AddsStateEventIDs) > 0 {
newEventID := output.NewRoomEvent.Event.EventID()
eventsReq := &api.QueryEventsByIDRequest{
- RoomID: output.NewRoomEvent.Event.RoomID(),
+ RoomID: output.NewRoomEvent.Event.RoomID().String(),
EventIDs: make([]string, 0, len(output.NewRoomEvent.AddsStateEventIDs)),
}
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
func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Context, event *types.HeaderedEvent, appservice *config.ApplicationService) bool {
user := ""
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return false
- }
- userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
+ userID, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err == nil {
user = userID.String()
}
@@ -250,7 +246,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
return false
case appservice.IsInterestedInUserID(user):
return true
- case appservice.IsInterestedInRoomID(event.RoomID()):
+ case appservice.IsInterestedInRoomID(event.RoomID().String()):
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
- queryReq := api.GetAliasesForRoomIDRequest{RoomID: event.RoomID()}
+ queryReq := api.GetAliasesForRoomIDRequest{RoomID: event.RoomID().String()}
var queryRes api.GetAliasesForRoomIDResponse
if err := s.rsAPI.GetAliasesForRoomID(ctx, &queryReq, &queryRes); err == nil {
for _, alias := range queryRes.Aliases {
@@ -272,7 +268,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
} else {
log.WithFields(log.Fields{
"appservice": appservice.ID,
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
}).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
// doesn't involve state res, then this is probably OK.
membershipReq := &api.QueryMembershipsForRoomRequest{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
JoinedOnly: true,
}
membershipRes := &api.QueryMembershipsForRoomResponse{}
@@ -317,7 +313,7 @@ func (s *OutputRoomEventConsumer) appserviceJoinedAtEvent(ctx context.Context, e
} else {
log.WithFields(log.Fields{
"appservice": appservice.ID,
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
}).WithError(err).Errorf("Unable to get membership for room")
}
return false
diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go
index 230c96d2..aa579db6 100644
--- a/clientapi/routing/redaction.go
+++ b/clientapi/routing/redaction.go
@@ -98,7 +98,7 @@ func SendRedaction(
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{
Code: 400,
JSON: spec.NotFound("cannot redact event in another room"),
diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go
index f81e9c1e..fc9c05ba 100644
--- a/clientapi/routing/sendevent.go
+++ b/clientapi/routing/sendevent.go
@@ -437,7 +437,7 @@ func generateSendEvent(
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{
Code: http.StatusBadRequest,
JSON: spec.InvalidParam("Cannot send tombstone event that points to the same room."),
diff --git a/clientapi/routing/state.go b/clientapi/routing/state.go
index d7f0b40f..6f363349 100644
--- a/clientapi/routing/state.go
+++ b/clientapi/routing/state.go
@@ -173,19 +173,14 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
}
for _, ev := range stateAfterRes.StateEvents {
sender := spec.UserID{}
- evRoomID, err := spec.NewRoomID(ev.RoomID())
- if err != nil {
- util.GetLogger(ctx).WithError(err).Error("Event roomID is invalid")
- continue
- }
- userID, err := rsAPI.QueryUserIDForSender(ctx, *evRoomID, ev.SenderID())
+ userID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
if err == nil && userID != nil {
sender = *userID
}
sk := ev.StateKey()
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 {
skString := skUserID.String()
sk = &skString
diff --git a/federationapi/consumers/roomserver.go b/federationapi/consumers/roomserver.go
index 6c058032..f1dcb117 100644
--- a/federationapi/consumers/roomserver.go
+++ b/federationapi/consumers/roomserver.go
@@ -176,7 +176,7 @@ func (s *OutputRoomEventConsumer) processMessage(ore api.OutputNewRoomEvent, rew
// Finally, work out if there are any more events missing.
if len(missingEventIDs) > 0 {
eventsReq := &api.QueryEventsByIDRequest{
- RoomID: ore.Event.RoomID(),
+ RoomID: ore.Event.RoomID().String(),
EventIDs: missingEventIDs,
}
eventsRes := &api.QueryEventsByIDResponse{}
@@ -205,7 +205,7 @@ func (s *OutputRoomEventConsumer) processMessage(ore api.OutputNewRoomEvent, rew
// talking to the roomserver
oldJoinedHosts, err := s.db.UpdateRoom(
s.ctx,
- ore.Event.RoomID(),
+ ore.Event.RoomID().String(),
addsJoinedHosts,
ore.RemovesStateEventIDs,
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 {
membership, _ := ore.Event.Membership()
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
- 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 {
return nil, err
}
@@ -409,12 +409,8 @@ func JoinedHostsFromEvents(ctx context.Context, evs []gomatrixserverlib.PDU, rsA
if membership != spec.Join {
continue
}
- validRoomID, err := spec.NewRoomID(ev.RoomID())
- if err != nil {
- return nil, err
- }
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 errors.As(err, new(base64.CorruptInputError)) {
// 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
// they present in our local database. Our only option is to fetch them
// 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
if err := s.rsAPI.QueryEventsByID(s.ctx, &eventReq, &eventResp); err != nil {
return nil, err
diff --git a/federationapi/federationapi_test.go b/federationapi/federationapi_test.go
index 4c2a99bb..1ea8c40e 100644
--- a/federationapi/federationapi_test.go
+++ b/federationapi/federationapi_test.go
@@ -146,7 +146,7 @@ func (f *fedClient) SendJoin(ctx context.Context, origin, s spec.ServerName, eve
f.fedClientMutex.Lock()
defer f.fedClientMutex.Unlock()
for _, r := range f.allowJoins {
- if r.ID == event.RoomID() {
+ if r.ID == event.RoomID().String() {
r.InsertEvent(f.t, &types.HeaderedEvent{PDU: event})
f.t.Logf("Join event: %v", event.EventID())
res.StateEvents = types.NewEventJSONsFromHeaderedEvents(r.CurrentState())
diff --git a/federationapi/internal/perform.go b/federationapi/internal/perform.go
index 3bba3ea0..0200cf69 100644
--- a/federationapi/internal/perform.go
+++ b/federationapi/internal/perform.go
@@ -548,11 +548,7 @@ func (r *FederationInternalAPI) SendInvite(
event gomatrixserverlib.PDU,
strippedState []gomatrixserverlib.InviteStrippedState,
) (gomatrixserverlib.PDU, error) {
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return nil, err
- }
- inviter, err := r.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
+ inviter, err := r.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err != nil {
return nil, err
}
@@ -575,7 +571,7 @@ func (r *FederationInternalAPI) SendInvite(
logrus.WithFields(logrus.Fields{
"event_id": event.EventID(),
"user_id": *event.StateKey(),
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
"room_version": event.Version(),
"destination": destination,
}).Info("Sending invite")
diff --git a/federationapi/queue/queue.go b/federationapi/queue/queue.go
index 26305ed7..24b3efd2 100644
--- a/federationapi/queue/queue.go
+++ b/federationapi/queue/queue.go
@@ -218,7 +218,7 @@ func (oqs *OutgoingQueues) SendEvent(
if api.IsServerBannedFromRoom(
oqs.process.Context(),
oqs.rsAPI,
- ev.RoomID(),
+ ev.RoomID().String(),
destination,
) {
delete(destmap, destination)
diff --git a/federationapi/queue/queue_test.go b/federationapi/queue/queue_test.go
index cc38e136..e75615e0 100644
--- a/federationapi/queue/queue_test.go
+++ b/federationapi/queue/queue_test.go
@@ -104,7 +104,7 @@ func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u
func mustCreatePDU(t *testing.T) *types.HeaderedEvent {
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)
if err != nil {
t.Fatalf("failed to create event: %v", err)
diff --git a/federationapi/routing/backfill.go b/federationapi/routing/backfill.go
index 552c4eac..75a00726 100644
--- a/federationapi/routing/backfill.go
+++ b/federationapi/routing/backfill.go
@@ -109,7 +109,7 @@ func Backfill(
var ev *types.HeaderedEvent
for _, ev = range res.Events {
- if ev.RoomID() == roomID {
+ if ev.RoomID().String() == roomID {
evs = append(evs, ev.PDU)
}
}
diff --git a/federationapi/routing/eventauth.go b/federationapi/routing/eventauth.go
index c26aa2f1..2be3ecdb 100644
--- a/federationapi/routing/eventauth.go
+++ b/federationapi/routing/eventauth.go
@@ -42,10 +42,10 @@ func GetEventAuth(
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")}
}
- resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID())
+ resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID().String())
if resErr != nil {
return *resErr
}
diff --git a/federationapi/routing/events.go b/federationapi/routing/events.go
index d3f0e81c..f4659f52 100644
--- a/federationapi/routing/events.go
+++ b/federationapi/routing/events.go
@@ -42,7 +42,7 @@ func GetEvent(
return *err
}
- err = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID())
+ err = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID().String())
if err != nil {
return *err
}
diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go
index f28c8211..7c86ba69 100644
--- a/federationapi/routing/leave.go
+++ b/federationapi/routing/leave.go
@@ -211,7 +211,7 @@ func SendLeave(
}
// Check that the room ID is correct.
- if event.RoomID() != roomID {
+ if event.RoomID().String() != roomID {
return util.JSONResponse{
Code: http.StatusBadRequest,
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
// 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.
- validRoomID, err := spec.NewRoomID(event.RoomID())
- 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())
+ sender, err := rsAPI.QueryUserIDForSender(httpReq.Context(), event.RoomID(), event.SenderID())
if err != nil {
return util.JSONResponse{
Code: http.StatusForbidden,
diff --git a/federationapi/routing/missingevents.go b/federationapi/routing/missingevents.go
index f57d3020..b1cefe7b 100644
--- a/federationapi/routing/missingevents.go
+++ b/federationapi/routing/missingevents.go
@@ -87,7 +87,7 @@ func filterEvents(
) []*types.HeaderedEvent {
ref := events[:0]
for _, ev := range events {
- if ev.RoomID() == roomID {
+ if ev.RoomID().String() == roomID {
ref = append(ref, ev)
}
}
diff --git a/federationapi/routing/state.go b/federationapi/routing/state.go
index 11ad1ebf..d1091057 100644
--- a/federationapi/routing/state.go
+++ b/federationapi/routing/state.go
@@ -113,10 +113,10 @@ func getState(
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")}
}
- resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID())
+ resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID, event.RoomID().String())
if resErr != nil {
return nil, nil, resErr
}
diff --git a/go.mod b/go.mod
index 661a6493..564b4250 100644
--- a/go.mod
+++ b/go.mod
@@ -22,7 +22,7 @@ require (
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/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/util v0.0.0-20221111132719-399730281e66
github.com/mattn/go-sqlite3 v1.14.17
diff --git a/go.sum b/go.sum
index 3fe25e9f..f7d21d96 100644
--- a/go.sum
+++ b/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/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/gomatrixserverlib v0.0.0-20230908150629-47bceffecd9e h1:WSqq/Pk+4Tna2F7zxEXMPrlZUAfBep3Y2gFbPhKgJHs=
-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 h1:+RC9Ddmt5v4y58qmdz5WuEEWCJ9gBWuYLyndnWkGfXU=
+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/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg=
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
diff --git a/internal/eventutil/events.go b/internal/eventutil/events.go
index aa99e586..b3523e12 100644
--- a/internal/eventutil/events.go
+++ b/internal/eventutil/events.go
@@ -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())
}
redactedEvent.Redact()
- validRoomID, err := spec.NewRoomID(redactionEvent.RoomID())
- if err != nil {
- return err
- }
- senderID, err := querier.QueryUserIDForSender(ctx, *validRoomID, redactionEvent.SenderID())
+ senderID, err := querier.QueryUserIDForSender(ctx, redactedEvent.RoomID(), redactionEvent.SenderID())
if err != nil {
return err
}
diff --git a/internal/pushrules/evaluate.go b/internal/pushrules/evaluate.go
index 28dea97c..6baef434 100644
--- a/internal/pushrules/evaluate.go
+++ b/internal/pushrules/evaluate.go
@@ -111,15 +111,11 @@ func ruleMatches(rule *Rule, kind Kind, event gomatrixserverlib.PDU, ec Evaluati
return patternMatches("content.body", *rule.Pattern, event)
case RoomKind:
- return rule.RuleID == event.RoomID(), nil
+ return rule.RuleID == event.RoomID().String(), nil
case SenderKind:
userID := ""
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return false, err
- }
- sender, err := userIDForSender(*validRoomID, event.SenderID())
+ sender, err := userIDForSender(event.RoomID(), event.SenderID())
if err == nil {
userID = sender.String()
}
diff --git a/internal/pushrules/evaluate_test.go b/internal/pushrules/evaluate_test.go
index a4ccc3d0..fbc88b2e 100644
--- a/internal/pushrules/evaluate_test.go
+++ b/internal/pushrules/evaluate_test.go
@@ -13,7 +13,7 @@ func UserIDForSender(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID,
}
func TestRuleSetEvaluatorMatchEvent(t *testing.T) {
- ev := mustEventFromJSON(t, `{}`)
+ ev := mustEventFromJSON(t, `{"room_id":"!room:a"}`)
defaultEnabled := &Rule{
RuleID: ".default.enabled",
Default: true,
@@ -44,8 +44,8 @@ func TestRuleSetEvaluatorMatchEvent(t *testing.T) {
{"overrideRoom", RuleSet{Override: []*Rule{userEnabled}, Room: []*Rule{userEnabled2}}, userEnabled, ev},
{"overrideSender", RuleSet{Override: []*Rule{userEnabled}, Sender: []*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"}`)},
- {"receipts don't notify", *defaultRuleset, nil, mustEventFromJSON(t, `{"type":"m.receipt"}`)},
+ {"reactions don't notify", *defaultRuleset, &mRuleReactionDefinition, mustEventFromJSON(t, `{"room_id":"!room:a","type":"m.reaction"}`)},
+ {"receipts don't notify", *defaultRuleset, nil, mustEventFromJSON(t, `{"room_id":"!room:a","type":"m.receipt"}`)},
}
for _, tst := range tsts {
t.Run(tst.Name, func(t *testing.T) {
@@ -70,28 +70,27 @@ func TestRuleMatches(t *testing.T) {
EventJSON string
Want bool
}{
- {"emptyOverride", OverrideKind, emptyRule, `{}`, true},
- {"emptyContent", ContentKind, emptyRule, `{}`, false},
- {"emptyRoom", RoomKind, emptyRule, `{}`, true},
+ {"emptyOverride", OverrideKind, emptyRule, `{"room_id":"!room:example.com"}`, true},
+ {"emptyContent", ContentKind, emptyRule, `{"room_id":"!room:example.com"}`, false},
{"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},
- {"overrideConditionNoMatch", OverrideKind, Rule{Enabled: true, Conditions: []*Condition{{}}}, `{}`, false},
+ {"overrideConditionMatch", OverrideKind, Rule{Enabled: true}, `{"room_id":"!room:example.com"}`, true},
+ {"overrideConditionNoMatch", OverrideKind, Rule{Enabled: true, Conditions: []*Condition{{}}}, `{"room_id":"!room:example.com"}`, false},
- {"underrideConditionMatch", UnderrideKind, Rule{Enabled: true}, `{}`, true},
- {"underrideConditionNoMatch", UnderrideKind, Rule{Enabled: true, Conditions: []*Condition{{}}}, `{}`, false},
+ {"underrideConditionMatch", UnderrideKind, Rule{Enabled: true}, `{"room_id":"!room:example.com"}`, true},
+ {"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},
- {"contentNoMatch", ContentKind, Rule{Enabled: true, Pattern: pointer("d")}, `{"content":{"body":"abc"}}`, false},
+ {"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")}, `{"room_id":"!room:example.com","content":{"body":"abc"}}`, false},
{"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},
- {"senderMatch", SenderKind, Rule{Enabled: true, RuleID: "@user: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},
+ {"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"}, `{"room_id":"!room:example.com","sender":"@otheruser:example.com","room_id":"!room:example.com"}`, false},
}
for _, tst := range tsts {
t.Run(tst.Name, func(t *testing.T) {
@@ -114,32 +113,32 @@ func TestConditionMatches(t *testing.T) {
WantMatch bool
WantErr bool
}{
- {Name: "empty", Cond: Condition{}, EventJSON: `{}`, WantMatch: false, WantErr: false},
- {Name: "empty", Cond: Condition{Kind: "unknownstring"}, 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: `{"room_id":"!room:example.com"}`, WantMatch: false, WantErr: false},
// Neither of these should match because `content` is not a full string match,
// 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: "eventBodyMatch", Cond: Condition{Kind: EventMatchCondition, Key: "content.body", Is: "3", Pattern: pointer("")}, EventJSON: `{"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: "EventMatch missing pattern", Cond: Condition{Kind: EventMatchCondition, Key: "content.body"}, EventJSON: `{"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: "displayNameMatch", Cond: Condition{Kind: ContainsDisplayNameCondition}, EventJSON: `{"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: "roomMemberCountLessMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<3"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
- {Name: "roomMemberCountLessEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<=1"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
- {Name: "roomMemberCountLessEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "<=2"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
- {Name: "roomMemberCountEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "==1"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
- {Name: "roomMemberCountEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: "==2"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
- {Name: "roomMemberCountGreaterEqualNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">=3"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
- {Name: "roomMemberCountGreaterEqualMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">=2"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
- {Name: "roomMemberCountGreaterNoMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">2"}, EventJSON: `{}`, WantMatch: false, WantErr: false},
- {Name: "roomMemberCountGreaterMatch", Cond: Condition{Kind: RoomMemberCountCondition, Is: ">1"}, EventJSON: `{}`, WantMatch: true, WantErr: false},
-
- {Name: "senderNotificationPermissionMatch", Cond: Condition{Kind: SenderNotificationPermissionCondition, Key: "powerlevel"}, EventJSON: `{"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: "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: `{"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: `{"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: `{"room_id":"!room:example.com","content":{"body": "hello world!"}}`, WantMatch: false, WantErr: true},
+
+ {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: `{"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: `{"room_id":"!room:example.com"}`, WantMatch: false, 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: `{"room_id":"!room:example.com"}`, WantMatch: false, 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: `{"room_id":"!room:example.com"}`, WantMatch: false, 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: `{"room_id":"!room:example.com"}`, WantMatch: false, 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: `{"room_id":"!room:example.com"}`, WantMatch: false, 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: `{"room_id":"!room:example.com","sender":"@poweruser:example.com"}`, WantMatch: true, 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 {
t.Run(tst.Name, func(t *testing.T) {
@@ -170,15 +169,15 @@ func TestPatternMatches(t *testing.T) {
EventJSON string
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},
- {"substring", "content.creator", "reat", `{"content":{"creator":"acreator"}}`, true},
- {"singlePattern", "content.creator", "acr?ator", `{"content":{"creator":"acreator"}}`, true},
- {"multiPattern", "content.creator", "a*ea*r", `{"content":{"creator":"acreator"}}`, true},
- {"patternNoSubstring", "content.creator", "r*t", `{"content":{"creator":"acreator"}}`, false},
+ {"literal", "content.creator", "acreator", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
+ {"substring", "content.creator", "reat", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
+ {"singlePattern", "content.creator", "acr?ator", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
+ {"multiPattern", "content.creator", "a*ea*r", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, true},
+ {"patternNoSubstring", "content.creator", "r*t", `{"room_id":"!room:a","content":{"creator":"acreator"}}`, false},
}
for _, tst := range tsts {
t.Run(tst.Name, func(t *testing.T) {
diff --git a/internal/transactionrequest.go b/internal/transactionrequest.go
index 5bf7d819..0663c2dc 100644
--- a/internal/transactionrequest.go
+++ b/internal/transactionrequest.go
@@ -161,7 +161,7 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *ut
if event.Type() == spec.MRoomCreate && event.StateKeyEquals("") {
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{
Error: "Forbidden by server ACLs",
}
diff --git a/roomserver/acls/acls.go b/roomserver/acls/acls.go
index b04828b6..601ce906 100644
--- a/roomserver/acls/acls.go
+++ b/roomserver/acls/acls.go
@@ -119,7 +119,7 @@ func (s *ServerACLs) OnServerACLUpdate(state gomatrixserverlib.PDU) {
}).Debugf("Updating server ACLs for %q", state.RoomID())
s.aclsMutex.Lock()
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 {
diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go
index 2505a993..0ad5d201 100644
--- a/roomserver/api/wrapper.go
+++ b/roomserver/api/wrapper.go
@@ -75,7 +75,7 @@ func SendEventWithState(
}
logrus.WithContext(ctx).WithFields(logrus.Fields{
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
"event_id": event.EventID(),
"outliers": len(ires),
"state_ids": len(stateEventIDs),
diff --git a/roomserver/auth/auth.go b/roomserver/auth/auth.go
index df95851e..d5172dab 100644
--- a/roomserver/auth/auth.go
+++ b/roomserver/auth/auth.go
@@ -85,11 +85,7 @@ func IsAnyUserOnServerWithMembership(ctx context.Context, querier api.QuerySende
continue
}
- validRoomID, err := spec.NewRoomID(ev.RoomID())
- if err != nil {
- continue
- }
- userID, err := querier.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*stateKey))
+ userID, err := querier.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*stateKey))
if err != nil {
continue
}
diff --git a/roomserver/internal/alias.go b/roomserver/internal/alias.go
index a7f0aab9..5ceda7e0 100644
--- a/roomserver/internal/alias.go
+++ b/roomserver/internal/alias.go
@@ -189,7 +189,7 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(ctx context.Context, senderID sp
proto := &gomatrixserverlib.ProtoEvent{
SenderID: string(canonicalSenderID),
- RoomID: ev.RoomID(),
+ RoomID: ev.RoomID().String(),
Type: ev.Type(),
StateKey: ev.StateKey(),
Content: res,
diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go
index 530147da..1e08f6a3 100644
--- a/roomserver/internal/api.go
+++ b/roomserver/internal/api.go
@@ -239,7 +239,7 @@ func (r *RoomserverInternalAPI) HandleInvite(
if err != nil {
return err
}
- return r.OutputProducer.ProduceRoomEvents(inviteEvent.RoomID(), outputEvents)
+ return r.OutputProducer.ProduceRoomEvents(inviteEvent.RoomID().String(), outputEvents)
}
func (r *RoomserverInternalAPI) PerformCreateRoom(
diff --git a/roomserver/internal/helpers/auth.go b/roomserver/internal/helpers/auth.go
index 89fae244..9da751b1 100644
--- a/roomserver/internal/helpers/auth.go
+++ b/roomserver/internal/helpers/auth.go
@@ -218,9 +218,9 @@ func loadAuthEvents(
roomID := ""
for _, ev := range result.events {
if roomID == "" {
- roomID = ev.RoomID()
+ roomID = ev.RoomID().String()
}
- if ev.RoomID() != roomID {
+ if ev.RoomID().String() != roomID {
result.valid = false
break
}
diff --git a/roomserver/internal/helpers/helpers.go b/roomserver/internal/helpers/helpers.go
index febabf41..b2e21bf5 100644
--- a/roomserver/internal/helpers/helpers.go
+++ b/roomserver/internal/helpers/helpers.go
@@ -54,7 +54,7 @@ func UpdateToInviteMembership(
Type: api.OutputTypeRetireInviteEvent,
RetireInviteEvent: &api.OutputRetireInviteEvent{
EventID: eventID,
- RoomID: add.RoomID(),
+ RoomID: add.RoomID().String(),
Membership: spec.Join,
RetiredByEventID: add.EventID(),
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
// only talk in event IDs, no room IDs at all (!!!)
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 {
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.
if !visited[pre] {
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 {
util.GetLogger(ctx).WithField("server", serverName).WithField("event_id", pre).WithError(err).Error(
"Error checking if allowed to see event",
diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go
index 99056359..40475153 100644
--- a/roomserver/internal/input/input.go
+++ b/roomserver/internal/input/input.go
@@ -358,7 +358,7 @@ func (r *Inputer) queueInputRoomEvents(
// For each event, marshal the input room event and then
// send it into the input queue.
for _, e := range request.InputRoomEvents {
- roomID := e.Event.RoomID()
+ roomID := e.Event.RoomID().String()
subj := r.Cfg.Matrix.JetStream.Prefixed(jetstream.InputRoomEventSubj(roomID))
msg := &nats.Msg{
Subject: subj,
diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go
index bf321662..77b50d0e 100644
--- a/roomserver/internal/input/input_events.go
+++ b/roomserver/internal/input/input_events.go
@@ -87,7 +87,7 @@ func (r *Inputer) 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())
defer trace.EndRegion()
@@ -96,7 +96,7 @@ func (r *Inputer) processRoomEvent(
defer func() {
timetaken := time.Since(started)
processRoomEventDuration.With(prometheus.Labels{
- "room_id": input.Event.RoomID(),
+ "room_id": input.Event.RoomID().String(),
}).Observe(float64(timetaken.Milliseconds()))
}()
@@ -105,7 +105,7 @@ func (r *Inputer) processRoomEvent(
event := headered.PDU
logger := util.GetLogger(ctx).WithFields(logrus.Fields{
"event_id": event.EventID(),
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
"kind": input.Kind,
"origin": input.Origin,
"type": event.Type(),
@@ -120,19 +120,15 @@ func (r *Inputer) processRoomEvent(
// 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
// event.
- roomInfo, rerr := r.DB.RoomInfo(ctx, event.RoomID())
+ roomInfo, rerr := r.DB.RoomInfo(ctx, event.RoomID().String())
if rerr != nil {
return fmt.Errorf("r.DB.RoomInfo: %w", rerr)
}
isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
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())
- if err != nil {
- return err
- }
- sender, err := r.Queryer.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
+ sender, err := r.Queryer.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err != nil {
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 missingAuth || missingPrev {
serverReq := &fedapi.QueryJoinedHostServerNamesInRoomRequest{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
ExcludeSelf: true,
ExcludeBlacklisted: true,
}
@@ -395,12 +391,12 @@ func (r *Inputer) processRoomEvent(
// Request the room info again — it's possible that the room has been
// 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 {
return fmt.Errorf("updater.RoomInfo: %w", err)
}
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) {
@@ -459,7 +455,7 @@ func (r *Inputer) processRoomEvent(
if userErr != nil {
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 {
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)
}
case api.KindOld:
- err = r.OutputProducer.ProduceRoomEvents(event.RoomID(), []api.OutputEvent{
+ err = r.OutputProducer.ProduceRoomEvents(event.RoomID().String(), []api.OutputEvent{
{
Type: api.OutputTypeOldRoomEvent,
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
// been tracking our output log.
if redactedEventID != "" {
- err = r.OutputProducer.ProduceRoomEvents(event.RoomID(), []api.OutputEvent{
+ err = r.OutputProducer.ProduceRoomEvents(event.RoomID().String(), []api.OutputEvent{
{
Type: api.OutputTypeRedactedEvent,
RedactedEvent: &api.OutputRedactedEvent{
@@ -536,7 +532,7 @@ func (r *Inputer) processRoomEvent(
// handleRemoteRoomUpgrade updates published rooms and room aliases
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
return r.DB.UpgradeRoom(ctx, oldRoomID, newRoomID, string(event.SenderID()))
}
@@ -596,7 +592,7 @@ func (r *Inputer) processStateBefore(
StateKey: "",
})
stateBeforeReq := &api.QueryStateAfterEventsRequest{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
PrevEventIDs: event.PrevEventIDs(),
StateToFetch: tuplesNeeded,
}
@@ -606,7 +602,7 @@ func (r *Inputer) processStateBefore(
}
switch {
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
case !stateBeforeRes.PrevEventsExist:
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
// contain all of the auth events — including ones that we already know —
// 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 {
logger.WithError(err).Warnf("Failed to get event auth from federation for %q: %s", event.EventID(), err)
continue
@@ -866,25 +862,20 @@ func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, r
inputEvents := make([]api.InputRoomEvent, 0, len(memberEvents))
latestReq := &api.QueryLatestEventsAndStateRequest{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
}
latestRes := &api.QueryLatestEventsAndStateResponse{}
if err = r.Queryer.QueryLatestEventsAndState(ctx, latestReq, latestRes); err != nil {
return err
}
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return err
- }
-
prevEvents := latestRes.LatestEvents
for _, memberEvent := range memberEvents {
if memberEvent.StateKey() == nil {
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 {
continue
}
@@ -912,7 +903,7 @@ func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, r
stateKey := *memberEvent.StateKey()
fledglingEvent := &gomatrixserverlib.ProtoEvent{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
Type: spec.MRoomMember,
StateKey: &stateKey,
SenderID: stateKey,
@@ -928,12 +919,7 @@ func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, r
return err
}
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return err
- }
-
- signingIdentity, err := r.SigningIdentity(ctx, *validRoomID, *memberUserID)
+ signingIdentity, err := r.SigningIdentity(ctx, event.RoomID(), *memberUserID)
if err != nil {
return err
}
diff --git a/roomserver/internal/input/input_latest_events.go b/roomserver/internal/input/input_latest_events.go
index 940783e0..ec03d6f1 100644
--- a/roomserver/internal/input/input_latest_events.go
+++ b/roomserver/internal/input/input_latest_events.go
@@ -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
// 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.
- 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)
}
@@ -290,7 +290,7 @@ func (u *latestEventsUpdater) latestState() error {
if removed := len(u.removed) - len(u.added); !u.rewritesState && removed > 0 {
logrus.WithFields(logrus.Fields{
"event_id": u.event.EventID(),
- "room_id": u.event.RoomID(),
+ "room_id": u.event.RoomID().String(),
"old_state_nid": u.oldStateNID,
"new_state_nid": u.newStateNID,
"old_latest": u.oldLatest.EventIDs(),
diff --git a/roomserver/internal/input/input_membership.go b/roomserver/internal/input/input_membership.go
index c46f8dba..4cfc2cda 100644
--- a/roomserver/internal/input/input_membership.go
+++ b/roomserver/internal/input/input_membership.go
@@ -139,11 +139,7 @@ func (r *Inputer) updateMembership(
func (r *Inputer) isLocalTarget(ctx context.Context, event *types.Event) bool {
isTargetLocalUser := false
if statekey := event.StateKey(); statekey != nil {
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return isTargetLocalUser
- }
- userID, err := r.Queryer.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*statekey))
+ userID, err := r.Queryer.QueryUserIDForSender(ctx, event.RoomID(), spec.SenderID(*statekey))
if err != nil || userID == nil {
return isTargetLocalUser
}
@@ -168,7 +164,7 @@ func updateToJoinMembership(
Type: api.OutputTypeRetireInviteEvent,
RetireInviteEvent: &api.OutputRetireInviteEvent{
EventID: eventID,
- RoomID: add.RoomID(),
+ RoomID: add.RoomID().String(),
Membership: spec.Join,
RetiredByEventID: add.EventID(),
TargetSenderID: spec.SenderID(*add.StateKey()),
@@ -195,7 +191,7 @@ func updateToLeaveMembership(
Type: api.OutputTypeRetireInviteEvent,
RetireInviteEvent: &api.OutputRetireInviteEvent{
EventID: eventID,
- RoomID: add.RoomID(),
+ RoomID: add.RoomID().String(),
Membership: newMembership,
RetiredByEventID: add.EventID(),
TargetSenderID: spec.SenderID(*add.StateKey()),
diff --git a/roomserver/internal/input/input_missing.go b/roomserver/internal/input/input_missing.go
index 5b4c0727..d9ab291e 100644
--- a/roomserver/internal/input/input_missing.go
+++ b/roomserver/internal/input/input_missing.go
@@ -84,7 +84,7 @@ func (t *missingStateReq) processEventWithMissingState(
// need to fallback to /state.
t.log = util.GetLogger(ctx).WithFields(map[string]interface{}{
"txn_event": e.EventID(),
- "room_id": e.RoomID(),
+ "room_id": e.RoomID().String(),
"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
// come from the roomserver, if we know all the required events, or it will
// 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) {
case gomatrixserverlib.EventValidationError:
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
var err error
- t.roomsMu.Lock(e.RoomID())
+ t.roomsMu.Lock(e.RoomID().String())
resolvedState, err = t.resolveStatesAndCheck(ctx, roomVersion, respStates, e)
- t.roomsMu.Unlock(e.RoomID())
+ t.roomsMu.Unlock(e.RoomID().String())
switch err2 := err.(type) {
case gomatrixserverlib.EventValidationError:
if !err2.Persistable {
@@ -510,7 +510,7 @@ retryAllowedState:
}); err != nil {
switch missing := err.(type) {
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) {
case gomatrixserverlib.EventValidationError:
if !e.Persistable {
@@ -546,7 +546,7 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e gomatrixserver
trace, ctx := internal.StartRegion(ctx, "getMissingEvents")
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)
if err != nil {
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
for _, server := range t.servers {
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,
// The latest event IDs that the sender already has. These are skipped when retrieving the previous events of latest_events.
EarliestEvents: latestEvents,
diff --git a/roomserver/internal/perform/perform_backfill.go b/roomserver/internal/perform/perform_backfill.go
index 33200e81..dafa5873 100644
--- a/roomserver/internal/perform/perform_backfill.go
+++ b/roomserver/internal/perform/perform_backfill.go
@@ -301,7 +301,7 @@ func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent
return ids, nil
}
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{}
return nil, nil
}
@@ -494,11 +494,7 @@ FindSuccessor:
// Store the server names in a temporary map to avoid duplicates.
serverSet := make(map[spec.ServerName]bool)
for _, event := range memberEvents {
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- continue
- }
- if sender, err := b.querier.QueryUserIDForSender(ctx, *validRoomID, event.SenderID()); err == nil {
+ if sender, err := b.querier.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID()); err == nil {
serverSet[sender.Domain()] = true
}
}
diff --git a/roomserver/internal/perform/perform_invite.go b/roomserver/internal/perform/perform_invite.go
index e07780d6..3abb69cb 100644
--- a/roomserver/internal/perform/perform_invite.go
+++ b/roomserver/internal/perform/perform_invite.go
@@ -100,16 +100,12 @@ func (r *Inviter) ProcessInviteMembership(
var outputUpdates []api.OutputEvent
var updater *shared.MembershipUpdater
- validRoomID, err := spec.NewRoomID(inviteEvent.RoomID())
- if err != nil {
- return nil, err
- }
- userID, err := r.RSAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*inviteEvent.StateKey()))
+ userID, err := r.RSAPI.QueryUserIDForSender(ctx, inviteEvent.RoomID(), spec.SenderID(*inviteEvent.StateKey()))
if err != nil {
return nil, api.ErrInvalidID{Err: fmt.Errorf("the user ID %s is invalid", *inviteEvent.StateKey())}
}
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)
}
outputUpdates, err = helpers.UpdateToInviteMembership(updater, &types.Event{
diff --git a/roomserver/internal/query/query_room_hierarchy.go b/roomserver/internal/query/query_room_hierarchy.go
index 7274be52..76eba12b 100644
--- a/roomserver/internal/query/query_room_hierarchy.go
+++ b/roomserver/internal/query/query_room_hierarchy.go
@@ -513,14 +513,14 @@ func restrictedJoinRuleAllowedRooms(ctx context.Context, joinRuleEv *types.Heade
}
var jrContent gomatrixserverlib.JoinRuleContent
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
}
for _, allow := range jrContent.Allow {
if allow.Type == spec.MRoomMembership {
allowedRoomID, err := spec.NewRoomID(allow.RoomID)
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 {
allows = append(allows, *allowedRoomID)
}
diff --git a/roomserver/internal/query/query_test.go b/roomserver/internal/query/query_test.go
index 619d9303..296960b2 100644
--- a/roomserver/internal/query/query_test.go
+++ b/roomserver/internal/query/query_test.go
@@ -49,6 +49,7 @@ func (db *getEventDB) addFakeEvent(eventID string, authIDs []string) error {
}
builder := map[string]interface{}{
"event_id": eventID,
+ "room_id": "!room:a",
"auth_events": authEvents,
}
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index b09c5afb..3331c602 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -696,8 +696,8 @@ func (d *Database) GetOrCreateRoomInfo(ctx context.Context, event gomatrixserver
return nil, fmt.Errorf("extractRoomVersionFromCreateEvent: %w", err)
}
- roomNID, nidOK := d.Cache.GetRoomServerRoomNID(event.RoomID())
- cachedRoomVersion, versionOK := d.Cache.GetRoomVersion(event.RoomID())
+ roomNID, nidOK := d.Cache.GetRoomServerRoomNID(event.RoomID().String())
+ 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 nidOK && versionOK {
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 {
- roomNID, err = d.assignRoomNID(ctx, txn, event.RoomID(), roomVersion)
+ roomNID, err = d.assignRoomNID(ctx, txn, event.RoomID().String(), roomVersion)
if err != nil {
return err
}
return nil
})
if roomVersion != "" {
- d.Cache.StoreRoomVersion(event.RoomID(), roomVersion)
+ d.Cache.StoreRoomVersion(event.RoomID().String(), roomVersion)
}
return &types.RoomInfo{
RoomVersion: roomVersion,
@@ -1026,24 +1026,19 @@ func (d *EventDatabase) MaybeRedactEvent(
case validated || redactedEvent == nil || redactionEvent == nil:
// we've seen this redaction before or there is nothing to redact
return nil
- case redactedEvent.RoomID() != redactionEvent.RoomID():
+ case redactedEvent.RoomID().String() != redactionEvent.RoomID().String():
// redactions across rooms aren't allowed
ignoreRedaction = true
return nil
}
- var validRoomID *spec.RoomID
- validRoomID, err = spec.NewRoomID(redactedEvent.RoomID())
- if err != nil {
- return err
- }
sender1Domain := ""
- sender1, err1 := querier.QueryUserIDForSender(ctx, *validRoomID, redactedEvent.SenderID())
+ sender1, err1 := querier.QueryUserIDForSender(ctx, redactedEvent.RoomID(), redactedEvent.SenderID())
if err1 == nil {
sender1Domain = string(sender1.Domain())
}
sender2Domain := ""
- sender2, err2 := querier.QueryUserIDForSender(ctx, *validRoomID, redactionEvent.SenderID())
+ sender2, err2 := querier.QueryUserIDForSender(ctx, redactedEvent.RoomID(), redactionEvent.SenderID())
if err2 == nil {
sender2Domain = string(sender2.Domain())
}
@@ -1522,7 +1517,7 @@ func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tu
}
result[i] = tables.StrippedEvent{
EventType: ev.Type(),
- RoomID: ev.RoomID(),
+ RoomID: ev.RoomID().String(),
StateKey: *ev.StateKey(),
ContentValue: tables.ExtractContentValue(&types.HeaderedEvent{PDU: ev}),
}
diff --git a/setup/mscs/msc2836/msc2836.go b/setup/mscs/msc2836/msc2836.go
index 7f8e2de0..15811710 100644
--- a/setup/mscs/msc2836/msc2836.go
+++ b/setup/mscs/msc2836/msc2836.go
@@ -271,7 +271,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
event = rc.fetchUnknownEvent(rc.req.EventID, rc.req.RoomID)
}
if rc.req.RoomID == "" && event != nil {
- rc.req.RoomID = event.RoomID()
+ rc.req.RoomID = event.RoomID().String()
}
if event == nil || !rc.authorisedToSeeEvent(event) {
return nil, &util.JSONResponse{
@@ -526,7 +526,7 @@ func (rc *reqCtx) authorisedToSeeEvent(event *types.HeaderedEvent) bool {
// make sure the server is in this room
var res fs.QueryJoinedHostServerNamesInRoomResponse
err := rc.fsAPI.QueryJoinedHostServerNamesInRoom(rc.ctx, &fs.QueryJoinedHostServerNamesInRoomRequest{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
}, &res)
if err != nil {
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
var queryMembershipRes roomserver.QueryMembershipForUserResponse
err := rc.rsAPI.QueryMembershipForUser(rc.ctx, &roomserver.QueryMembershipForUserRequest{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
UserID: rc.userID,
}, &queryMembershipRes)
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
rc.injectResponseToRoomserver(queryRes)
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}
}
}
@@ -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 nil
diff --git a/setup/mscs/msc2836/storage.go b/setup/mscs/msc2836/storage.go
index 73bd6ed4..ade2a161 100644
--- a/setup/mscs/msc2836/storage.go
+++ b/setup/mscs/msc2836/storage.go
@@ -239,7 +239,7 @@ func (p *DB) StoreRelation(ctx context.Context, ev *types.HeaderedEvent) error {
return err
}
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
})
}
diff --git a/syncapi/consumers/clientapi.go b/syncapi/consumers/clientapi.go
index 3ed455e9..76b44713 100644
--- a/syncapi/consumers/clientapi.go
+++ b/syncapi/consumers/clientapi.go
@@ -113,7 +113,7 @@ func (s *OutputClientDataConsumer) Start() error {
id = streamPos
e := fulltext.IndexElement{
EventID: ev.EventID(),
- RoomID: ev.RoomID(),
+ RoomID: ev.RoomID().String(),
StreamPosition: streamPos,
}
e.SetContentType(ev.Type())
diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go
index 9df5e0f9..666f900d 100644
--- a/syncapi/consumers/roomserver.go
+++ b/syncapi/consumers/roomserver.go
@@ -166,9 +166,9 @@ func (s *OutputRoomEventConsumer) onRedactEvent(
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{
- "room_id": msg.RedactedBecause.RoomID(),
+ "room_id": msg.RedactedBecause.RoomID().String(),
"event_id": msg.RedactedBecause.EventID(),
"redacted_event_id": msg.RedactedEventID,
}).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.
if len(missingEventIDs) > 0 {
eventsReq := &api.QueryEventsByIDRequest{
- RoomID: ev.RoomID(),
+ RoomID: ev.RoomID().String(),
EventIDs: missingEventIDs,
}
eventsRes := &api.QueryEventsByIDResponse{}
@@ -257,17 +257,12 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
}
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)
}
}
- validRoomID, err := spec.NewRoomID(ev.RoomID())
- if err != nil {
- return err
- }
-
- userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, ev.SenderID())
+ userID, err := s.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
if err != nil {
return err
}
@@ -307,7 +302,7 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
}
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
}
@@ -324,12 +319,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
// old events in the sync API, this should at least prevent us
// from confusing clients into thinking they've joined/left rooms.
- validRoomID, err := spec.NewRoomID(ev.RoomID())
- if err != nil {
- return err
- }
-
- userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, ev.SenderID())
+ userID, err := s.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
if err != nil {
return err
}
@@ -355,7 +345,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
if err = s.db.UpdateRelations(ctx, ev); err != nil {
log.WithFields(log.Fields{
- "room_id": ev.RoomID(),
+ "room_id": ev.RoomID().String(),
"event_id": ev.EventID(),
"type": ev.Type(),
}).WithError(err).Warn("Failed to update relations")
@@ -368,7 +358,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
}
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
}
@@ -388,11 +378,7 @@ func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *rst
return sp, fmt.Errorf("unexpected nil state_key")
}
- validRoomID, err := spec.NewRoomID(ev.RoomID())
- if err != nil {
- return sp, err
- }
- userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*ev.StateKey()))
+ userID, err := s.rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*ev.StateKey()))
if err != nil || userID == nil {
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
- peekSP, peekErr := s.db.DeletePeeks(ctx, ev.RoomID(), *ev.StateKey())
+ peekSP, peekErr := s.db.DeletePeeks(ctx, ev.RoomID().String(), *ev.StateKey())
if peekErr != nil {
return sp, fmt.Errorf("s.db.DeletePeeks: %w", peekErr)
}
@@ -419,11 +405,7 @@ func (s *OutputRoomEventConsumer) onNewInviteEvent(
return
}
- validRoomID, err := spec.NewRoomID(msg.Event.RoomID())
- if err != nil {
- return
- }
- userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*msg.Event.StateKey()))
+ userID, err := s.rsAPI.QueryUserIDForSender(ctx, msg.Event.RoomID(), spec.SenderID(*msg.Event.StateKey()))
if err != nil || userID == nil {
return
}
@@ -560,15 +542,10 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *rstypes.HeaderedEvent)
var succeeded bool
defer sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err)
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return event, err
- }
-
sKeyUser := ""
if stateKey != "" {
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 {
sKeyUser = sku.String()
event.StateKeyResolved = &sKeyUser
@@ -576,13 +553,13 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *rstypes.HeaderedEvent)
}
prevEvent, err := snapshot.GetStateEvent(
- s.ctx, event.RoomID(), event.Type(), sKeyUser,
+ s.ctx, event.RoomID().String(), event.Type(), sKeyUser,
)
if err != nil {
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 {
return event, err
}
@@ -610,7 +587,7 @@ func (s *OutputRoomEventConsumer) writeFTS(ev *rstypes.HeaderedEvent, pduPositio
}
e := fulltext.IndexElement{
EventID: ev.EventID(),
- RoomID: ev.RoomID(),
+ RoomID: ev.RoomID().String(),
StreamPosition: int64(pduPosition),
}
e.SetContentType(ev.Type())
diff --git a/syncapi/internal/history_visibility.go b/syncapi/internal/history_visibility.go
index 7aae9fd3..48475327 100644
--- a/syncapi/internal/history_visibility.go
+++ b/syncapi/internal/history_visibility.go
@@ -118,26 +118,23 @@ func ApplyHistoryVisibilityFilter(
start := time.Now()
// 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 {
return nil, err
}
// Get the mapping from eventID -> eventVisibility
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 {
return nil, err
}
- senderID, err := rsAPI.QuerySenderIDForUser(ctx, *firstEvRoomID, userID)
- if err != nil {
- return nil, err
- }
- visibilities := visibilityForEvents(ctx, rsAPI, events, senderID, *firstEvRoomID)
+ visibilities := visibilityForEvents(ctx, rsAPI, events, senderID, firstEvRoomID)
for _, ev := range events {
// 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")
}
diff --git a/syncapi/notifier/notifier.go b/syncapi/notifier/notifier.go
index a8733f6f..07b80b16 100644
--- a/syncapi/notifier/notifier.go
+++ b/syncapi/notifier/notifier.go
@@ -101,20 +101,13 @@ func (n *Notifier) OnNewEvent(
n._removeEmptyUserStreams()
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.
- 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.
- 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 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 {
log.WithError(err).WithField("event_id", ev.EventID()).Errorf(
"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
// along all members in the room
usersToNotify = append(usersToNotify, targetUserID.String())
- n._addJoinedUser(ev.RoomID(), targetUserID.String())
+ n._addJoinedUser(ev.RoomID().String(), targetUserID.String())
case spec.Leave:
fallthrough
case spec.Ban:
- n._removeJoinedUser(ev.RoomID(), targetUserID.String())
+ n._removeJoinedUser(ev.RoomID().String(), targetUserID.String())
}
}
}
diff --git a/syncapi/routing/getevent.go b/syncapi/routing/getevent.go
index bf0f9bf8..886b1167 100644
--- a/syncapi/routing/getevent.go
+++ b/syncapi/routing/getevent.go
@@ -129,14 +129,7 @@ func GetEvent(
sk := events[0].StateKey()
if sk != nil && *sk != "" {
- evRoomID, err := spec.NewRoomID(events[0].RoomID())
- 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()))
+ skUserID, err := rsAPI.QueryUserIDForSender(ctx, events[0].RoomID(), spec.SenderID(*events[0].StateKey()))
if err == nil && skUserID != nil {
skString := skUserID.String()
sk = &skString
diff --git a/syncapi/routing/memberships.go b/syncapi/routing/memberships.go
index 5e5d0125..e849adf6 100644
--- a/syncapi/routing/memberships.go
+++ b/syncapi/routing/memberships.go
@@ -152,15 +152,7 @@ func GetMemberships(
}
}
- validRoomID, err := spec.NewRoomID(ev.RoomID())
- 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())
+ userID, err := rsAPI.QueryUserIDForSender(req.Context(), ev.RoomID(), ev.SenderID())
if err != nil || userID == nil {
util.GetLogger(req.Context()).WithError(err).Error("rsAPI.QueryUserIDForSender failed")
return util.JSONResponse{
diff --git a/syncapi/routing/search.go b/syncapi/routing/search.go
index 7d5c061b..f574781a 100644
--- a/syncapi/routing/search.go
+++ b/syncapi/routing/search.go
@@ -205,12 +205,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
profileInfos := make(map[string]ProfileInfoResponse)
for _, ev := range append(eventsBefore, eventsAfter...) {
- validRoomID, roomErr := spec.NewRoomID(ev.RoomID())
- 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())
+ userID, queryErr := rsAPI.QueryUserIDForSender(req.Context(), ev.RoomID(), ev.SenderID())
if queryErr != nil {
logrus.WithError(queryErr).WithField("sender_id", ev.SenderID()).Warn("failed to query userprofile")
continue
@@ -218,7 +213,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
profile, ok := knownUsersProfiles[userID.String()]
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 {
logrus.WithError(stateErr).WithField("sender_id", event.SenderID()).Warn("failed to query userprofile")
continue
@@ -236,19 +231,14 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
}
sender := spec.UserID{}
- validRoomID, roomErr := spec.NewRoomID(event.RoomID())
- 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())
+ userID, err := rsAPI.QueryUserIDForSender(req.Context(), event.RoomID(), event.SenderID())
if err == nil && userID != nil {
sender = *userID
}
sk := event.StateKey()
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 {
skString := skUserID.String()
sk = &skString
@@ -269,12 +259,12 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
Rank: eventScore[event.EventID()].Score,
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())
- groups[event.RoomID()] = roomGroup
- if _, ok := stateForRooms[event.RoomID()]; searchReq.SearchCategories.RoomEvents.IncludeState && !ok {
+ groups[event.RoomID().String()] = roomGroup
+ if _, ok := stateForRooms[event.RoomID().String()]; searchReq.SearchCategories.RoomEvents.IncludeState && !ok {
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 {
logrus.WithError(err).Error("unable to get current state")
return util.JSONResponse{
@@ -282,7 +272,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
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)
})
}
@@ -328,19 +318,19 @@ func contextEvents(
roomFilter *synctypes.RoomEventFilter,
searchReq SearchRequest,
) ([]*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 {
logrus.WithError(err).Error("failed to query context event")
return nil, nil, err
}
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 {
logrus.WithError(err).Error("failed to query before context event")
return nil, nil, err
}
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 {
logrus.WithError(err).Error("failed to query after context event")
return nil, nil, err
diff --git a/syncapi/routing/search_test.go b/syncapi/routing/search_test.go
index 905a9a1a..a983bb7b 100644
--- a/syncapi/routing/search_test.go
+++ b/syncapi/routing/search_test.go
@@ -238,7 +238,7 @@ func TestSearch(t *testing.T) {
}
elements = append(elements, fulltext.IndexElement{
EventID: x.EventID(),
- RoomID: x.RoomID(),
+ RoomID: x.RoomID().String(),
Content: string(x.Content()),
ContentType: x.Type(),
StreamPosition: int64(sp),
diff --git a/syncapi/storage/postgres/current_room_state_table.go b/syncapi/storage/postgres/current_room_state_table.go
index 112fa9d4..b0148bef 100644
--- a/syncapi/storage/postgres/current_room_state_table.go
+++ b/syncapi/storage/postgres/current_room_state_table.go
@@ -340,7 +340,7 @@ func (s *currentRoomStateStatements) UpsertRoomState(
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
_, err = stmt.ExecContext(
ctx,
- event.RoomID(),
+ event.RoomID().String(),
event.EventID(),
event.Type(),
event.UserID.String(),
diff --git a/syncapi/storage/postgres/invites_table.go b/syncapi/storage/postgres/invites_table.go
index 7b8d2d73..1f46cd09 100644
--- a/syncapi/storage/postgres/invites_table.go
+++ b/syncapi/storage/postgres/invites_table.go
@@ -99,7 +99,7 @@ func (s *inviteEventsStatements) InsertInviteEvent(
err = sqlutil.TxStmt(txn, s.insertInviteEventStmt).QueryRowContext(
ctx,
- inviteEvent.RoomID(),
+ inviteEvent.RoomID().String(),
inviteEvent.EventID(),
inviteEvent.UserID.String(),
headeredJSON,
diff --git a/syncapi/storage/postgres/memberships_table.go b/syncapi/storage/postgres/memberships_table.go
index 09b47432..fcbe14b1 100644
--- a/syncapi/storage/postgres/memberships_table.go
+++ b/syncapi/storage/postgres/memberships_table.go
@@ -108,7 +108,7 @@ func (s *membershipsStatements) UpsertMembership(
}
_, err = sqlutil.TxStmt(txn, s.upsertMembershipStmt).ExecContext(
ctx,
- event.RoomID(),
+ event.RoomID().String(),
event.StateKeyResolved,
membership,
event.EventID(),
diff --git a/syncapi/storage/postgres/output_room_events_table.go b/syncapi/storage/postgres/output_room_events_table.go
index b58cf59f..b2d19111 100644
--- a/syncapi/storage/postgres/output_room_events_table.go
+++ b/syncapi/storage/postgres/output_room_events_table.go
@@ -334,7 +334,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
if err := json.Unmarshal(eventBytes, &ev); err != nil {
return nil, nil, err
}
- needSet := stateNeeded[ev.RoomID()]
+ needSet := stateNeeded[ev.RoomID().String()]
if needSet == nil { // make set if required
needSet = make(map[string]bool)
}
@@ -344,7 +344,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
for _, id := range addIDs {
needSet[id] = true
}
- stateNeeded[ev.RoomID()] = needSet
+ stateNeeded[ev.RoomID().String()] = needSet
ev.Visibility = historyVisibility
eventIDToEvent[eventID] = types.StreamEvent{
@@ -403,7 +403,7 @@ func (s *outputRoomEventsStatements) InsertEvent(
stmt := sqlutil.TxStmt(txn, s.insertEventStmt)
err = stmt.QueryRowContext(
ctx,
- event.RoomID(),
+ event.RoomID().String(),
event.EventID(),
headeredJSON,
event.Type(),
diff --git a/syncapi/storage/postgres/output_room_events_topology_table.go b/syncapi/storage/postgres/output_room_events_topology_table.go
index b281f330..2158d99e 100644
--- a/syncapi/storage/postgres/output_room_events_topology_table.go
+++ b/syncapi/storage/postgres/output_room_events_topology_table.go
@@ -107,7 +107,7 @@ func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
) (topoPos types.StreamPosition, err error) {
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)
return
}
diff --git a/syncapi/storage/shared/storage_consumer.go b/syncapi/storage/shared/storage_consumer.go
index 69e64cc7..0f4080d5 100644
--- a/syncapi/storage/shared/storage_consumer.go
+++ b/syncapi/storage/shared/storage_consumer.go
@@ -114,14 +114,7 @@ func (d *Database) StreamEventsToEvents(ctx context.Context, device *userapi.Dev
}).WithError(err).Warnf("Failed to add transaction ID to event")
continue
}
- roomID, err := spec.NewRoomID(in[i].RoomID())
- 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)
+ deviceSenderID, err := rsAPI.QuerySenderIDForUser(ctx, in[i].RoomID(), *userID)
if err != nil || deviceSenderID == nil {
logrus.WithFields(logrus.Fields{
"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.
// 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 {
- 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
}
@@ -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 !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
}
}
@@ -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
for _, ev := range evs {
- roomID := ev.RoomID()
+ roomID := ev.RoomID().String()
stateBetween[roomID] = append(stateBetween[roomID], ev)
}
}
@@ -522,11 +515,7 @@ func getMembershipFromEvent(ctx context.Context, ev gomatrixserverlib.PDU, userI
if err != nil {
return "", ""
}
- roomID, err := spec.NewRoomID(ev.RoomID())
- if err != nil {
- return "", ""
- }
- senderID, err := rsAPI.QuerySenderIDForUser(ctx, *roomID, *fullUser)
+ senderID, err := rsAPI.QuerySenderIDForUser(ctx, ev.RoomID(), *fullUser)
if err != nil || senderID == nil {
return "", ""
}
@@ -626,7 +615,7 @@ func (d *Database) UpdateRelations(ctx context.Context, event *rstypes.HeaderedE
default:
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
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,
)
})
diff --git a/syncapi/storage/sqlite3/current_room_state_table.go b/syncapi/storage/sqlite3/current_room_state_table.go
index 3bd19b36..78b2e397 100644
--- a/syncapi/storage/sqlite3/current_room_state_table.go
+++ b/syncapi/storage/sqlite3/current_room_state_table.go
@@ -339,7 +339,7 @@ func (s *currentRoomStateStatements) UpsertRoomState(
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
_, err = stmt.ExecContext(
ctx,
- event.RoomID(),
+ event.RoomID().String(),
event.EventID(),
event.Type(),
event.UserID.String(),
diff --git a/syncapi/storage/sqlite3/invites_table.go b/syncapi/storage/sqlite3/invites_table.go
index 7e0d895f..ebb469d2 100644
--- a/syncapi/storage/sqlite3/invites_table.go
+++ b/syncapi/storage/sqlite3/invites_table.go
@@ -106,7 +106,7 @@ func (s *inviteEventsStatements) InsertInviteEvent(
_, err = stmt.ExecContext(
ctx,
streamPos,
- inviteEvent.RoomID(),
+ inviteEvent.RoomID().String(),
inviteEvent.EventID(),
inviteEvent.UserID.String(),
headeredJSON,
diff --git a/syncapi/storage/sqlite3/memberships_table.go b/syncapi/storage/sqlite3/memberships_table.go
index a9e880d2..05f756fd 100644
--- a/syncapi/storage/sqlite3/memberships_table.go
+++ b/syncapi/storage/sqlite3/memberships_table.go
@@ -111,7 +111,7 @@ func (s *membershipsStatements) UpsertMembership(
}
_, err = sqlutil.TxStmt(txn, s.upsertMembershipStmt).ExecContext(
ctx,
- event.RoomID(),
+ event.RoomID().String(),
event.StateKeyResolved,
membership,
event.EventID(),
diff --git a/syncapi/storage/sqlite3/output_room_events_table.go b/syncapi/storage/sqlite3/output_room_events_table.go
index 06c65419..93caee80 100644
--- a/syncapi/storage/sqlite3/output_room_events_table.go
+++ b/syncapi/storage/sqlite3/output_room_events_table.go
@@ -254,7 +254,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
if err := json.Unmarshal(eventBytes, &ev); err != nil {
return nil, nil, err
}
- needSet := stateNeeded[ev.RoomID()]
+ needSet := stateNeeded[ev.RoomID().String()]
if needSet == nil { // make set if required
needSet = make(map[string]bool)
}
@@ -264,7 +264,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
for _, id := range addIDs {
needSet[id] = true
}
- stateNeeded[ev.RoomID()] = needSet
+ stateNeeded[ev.RoomID().String()] = needSet
ev.Visibility = historyVisibility
eventIDToEvent[eventID] = types.StreamEvent{
@@ -344,7 +344,7 @@ func (s *outputRoomEventsStatements) InsertEvent(
_, err = insertStmt.ExecContext(
ctx,
streamPos,
- event.RoomID(),
+ event.RoomID().String(),
event.EventID(),
headeredJSON,
event.Type(),
diff --git a/syncapi/storage/sqlite3/output_room_events_topology_table.go b/syncapi/storage/sqlite3/output_room_events_topology_table.go
index 614e1df9..36967d1e 100644
--- a/syncapi/storage/sqlite3/output_room_events_topology_table.go
+++ b/syncapi/storage/sqlite3/output_room_events_topology_table.go
@@ -106,7 +106,7 @@ func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
) (types.StreamPosition, error) {
_, 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
}
diff --git a/syncapi/streams/stream_invite.go b/syncapi/streams/stream_invite.go
index 1ce3346f..1424dc2e 100644
--- a/syncapi/streams/stream_invite.go
+++ b/syncapi/streams/stream_invite.go
@@ -70,18 +70,14 @@ func (p *InviteStreamProvider) IncrementalSync(
for roomID, inviteEvent := range invites {
user := spec.UserID{}
- validRoomID, err := spec.NewRoomID(inviteEvent.RoomID())
- if err != nil {
- continue
- }
- sender, err := p.rsAPI.QueryUserIDForSender(ctx, *validRoomID, inviteEvent.SenderID())
+ sender, err := p.rsAPI.QueryUserIDForSender(ctx, inviteEvent.RoomID(), inviteEvent.SenderID())
if err == nil && sender != nil {
user = *sender
}
sk := inviteEvent.StateKey()
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 {
skString := skUserID.String()
sk = &skString
diff --git a/syncapi/streams/stream_pdu.go b/syncapi/streams/stream_pdu.go
index 3b27acd8..eb1f0ef2 100644
--- a/syncapi/streams/stream_pdu.go
+++ b/syncapi/streams/stream_pdu.go
@@ -476,9 +476,8 @@ func (p *PDUStreamProvider) updatePowerLevelEvent(ctx context.Context, ev *rstyp
newPls := make(map[string]int64)
var userID *spec.UserID
for user, level := range pls.Users {
- validRoomID, _ := spec.NewRoomID(ev.RoomID())
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 {
return nil, err
}
@@ -515,9 +514,8 @@ func (p *PDUStreamProvider) updatePowerLevelEvent(ctx context.Context, ev *rstyp
newPls = make(map[string]int64)
for user, level := range pls.Users {
- validRoomID, _ := spec.NewRoomID(ev.RoomID())
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 {
return nil, err
}
diff --git a/syncapi/syncapi_test.go b/syncapi/syncapi_test.go
index f2971995..ac526851 100644
--- a/syncapi/syncapi_test.go
+++ b/syncapi/syncapi_test.go
@@ -1401,7 +1401,7 @@ func toNATSMsgs(t *testing.T, cfg *config.Dendrite, input ...*rstypes.HeaderedEv
if ev.StateKey() != nil {
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,
NewRoomEvent: &rsapi.OutputNewRoomEvent{
Event: ev,
diff --git a/syncapi/synctypes/clientevent.go b/syncapi/synctypes/clientevent.go
index 7e5b1c1b..e0616e11 100644
--- a/syncapi/synctypes/clientevent.go
+++ b/syncapi/synctypes/clientevent.go
@@ -84,18 +84,14 @@ func ToClientEvents(serverEvs []gomatrixserverlib.PDU, format ClientEventFormat,
}
sender := spec.UserID{}
- validRoomID, err := spec.NewRoomID(se.RoomID())
- if err != nil {
- continue
- }
- userID, err := userIDForSender(*validRoomID, se.SenderID())
+ userID, err := userIDForSender(se.RoomID(), se.SenderID())
if err == nil && userID != nil {
sender = *userID
}
sk := se.StateKey()
if sk != nil && *sk != "" {
- skUserID, err := userIDForSender(*validRoomID, spec.SenderID(*sk))
+ skUserID, err := userIDForSender(se.RoomID(), spec.SenderID(*sk))
if err == nil && skUserID != nil {
skString := skUserID.String()
sk = &skString
@@ -105,7 +101,7 @@ func ToClientEvents(serverEvs []gomatrixserverlib.PDU, format ClientEventFormat,
unsigned := se.Unsigned()
var prev PrevEventRef
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 {
prev.PrevSenderID = prevUserID.String()
} else {
@@ -142,10 +138,10 @@ func ToClientEvent(se gomatrixserverlib.PDU, format ClientEventFormat, sender st
switch format {
case FormatAll:
- ce.RoomID = se.RoomID()
+ ce.RoomID = se.RoomID().String()
case FormatSync:
case FormatSyncFederation:
- ce.RoomID = se.RoomID()
+ ce.RoomID = se.RoomID().String()
ce.AuthEvents = se.AuthEventIDs()
ce.PrevEvents = se.PrevEventIDs()
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.
func ToClientEventDefault(userIDQuery spec.UserIDForSender, event gomatrixserverlib.PDU) ClientEvent {
sender := spec.UserID{}
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return ClientEvent{}
- }
- userID, err := userIDQuery(*validRoomID, event.SenderID())
+ userID, err := userIDQuery(event.RoomID(), event.SenderID())
if err == nil && userID != nil {
sender = *userID
}
sk := event.StateKey()
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 {
skString := skUserID.String()
sk = &skString
diff --git a/userapi/consumers/roomserver.go b/userapi/consumers/roomserver.go
index 8863d258..dca09193 100644
--- a/userapi/consumers/roomserver.go
+++ b/userapi/consumers/roomserver.go
@@ -108,7 +108,7 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msgs []*nats.Ms
}
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{
@@ -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 {
- members, roomSize, err := s.localRoomMembers(ctx, event.RoomID())
+ members, roomSize, err := s.localRoomMembers(ctx, event.RoomID().String())
if err != nil {
return fmt.Errorf("s.localRoomMembers: %w", err)
}
@@ -302,18 +302,14 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rst
switch {
case event.Type() == spec.MRoomMember:
sender := spec.UserID{}
- validRoomID, roomErr := spec.NewRoomID(event.RoomID())
- if roomErr != nil {
- return roomErr
- }
- userID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
+ userID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if queryErr == nil && userID != nil {
sender = *userID
}
sk := event.StateKey()
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 {
skString := skUserID.String()
sk = &skString
@@ -334,7 +330,7 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rst
}
case event.Type() == "m.room.tombstone" && event.StateKeyEquals(""):
// Handle room upgrades
- oldRoomID := event.RoomID()
+ oldRoomID := event.RoomID().String()
newRoomID := gjson.GetBytes(event.Content(), "replacement_room").Str
if err = s.handleRoomUpgrade(ctx, oldRoomID, newRoomID, members, roomSize); err != nil {
// 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{
"event_id": event.EventID(),
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
"num_members": len(members),
"room_size": roomSize,
}).Tracef("Notifying members")
@@ -464,7 +460,7 @@ func (s *OutputRoomEventConsumer) roomName(ctx context.Context, event *rstypes.H
}
req := &rsapi.QueryCurrentStateRequest{
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
StateTuples: []gomatrixserverlib.StateKeyTuple{roomNameTuple, canonicalAliasTuple},
}
var res rsapi.QueryCurrentStateResponse
@@ -532,7 +528,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
if a != pushrules.NotifyAction && a != pushrules.CoalesceAction {
log.WithFields(log.Fields{
"event_id": event.EventID(),
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
"localpart": mem.Localpart,
}).Tracef("Push rule evaluation rejected the event")
return nil
@@ -544,18 +540,14 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
}
sender := spec.UserID{}
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return err
- }
- userID, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
+ userID, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err == nil && userID != nil {
sender = *userID
}
sk := event.StateKey()
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 {
skString := skUserID.String()
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
// to "work", but they only use a single device.
ProfileTag: profileTag,
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
TS: spec.AsTimestamp(time.Now()),
}
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)
}
- 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)
}
@@ -591,7 +583,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
log.WithFields(log.Fields{
"event_id": event.EventID(),
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
"localpart": mem.Localpart,
"num_urls": len(devicesByURLAndFormat),
"num_unread": userNumUnreadNotifs,
@@ -648,11 +640,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
// user. Returns actions (including dont_notify).
func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *rstypes.HeaderedEvent, mem *localMembership, roomSize int) ([]*pushrules.Action, error) {
user := ""
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return nil, err
- }
- sender, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
+ sender, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err == nil {
user = sender.String()
}
@@ -686,7 +674,7 @@ func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *
ctx: ctx,
rsAPI: s.rsAPI,
mem: mem,
- roomID: event.RoomID(),
+ roomID: event.RoomID().String(),
roomSize: roomSize,
}
eval := pushrules.NewRuleSetEvaluator(ec, &ruleSets.Global)
@@ -704,7 +692,7 @@ func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *
log.WithFields(log.Fields{
"event_id": event.EventID(),
- "room_id": event.RoomID(),
+ "room_id": event.RoomID().String(),
"localpart": mem.Localpart,
"rule_id": rule.RuleID,
}).Trace("Matched a push rule")
@@ -793,16 +781,12 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *rstypes
},
Devices: devices,
EventID: event.EventID(),
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
},
}
default:
- validRoomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- return nil, err
- }
- sender, err := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, event.SenderID())
+ sender, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err != nil {
logger.WithError(err).Errorf("Failed to get userID for sender %s", event.SenderID())
return nil, err
@@ -816,7 +800,7 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *rstypes
Devices: devices,
EventID: event.EventID(),
ID: event.EventID(),
- RoomID: event.RoomID(),
+ RoomID: event.RoomID().String(),
RoomName: roomName,
Sender: sender.String(),
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)
return nil, err
}
- roomID, err := spec.NewRoomID(event.RoomID())
- if err != nil {
- logger.WithError(err).Errorf("event roomID is invalid %s", event.RoomID())
- return nil, err
- }
-
- localSender, err := s.rsAPI.QuerySenderIDForUser(ctx, *roomID, *userID)
+ localSender, err := s.rsAPI.QuerySenderIDForUser(ctx, event.RoomID(), *userID)
if err != 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, err
} else if localSender == nil {
- logger.WithError(err).Errorf("Failed to get local user senderID for room %s: %s", userID.String(), event.RoomID())
- return nil, fmt.Errorf("no sender ID for user %s in %s", userID.String(), roomID.String())
+ 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(), event.RoomID().String())
}
if event.StateKey() != nil && *event.StateKey() == string(*localSender) {
req.Notification.UserIsTarget = true