mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-18 04:13:10 -06:00
Try to take room version from createRoomReq
This commit is contained in:
parent
c5163313e4
commit
1ac571973c
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -49,6 +48,7 @@ type createRoomRequest struct {
|
||||||
InitialState []fledglingEvent `json:"initial_state"`
|
InitialState []fledglingEvent `json:"initial_state"`
|
||||||
RoomAliasName string `json:"room_alias_name"`
|
RoomAliasName string `json:"room_alias_name"`
|
||||||
GuestCanJoin bool `json:"guest_can_join"`
|
GuestCanJoin bool `json:"guest_can_join"`
|
||||||
|
RoomVersion string `json:"room_version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -181,10 +181,16 @@ func createRoom(
|
||||||
r.CreationContent = make(map[string]interface{}, 2)
|
r.CreationContent = make(map[string]interface{}, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.CreationContent["creator"] = userID
|
roomVersion := roomserverVersion.GetDefaultRoomVersion()
|
||||||
|
if r.RoomVersion != "" {
|
||||||
|
id, meta, verr := roomserverVersion.GetSupportedRoomVersionFromString(r.RoomVersion)
|
||||||
|
if verr == nil && meta.Supported {
|
||||||
|
roomVersion = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defaultVersion := roomserverVersion.GetDefaultRoomVersion()
|
r.CreationContent["room_version"] = roomVersion.String()
|
||||||
r.CreationContent["room_version"] = strconv.Itoa(int(defaultVersion))
|
r.CreationContent["creator"] = userID
|
||||||
|
|
||||||
// TODO: visibility/presets/raw initial state
|
// TODO: visibility/presets/raw initial state
|
||||||
// TODO: Create room alias association
|
// TODO: Create room alias association
|
||||||
|
|
@ -193,6 +199,7 @@ func createRoom(
|
||||||
logger.WithFields(log.Fields{
|
logger.WithFields(log.Fields{
|
||||||
"userID": userID,
|
"userID": userID,
|
||||||
"roomID": roomID,
|
"roomID": roomID,
|
||||||
|
"roomVersion": r.CreationContent["room_version"],
|
||||||
}).Info("Creating new room")
|
}).Info("Creating new room")
|
||||||
|
|
||||||
profile, err := appserviceAPI.RetrieveUserProfile(req.Context(), userID, asAPI, accountDB)
|
profile, err := appserviceAPI.RetrieveUserProfile(req.Context(), userID, asAPI, accountDB)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
"github.com/matrix-org/dendrite/roomserver/state"
|
||||||
)
|
)
|
||||||
|
|
@ -101,8 +102,13 @@ func GetSupportedRoomVersions() map[RoomVersionID]RoomVersionDescription {
|
||||||
return versions
|
return versions
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSupportedRoomVersion(version RoomVersionID) (desc RoomVersionDescription, err error) {
|
func GetSupportedRoomVersion(id RoomVersionID) (
|
||||||
if version, ok := roomVersions[version]; ok {
|
ver RoomVersionID,
|
||||||
|
desc RoomVersionDescription,
|
||||||
|
err error,
|
||||||
|
) {
|
||||||
|
if version, ok := roomVersions[id]; ok {
|
||||||
|
ver = id
|
||||||
desc = version
|
desc = version
|
||||||
}
|
}
|
||||||
if !desc.Supported {
|
if !desc.Supported {
|
||||||
|
|
@ -110,3 +116,21 @@ func GetSupportedRoomVersion(version RoomVersionID) (desc RoomVersionDescription
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v RoomVersionID) String() string {
|
||||||
|
return strconv.Itoa(int(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSupportedRoomVersionFromString(version string) (
|
||||||
|
ver RoomVersionID,
|
||||||
|
desc RoomVersionDescription,
|
||||||
|
err error,
|
||||||
|
) {
|
||||||
|
var v RoomVersionID
|
||||||
|
if version, err := strconv.Atoi(version); err == nil {
|
||||||
|
v = RoomVersionID(version)
|
||||||
|
} else {
|
||||||
|
v = GetDefaultRoomVersion()
|
||||||
|
}
|
||||||
|
return GetSupportedRoomVersion(v)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue