Use PDU not *Event in HeaderedEvent (#3073)

Requires https://github.com/matrix-org/gomatrixserverlib/pull/376

This has numerous upsides:
 - Less type casting to `*Event` is required.
- Making Dendrite work with `PDU` interfaces means we can swap out Event
impls more easily.
 - Tests which represent weird event shapes are easier to write.

Part of a series of refactors on GMSL.
This commit is contained in:
kegsay 2023-05-02 15:03:16 +01:00 committed by GitHub
parent 696cbb70b8
commit f5b3144dc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 296 additions and 284 deletions

View file

@ -15,18 +15,28 @@
package types
import (
"unsafe"
"github.com/matrix-org/gomatrixserverlib"
)
// HeaderedEvent is an Event which serialises to the headered form, which includes
// _room_version and _event_id fields.
type HeaderedEvent struct {
*gomatrixserverlib.Event
gomatrixserverlib.PDU
Visibility gomatrixserverlib.HistoryVisibility
}
func (h *HeaderedEvent) CacheCost() int {
return int(unsafe.Sizeof(*h)) +
len(h.EventID()) +
(cap(h.JSON()) * 2) +
len(h.Version()) +
1 // redacted bool
}
func (h *HeaderedEvent) MarshalJSON() ([]byte, error) {
return h.Event.ToHeaderedJSON()
return h.PDU.ToHeaderedJSON()
}
func (j *HeaderedEvent) UnmarshalJSON(data []byte) error {
@ -34,7 +44,7 @@ func (j *HeaderedEvent) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
j.Event = ev
j.PDU = ev
return nil
}

View file

@ -228,7 +228,7 @@ func (s StateAtEventAndReferences) EventIDs() string {
// It is when performing bulk event lookup in the database.
type Event struct {
EventNID EventNID
*gomatrixserverlib.Event
gomatrixserverlib.PDU
}
const (