diff --git a/roomserver/storage/postgres/storage.go b/roomserver/storage/postgres/storage.go index 0a56136da..2e589d0d4 100644 --- a/roomserver/storage/postgres/storage.go +++ b/roomserver/storage/postgres/storage.go @@ -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 } diff --git a/roomserver/storage/sqlite3/storage.go b/roomserver/storage/sqlite3/storage.go index 7fbacfa39..af5f41a48 100644 --- a/roomserver/storage/sqlite3/storage.go +++ b/roomserver/storage/sqlite3/storage.go @@ -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 }