mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -06:00
Get room version from initial persistence of m.room.create
This commit is contained in:
parent
15f9672c7d
commit
2f45bc417b
|
|
@ -19,6 +19,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
// Import the postgres database driver.
|
||||
_ "github.com/lib/pq"
|
||||
|
|
@ -26,6 +27,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
"github.com/matrix-org/dendrite/roomserver/version"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
|
@ -71,10 +73,13 @@ func (d *Database) StoreEvent(
|
|||
}
|
||||
}
|
||||
|
||||
roomVersion := ""
|
||||
roomVersion := strconv.Itoa(int(version.GetDefaultRoomVersion()))
|
||||
// The below works because the first event to be persisted to the database
|
||||
// is always the m.room.create event. We can therefore set the room version
|
||||
// correctly at the same time as assigning the room NID.
|
||||
if event.Type() == gomatrixserverlib.MRoomCreate {
|
||||
var createContent gomatrixserverlib.CreateContent
|
||||
if err := json.Unmarshal(event.Content(), createContent); err == nil {
|
||||
if err := json.Unmarshal(event.Content(), &createContent); err == nil {
|
||||
if createContent.RoomVersion != nil {
|
||||
roomVersion = *createContent.RoomVersion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,13 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
"github.com/matrix-org/dendrite/roomserver/version"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
|
@ -92,10 +94,13 @@ func (d *Database) StoreEvent(
|
|||
}
|
||||
}
|
||||
|
||||
roomVersion := ""
|
||||
roomVersion := strconv.Itoa(int(version.GetDefaultRoomVersion()))
|
||||
// The below works because the first event to be persisted to the database
|
||||
// is always the m.room.create event. We can therefore set the room version
|
||||
// correctly at the same time as assigning the room NID.
|
||||
if event.Type() == gomatrixserverlib.MRoomCreate {
|
||||
var createContent gomatrixserverlib.CreateContent
|
||||
if err := json.Unmarshal(event.Content(), createContent); err == nil {
|
||||
if err := json.Unmarshal(event.Content(), &createContent); err == nil {
|
||||
if createContent.RoomVersion != nil {
|
||||
roomVersion = *createContent.RoomVersion
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue