aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appservice/consumers/roomserver.go2
-rw-r--r--clientapi/routing/state.go6
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--internal/pushrules/evaluate.go8
-rw-r--r--internal/pushrules/evaluate_test.go4
-rw-r--r--setup/mscs/msc2836/msc2836.go2
-rw-r--r--syncapi/routing/context.go11
-rw-r--r--syncapi/routing/getevent.go2
-rw-r--r--syncapi/routing/memberships.go3
-rw-r--r--syncapi/routing/messages.go4
-rw-r--r--syncapi/routing/search.go9
-rw-r--r--syncapi/streams/stream_pdu.go50
-rw-r--r--syncapi/synctypes/clientevent.go22
-rw-r--r--userapi/consumers/roomserver.go4
-rw-r--r--userapi/util/notify_test.go2
16 files changed, 49 insertions, 84 deletions
diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go
index 5e08a22c..d8112334 100644
--- a/appservice/consumers/roomserver.go
+++ b/appservice/consumers/roomserver.go
@@ -181,7 +181,7 @@ func (s *OutputRoomEventConsumer) sendEvents(
// Create the transaction body.
transaction, err := json.Marshal(
ApplicationServiceTransaction{
- Events: synctypes.HeaderedToClientEvents(events, synctypes.FormatAll),
+ Events: synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(events), synctypes.FormatAll),
},
)
if err != nil {
diff --git a/clientapi/routing/state.go b/clientapi/routing/state.go
index 3ea75a5d..705782e8 100644
--- a/clientapi/routing/state.go
+++ b/clientapi/routing/state.go
@@ -134,7 +134,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
for _, ev := range stateRes.StateEvents {
stateEvents = append(
stateEvents,
- synctypes.HeaderedToClientEvent(ev, synctypes.FormatAll),
+ synctypes.ToClientEvent(ev, synctypes.FormatAll),
)
}
} else {
@@ -153,7 +153,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
for _, ev := range stateAfterRes.StateEvents {
stateEvents = append(
stateEvents,
- synctypes.HeaderedToClientEvent(ev, synctypes.FormatAll),
+ synctypes.ToClientEvent(ev, synctypes.FormatAll),
)
}
}
@@ -312,7 +312,7 @@ func OnIncomingStateTypeRequest(
}
stateEvent := stateEventInStateResp{
- ClientEvent: synctypes.HeaderedToClientEvent(event, synctypes.FormatAll),
+ ClientEvent: synctypes.ToClientEvent(event, synctypes.FormatAll),
}
var res interface{}
diff --git a/go.mod b/go.mod
index b35e1556..6ee9f07c 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-20230428003202-267b4e79f138
+ github.com/matrix-org/gomatrixserverlib v0.0.0-20230428142634-a4fa967eac17
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
github.com/mattn/go-sqlite3 v1.14.16
diff --git a/go.sum b/go.sum
index 73560ea5..c4f22ec2 100644
--- a/go.sum
+++ b/go.sum
@@ -325,6 +325,8 @@ github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428003202-267b4e79f138 h1:zqMuO/4ye8QnSPLhruxTC4cQcXfrvpPwdtT+4kqEgF4=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428003202-267b4e79f138/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
+github.com/matrix-org/gomatrixserverlib v0.0.0-20230428142634-a4fa967eac17 h1:So8d7SZZdKB7+vWFXwmAQ3C+tUkkegMlcGk8n60w2og=
+github.com/matrix-org/gomatrixserverlib v0.0.0-20230428142634-a4fa967eac17/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
diff --git a/internal/pushrules/evaluate.go b/internal/pushrules/evaluate.go
index fc8e0f17..7c98efd3 100644
--- a/internal/pushrules/evaluate.go
+++ b/internal/pushrules/evaluate.go
@@ -53,7 +53,7 @@ func NewRuleSetEvaluator(ec EvaluationContext, ruleSet *RuleSet) *RuleSetEvaluat
// MatchEvent returns the first matching rule. Returns nil if there
// was no match rule.
-func (rse *RuleSetEvaluator) MatchEvent(event *gomatrixserverlib.Event) (*Rule, error) {
+func (rse *RuleSetEvaluator) MatchEvent(event gomatrixserverlib.PDU) (*Rule, error) {
// TODO: server-default rules have lower priority than user rules,
// but they are stored together with the user rules. It's a bit
// unclear what the specification (11.14.1.4 Predefined rules)
@@ -83,7 +83,7 @@ func (rse *RuleSetEvaluator) MatchEvent(event *gomatrixserverlib.Event) (*Rule,
return nil, nil
}
-func ruleMatches(rule *Rule, kind Kind, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) {
+func ruleMatches(rule *Rule, kind Kind, event gomatrixserverlib.PDU, ec EvaluationContext) (bool, error) {
if !rule.Enabled {
return false, nil
}
@@ -120,7 +120,7 @@ func ruleMatches(rule *Rule, kind Kind, event *gomatrixserverlib.Event, ec Evalu
}
}
-func conditionMatches(cond *Condition, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) {
+func conditionMatches(cond *Condition, event gomatrixserverlib.PDU, ec EvaluationContext) (bool, error) {
switch cond.Kind {
case EventMatchCondition:
if cond.Pattern == nil {
@@ -150,7 +150,7 @@ func conditionMatches(cond *Condition, event *gomatrixserverlib.Event, ec Evalua
}
}
-func patternMatches(key, pattern string, event *gomatrixserverlib.Event) (bool, error) {
+func patternMatches(key, pattern string, event gomatrixserverlib.PDU) (bool, error) {
// It doesn't make sense for an empty pattern to match anything.
if pattern == "" {
return false, nil
diff --git a/internal/pushrules/evaluate_test.go b/internal/pushrules/evaluate_test.go
index 4fa17b29..5045a864 100644
--- a/internal/pushrules/evaluate_test.go
+++ b/internal/pushrules/evaluate_test.go
@@ -29,7 +29,7 @@ func TestRuleSetEvaluatorMatchEvent(t *testing.T) {
Name string
RuleSet RuleSet
Want *Rule
- Event *gomatrixserverlib.Event
+ Event gomatrixserverlib.PDU
}{
{"empty", RuleSet{}, nil, ev},
{"defaultCanWin", RuleSet{Override: []*Rule{defaultEnabled}}, defaultEnabled, ev},
@@ -188,7 +188,7 @@ func TestPatternMatches(t *testing.T) {
}
}
-func mustEventFromJSON(t *testing.T, json string) *gomatrixserverlib.Event {
+func mustEventFromJSON(t *testing.T, json string) gomatrixserverlib.PDU {
ev, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV7).NewEventFromTrustedJSON([]byte(json), false)
if err != nil {
t.Fatal(err)
diff --git a/setup/mscs/msc2836/msc2836.go b/setup/mscs/msc2836/msc2836.go
index 38412fa2..877a4a60 100644
--- a/setup/mscs/msc2836/msc2836.go
+++ b/setup/mscs/msc2836/msc2836.go
@@ -95,7 +95,7 @@ type MSC2836EventRelationshipsResponse struct {
func toClientResponse(res *MSC2836EventRelationshipsResponse) *EventRelationshipResponse {
out := &EventRelationshipResponse{
- Events: synctypes.ToClientEvents(res.ParsedEvents, synctypes.FormatAll),
+ Events: synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(res.ParsedEvents), synctypes.FormatAll),
Limited: res.Limited,
NextBatch: res.NextBatch,
}
diff --git a/syncapi/routing/context.go b/syncapi/routing/context.go
index b4d61ecc..b85ab7f2 100644
--- a/syncapi/routing/context.go
+++ b/syncapi/routing/context.go
@@ -33,6 +33,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/synctypes"
"github.com/matrix-org/dendrite/syncapi/types"
userapi "github.com/matrix-org/dendrite/userapi/api"
+ "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@@ -169,14 +170,14 @@ func Context(
return jsonerror.InternalServerError()
}
- eventsBeforeClient := synctypes.HeaderedToClientEvents(eventsBeforeFiltered, synctypes.FormatAll)
- eventsAfterClient := synctypes.HeaderedToClientEvents(eventsAfterFiltered, synctypes.FormatAll)
+ eventsBeforeClient := synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(eventsBeforeFiltered), synctypes.FormatAll)
+ eventsAfterClient := synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(eventsAfterFiltered), synctypes.FormatAll)
newState := state
if filter.LazyLoadMembers {
allEvents := append(eventsBeforeFiltered, eventsAfterFiltered...)
allEvents = append(allEvents, &requestedEvent)
- evs := synctypes.HeaderedToClientEvents(allEvents, synctypes.FormatAll)
+ evs := synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(allEvents), synctypes.FormatAll)
newState, err = applyLazyLoadMembers(ctx, device, snapshot, roomID, evs, lazyLoadCache)
if err != nil {
logrus.WithError(err).Error("unable to load membership events")
@@ -184,12 +185,12 @@ func Context(
}
}
- ev := synctypes.HeaderedToClientEvent(&requestedEvent, synctypes.FormatAll)
+ ev := synctypes.ToClientEvent(&requestedEvent, synctypes.FormatAll)
response := ContextRespsonse{
Event: &ev,
EventsAfter: eventsAfterClient,
EventsBefore: eventsBeforeClient,
- State: synctypes.HeaderedToClientEvents(newState, synctypes.FormatAll),
+ State: synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(newState), synctypes.FormatAll),
}
if len(response.State) > filter.Limit {
diff --git a/syncapi/routing/getevent.go b/syncapi/routing/getevent.go
index 84986d3b..7775598e 100644
--- a/syncapi/routing/getevent.go
+++ b/syncapi/routing/getevent.go
@@ -97,6 +97,6 @@ func GetEvent(
return util.JSONResponse{
Code: http.StatusOK,
- JSON: synctypes.HeaderedToClientEvent(events[0], synctypes.FormatAll),
+ JSON: synctypes.ToClientEvent(events[0], synctypes.FormatAll),
}
}
diff --git a/syncapi/routing/memberships.go b/syncapi/routing/memberships.go
index 9ea660f5..a23f1525 100644
--- a/syncapi/routing/memberships.go
+++ b/syncapi/routing/memberships.go
@@ -25,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/synctypes"
"github.com/matrix-org/dendrite/syncapi/types"
userapi "github.com/matrix-org/dendrite/userapi/api"
+ "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
)
@@ -134,6 +135,6 @@ func GetMemberships(
}
return util.JSONResponse{
Code: http.StatusOK,
- JSON: getMembershipResponse{synctypes.HeaderedToClientEvents(result, synctypes.FormatAll)},
+ JSON: getMembershipResponse{synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(result), synctypes.FormatAll)},
}
}
diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go
index 0d087403..54b72c64 100644
--- a/syncapi/routing/messages.go
+++ b/syncapi/routing/messages.go
@@ -256,7 +256,7 @@ func OnIncomingMessagesRequest(
util.GetLogger(req.Context()).WithError(err).Error("failed to apply lazy loading")
return jsonerror.InternalServerError()
}
- res.State = append(res.State, synctypes.HeaderedToClientEvents(membershipEvents, synctypes.FormatAll)...)
+ res.State = append(res.State, synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(membershipEvents), synctypes.FormatAll)...)
}
// If we didn't return any events, set the end to an empty string, so it will be omitted
@@ -365,7 +365,7 @@ func (r *messagesReq) retrieveEvents() (
"events_before": len(events),
"events_after": len(filteredEvents),
}).Debug("applied history visibility (messages)")
- return synctypes.HeaderedToClientEvents(filteredEvents, synctypes.FormatAll), start, end, err
+ return synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(filteredEvents), synctypes.FormatAll), start, end, err
}
func (r *messagesReq) getStartEnd(events []*rstypes.HeaderedEvent) (start, end types.TopologyToken, err error) {
diff --git a/syncapi/routing/search.go b/syncapi/routing/search.go
index beaa227c..5f037392 100644
--- a/syncapi/routing/search.go
+++ b/syncapi/routing/search.go
@@ -22,6 +22,7 @@ import (
"time"
"github.com/blevesearch/bleve/v2/search"
+ "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@@ -206,12 +207,12 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
Context: SearchContextResponse{
Start: startToken.String(),
End: endToken.String(),
- EventsAfter: synctypes.HeaderedToClientEvents(eventsAfter, synctypes.FormatSync),
- EventsBefore: synctypes.HeaderedToClientEvents(eventsBefore, synctypes.FormatSync),
+ EventsAfter: synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(eventsAfter), synctypes.FormatSync),
+ EventsBefore: synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(eventsBefore), synctypes.FormatSync),
ProfileInfo: profileInfos,
},
Rank: eventScore[event.EventID()].Score,
- Result: synctypes.HeaderedToClientEvent(event, synctypes.FormatAll),
+ Result: synctypes.ToClientEvent(event, synctypes.FormatAll),
})
roomGroup := groups[event.RoomID()]
roomGroup.Results = append(roomGroup.Results, event.EventID())
@@ -223,7 +224,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
logrus.WithError(err).Error("unable to get current state")
return jsonerror.InternalServerError()
}
- stateForRooms[event.RoomID()] = synctypes.HeaderedToClientEvents(state, synctypes.FormatSync)
+ stateForRooms[event.RoomID()] = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(state), synctypes.FormatSync)
}
}
diff --git a/syncapi/streams/stream_pdu.go b/syncapi/streams/stream_pdu.go
index e024dfae..b5fd5be8 100644
--- a/syncapi/streams/stream_pdu.go
+++ b/syncapi/streams/stream_pdu.go
@@ -274,20 +274,13 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
recentStreamEvents := dbEvents[delta.RoomID].Events
limited := dbEvents[delta.RoomID].Limited
- hisVisMap := map[string]gomatrixserverlib.HistoryVisibility{}
- for _, re := range recentStreamEvents {
- hisVisMap[re.EventID()] = re.Visibility
- }
- recEvents := gomatrixserverlib.HeaderedReverseTopologicalOrdering(
- gomatrixserverlib.ToPDUs(toEvents(snapshot.StreamEventsToEvents(device, recentStreamEvents))),
+ recEvents := gomatrixserverlib.ReverseTopologicalOrdering(
+ gomatrixserverlib.ToPDUs(snapshot.StreamEventsToEvents(device, recentStreamEvents)),
gomatrixserverlib.TopologicalOrderByPrevEvents,
)
recentEvents := make([]*rstypes.HeaderedEvent, len(recEvents))
for i := range recEvents {
- recentEvents[i] = &rstypes.HeaderedEvent{
- Event: recEvents[i].(*gomatrixserverlib.Event),
- Visibility: hisVisMap[recEvents[i].EventID()],
- }
+ recentEvents[i] = recEvents[i].(*rstypes.HeaderedEvent)
}
// If we didn't return any events at all then don't bother doing anything else.
@@ -353,20 +346,13 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
// Now that we've filtered the timeline, work out which state events are still
// left. Anything that appears in the filtered timeline will be removed from the
// "state" section and kept in "timeline".
- hisVisMap = map[string]gomatrixserverlib.HistoryVisibility{}
- for _, re := range delta.StateEvents {
- hisVisMap[re.EventID()] = re.Visibility
- }
sEvents := gomatrixserverlib.HeaderedReverseTopologicalOrdering(
- gomatrixserverlib.ToPDUs(toEvents(removeDuplicates(delta.StateEvents, events))),
+ gomatrixserverlib.ToPDUs(removeDuplicates(delta.StateEvents, events)),
gomatrixserverlib.TopologicalOrderByAuthEvents,
)
delta.StateEvents = make([]*rstypes.HeaderedEvent, len(sEvents))
for i := range sEvents {
- delta.StateEvents[i] = &rstypes.HeaderedEvent{
- Event: sEvents[i].(*gomatrixserverlib.Event),
- Visibility: hisVisMap[sEvents[i].EventID()],
- }
+ delta.StateEvents[i] = sEvents[i].(*rstypes.HeaderedEvent)
}
if len(delta.StateEvents) > 0 {
@@ -390,20 +376,20 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
}
}
jr.Timeline.PrevBatch = &prevBatch
- jr.Timeline.Events = synctypes.HeaderedToClientEvents(events, synctypes.FormatSync)
+ jr.Timeline.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(events), synctypes.FormatSync)
// If we are limited by the filter AND the history visibility filter
// didn't "remove" events, return that the response is limited.
jr.Timeline.Limited = (limited && len(events) == len(recentEvents)) || delta.NewlyJoined
- jr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
+ jr.State.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(delta.StateEvents), synctypes.FormatSync)
req.Response.Rooms.Join[delta.RoomID] = jr
case spec.Peek:
jr := types.NewJoinResponse()
jr.Timeline.PrevBatch = &prevBatch
// TODO: Apply history visibility on peeked rooms
- jr.Timeline.Events = synctypes.HeaderedToClientEvents(recentEvents, synctypes.FormatSync)
+ jr.Timeline.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(recentEvents), synctypes.FormatSync)
jr.Timeline.Limited = limited
- jr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
+ jr.State.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(delta.StateEvents), synctypes.FormatSync)
req.Response.Rooms.Peek[delta.RoomID] = jr
case spec.Leave:
@@ -412,11 +398,11 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
case spec.Ban:
lr := types.NewLeaveResponse()
lr.Timeline.PrevBatch = &prevBatch
- lr.Timeline.Events = synctypes.HeaderedToClientEvents(events, synctypes.FormatSync)
+ lr.Timeline.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(events), synctypes.FormatSync)
// If we are limited by the filter AND the history visibility filter
// didn't "remove" events, return that the response is limited.
lr.Timeline.Limited = limited && len(events) == len(recentEvents)
- lr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
+ lr.State.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(delta.StateEvents), synctypes.FormatSync)
req.Response.Rooms.Leave[delta.RoomID] = lr
}
@@ -566,11 +552,11 @@ func (p *PDUStreamProvider) getJoinResponseForCompleteSync(
}
jr.Timeline.PrevBatch = prevBatch
- jr.Timeline.Events = synctypes.HeaderedToClientEvents(events, synctypes.FormatSync)
+ jr.Timeline.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(events), synctypes.FormatSync)
// If we are limited by the filter AND the history visibility filter
// didn't "remove" events, return that the response is limited.
jr.Timeline.Limited = limited && len(events) == len(recentEvents)
- jr.State.Events = synctypes.HeaderedToClientEvents(stateEvents, synctypes.FormatSync)
+ jr.State.Events = synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(stateEvents), synctypes.FormatSync)
return jr, nil
}
@@ -656,7 +642,7 @@ func (p *PDUStreamProvider) addIgnoredUsersToFilter(ctx context.Context, snapsho
return nil
}
-func removeDuplicates(stateEvents, recentEvents []*rstypes.HeaderedEvent) []*rstypes.HeaderedEvent {
+func removeDuplicates[T gomatrixserverlib.PDU](stateEvents, recentEvents []T) []T {
for _, recentEv := range recentEvents {
if recentEv.StateKey() == nil {
continue // not a state event
@@ -677,11 +663,3 @@ func removeDuplicates(stateEvents, recentEvents []*rstypes.HeaderedEvent) []*rst
}
return stateEvents
}
-
-func toEvents(events []*rstypes.HeaderedEvent) []*gomatrixserverlib.Event {
- result := make([]*gomatrixserverlib.Event, len(events))
- for i := range events {
- result[i] = events[i].Event
- }
- return result
-}
diff --git a/syncapi/synctypes/clientevent.go b/syncapi/synctypes/clientevent.go
index 4b253f66..c722fe60 100644
--- a/syncapi/synctypes/clientevent.go
+++ b/syncapi/synctypes/clientevent.go
@@ -16,7 +16,6 @@
package synctypes
import (
- "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/spec"
)
@@ -45,7 +44,7 @@ type ClientEvent struct {
}
// ToClientEvents converts server events to client events.
-func ToClientEvents(serverEvs []*gomatrixserverlib.Event, format ClientEventFormat) []ClientEvent {
+func ToClientEvents(serverEvs []gomatrixserverlib.PDU, format ClientEventFormat) []ClientEvent {
evs := make([]ClientEvent, 0, len(serverEvs))
for _, se := range serverEvs {
if se == nil {
@@ -56,20 +55,8 @@ func ToClientEvents(serverEvs []*gomatrixserverlib.Event, format ClientEventForm
return evs
}
-// HeaderedToClientEvents converts headered server events to client events.
-func HeaderedToClientEvents(serverEvs []*types.HeaderedEvent, format ClientEventFormat) []ClientEvent {
- evs := make([]ClientEvent, 0, len(serverEvs))
- for _, se := range serverEvs {
- if se == nil {
- continue // TODO: shouldn't happen?
- }
- evs = append(evs, HeaderedToClientEvent(se, format))
- }
- return evs
-}
-
// ToClientEvent converts a single server event to a client event.
-func ToClientEvent(se *gomatrixserverlib.Event, format ClientEventFormat) ClientEvent {
+func ToClientEvent(se gomatrixserverlib.PDU, format ClientEventFormat) ClientEvent {
ce := ClientEvent{
Content: spec.RawJSON(se.Content()),
Sender: se.Sender(),
@@ -85,8 +72,3 @@ func ToClientEvent(se *gomatrixserverlib.Event, format ClientEventFormat) Client
}
return ce
}
-
-// HeaderedToClientEvent converts a single headered server event to a client event.
-func HeaderedToClientEvent(se *types.HeaderedEvent, format ClientEventFormat) ClientEvent {
- return ToClientEvent(se.Event, format)
-}
diff --git a/userapi/consumers/roomserver.go b/userapi/consumers/roomserver.go
index ede011af..6201aa81 100644
--- a/userapi/consumers/roomserver.go
+++ b/userapi/consumers/roomserver.go
@@ -301,7 +301,7 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rst
switch {
case event.Type() == spec.MRoomMember:
- cevent := synctypes.HeaderedToClientEvent(event, synctypes.FormatAll)
+ cevent := synctypes.ToClientEvent(event, synctypes.FormatAll)
var member *localMembership
member, err = newLocalMembership(&cevent)
if err != nil {
@@ -534,7 +534,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
// UNSPEC: the spec doesn't say this is a ClientEvent, but the
// fields seem to match. room_id should be missing, which
// matches the behaviour of FormatSync.
- Event: synctypes.HeaderedToClientEvent(event, synctypes.FormatSync),
+ Event: synctypes.ToClientEvent(event, synctypes.FormatSync),
// TODO: this is per-device, but it's not part of the primary
// key. So inserting one notification per profile tag doesn't
// make sense. What is this supposed to be? Sytests require it
diff --git a/userapi/util/notify_test.go b/userapi/util/notify_test.go
index d6cbad7d..e1c88d47 100644
--- a/userapi/util/notify_test.go
+++ b/userapi/util/notify_test.go
@@ -100,7 +100,7 @@ func TestNotifyUserCountsAsync(t *testing.T) {
// Insert a dummy event
if err := db.InsertNotification(ctx, aliceLocalpart, serverName, dummyEvent.EventID(), 0, nil, &api.Notification{
- Event: synctypes.HeaderedToClientEvent(dummyEvent, synctypes.FormatAll),
+ Event: synctypes.ToClientEvent(dummyEvent, synctypes.FormatAll),
}); err != nil {
t.Error(err)
}