mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Delegate responsibility for marking room versions as supported/stable to gomatrixserverlib (#1082)
This commit is contained in:
parent
e37720be44
commit
e598e80d76
3 changed files with 13 additions and 55 deletions
|
@ -20,42 +20,6 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
// RoomVersionDescription contains information about a room version,
|
||||
// namely whether it is marked as supported or stable in this server
|
||||
// version.
|
||||
// A version is supported if the server has some support for rooms
|
||||
// that are this version. A version is marked as stable or unstable
|
||||
// in order to hint whether the version should be used to clients
|
||||
// calling the /capabilities endpoint.
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-capabilities
|
||||
type RoomVersionDescription struct {
|
||||
Supported bool
|
||||
Stable bool
|
||||
}
|
||||
|
||||
var roomVersions = map[gomatrixserverlib.RoomVersion]RoomVersionDescription{
|
||||
gomatrixserverlib.RoomVersionV1: RoomVersionDescription{
|
||||
Supported: true,
|
||||
Stable: true,
|
||||
},
|
||||
gomatrixserverlib.RoomVersionV2: RoomVersionDescription{
|
||||
Supported: true,
|
||||
Stable: true,
|
||||
},
|
||||
gomatrixserverlib.RoomVersionV3: RoomVersionDescription{
|
||||
Supported: true,
|
||||
Stable: true,
|
||||
},
|
||||
gomatrixserverlib.RoomVersionV4: RoomVersionDescription{
|
||||
Supported: true,
|
||||
Stable: true,
|
||||
},
|
||||
gomatrixserverlib.RoomVersionV5: RoomVersionDescription{
|
||||
Supported: true,
|
||||
Stable: true,
|
||||
},
|
||||
}
|
||||
|
||||
// DefaultRoomVersion contains the room version that will, by
|
||||
// default, be used to create new rooms on this server.
|
||||
func DefaultRoomVersion() gomatrixserverlib.RoomVersion {
|
||||
|
@ -64,43 +28,37 @@ func DefaultRoomVersion() gomatrixserverlib.RoomVersion {
|
|||
|
||||
// RoomVersions returns a map of all known room versions to this
|
||||
// server.
|
||||
func RoomVersions() map[gomatrixserverlib.RoomVersion]RoomVersionDescription {
|
||||
return roomVersions
|
||||
func RoomVersions() map[gomatrixserverlib.RoomVersion]gomatrixserverlib.RoomVersionDescription {
|
||||
return gomatrixserverlib.RoomVersions()
|
||||
}
|
||||
|
||||
// SupportedRoomVersions returns a map of descriptions for room
|
||||
// versions that are supported by this homeserver.
|
||||
func SupportedRoomVersions() map[gomatrixserverlib.RoomVersion]RoomVersionDescription {
|
||||
versions := make(map[gomatrixserverlib.RoomVersion]RoomVersionDescription)
|
||||
for id, version := range RoomVersions() {
|
||||
if version.Supported {
|
||||
versions[id] = version
|
||||
}
|
||||
}
|
||||
return versions
|
||||
func SupportedRoomVersions() map[gomatrixserverlib.RoomVersion]gomatrixserverlib.RoomVersionDescription {
|
||||
return gomatrixserverlib.SupportedRoomVersions()
|
||||
}
|
||||
|
||||
// RoomVersion returns information about a specific room version.
|
||||
// An UnknownVersionError is returned if the version is not known
|
||||
// to the server.
|
||||
func RoomVersion(version gomatrixserverlib.RoomVersion) (RoomVersionDescription, error) {
|
||||
if version, ok := roomVersions[version]; ok {
|
||||
func RoomVersion(version gomatrixserverlib.RoomVersion) (gomatrixserverlib.RoomVersionDescription, error) {
|
||||
if version, ok := gomatrixserverlib.RoomVersions()[version]; ok {
|
||||
return version, nil
|
||||
}
|
||||
return RoomVersionDescription{}, UnknownVersionError{version}
|
||||
return gomatrixserverlib.RoomVersionDescription{}, UnknownVersionError{version}
|
||||
}
|
||||
|
||||
// SupportedRoomVersion returns information about a specific room
|
||||
// version. An UnknownVersionError is returned if the version is not
|
||||
// known to the server, or an UnsupportedVersionError is returned if
|
||||
// the version is known but specifically marked as unsupported.
|
||||
func SupportedRoomVersion(version gomatrixserverlib.RoomVersion) (RoomVersionDescription, error) {
|
||||
func SupportedRoomVersion(version gomatrixserverlib.RoomVersion) (gomatrixserverlib.RoomVersionDescription, error) {
|
||||
result, err := RoomVersion(version)
|
||||
if err != nil {
|
||||
return RoomVersionDescription{}, err
|
||||
return gomatrixserverlib.RoomVersionDescription{}, err
|
||||
}
|
||||
if !result.Supported {
|
||||
return RoomVersionDescription{}, UnsupportedVersionError{version}
|
||||
return gomatrixserverlib.RoomVersionDescription{}, UnsupportedVersionError{version}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue