mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-18 04:13:10 -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"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
// Import the postgres database driver.
|
// Import the postgres database driver.
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
|
@ -26,6 +27,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
"github.com/matrix-org/dendrite/roomserver/state"
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/version"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"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 {
|
if event.Type() == gomatrixserverlib.MRoomCreate {
|
||||||
var createContent gomatrixserverlib.CreateContent
|
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 {
|
if createContent.RoomVersion != nil {
|
||||||
roomVersion = *createContent.RoomVersion
|
roomVersion = *createContent.RoomVersion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,13 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
"github.com/matrix-org/dendrite/roomserver/state"
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/version"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "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 {
|
if event.Type() == gomatrixserverlib.MRoomCreate {
|
||||||
var createContent gomatrixserverlib.CreateContent
|
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 {
|
if createContent.RoomVersion != nil {
|
||||||
roomVersion = *createContent.RoomVersion
|
roomVersion = *createContent.RoomVersion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue