Update room version metadata

This commit is contained in:
Neil Alexander 2020-02-05 13:23:15 +00:00
parent 649b22768e
commit fe74f1ba0e

View file

@ -18,9 +18,9 @@ const (
) )
const ( const (
EventFormatV1 EventFormatID = iota + 1 EventFormatV1 EventFormatID = iota + 1 // original event ID formatting
EventFormatV2 EventFormatV2 // event ID is event hash
EventFormatV3 EventFormatV3 // event ID is URL-safe base64 event hash
) )
type RoomVersionDescription struct { type RoomVersionDescription struct {
@ -28,46 +28,64 @@ type RoomVersionDescription struct {
Stable bool Stable bool
StateResolution state.StateResolutionVersion StateResolution state.StateResolutionVersion
EventFormat EventFormatID EventFormat EventFormatID
EnforceSigningKeyValidity bool
} }
func GetRoomVersionDescription(version RoomVersionID) (desc RoomVersionDescription, err error) { var roomVersions = map[string]RoomVersionDescription{
switch version { RoomVersionV1: RoomVersionDescription{
case RoomVersionV1:
desc = RoomVersionDescription{
Supported: true, Supported: true,
Stable: true, Stable: true,
StateResolution: state.StateResolutionAlgorithmV1, StateResolution: state.StateResolutionAlgorithmV1,
EventFormat: EventFormatV1, EventFormat: EventFormatV1,
} EnforceSigningKeyValidity: false,
case RoomVersionV2: },
desc = RoomVersionDescription{ RoomVersionV2: RoomVersionDescription{
Supported: false, Supported: false,
Stable: true, Stable: true,
StateResolution: state.StateResolutionAlgorithmV2, StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV1, EventFormat: EventFormatV1,
} EnforceSigningKeyValidity: false,
case RoomVersionV3: },
desc = RoomVersionDescription{ RoomVersionV3: RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV1,
}
case RoomVersionV4:
desc = RoomVersionDescription{
Supported: false, Supported: false,
Stable: true, Stable: true,
StateResolution: state.StateResolutionAlgorithmV2, StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV2, EventFormat: EventFormatV2,
} EnforceSigningKeyValidity: false,
case RoomVersionV5: },
desc = RoomVersionDescription{ RoomVersionV4: RoomVersionDescription{
Supported: false, Supported: false,
Stable: true, Stable: true,
StateResolution: state.StateResolutionAlgorithmV2, StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV3, EventFormat: EventFormatV3,
EnforceSigningKeyValidity: false,
},
RoomVersionV5: RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV3,
EnforceSigningKeyValidity: true,
},
} }
default:
func GetRoomVersions() map[string]RoomVersionDescription {
return roomVersions
}
func GetSupportedRoomVersions() map[string]RoomVersionDescription {
versions := make(map[string]RoomVersionDescription)
for id, version := range GetRoomVersionDescriptions() {
if version.Supported {
versions[id] = version
}
}
return versions
}
func GetSupportedRoomVersion(version RoomVersionID) (desc RoomVersionDescription, err error) {
if version, ok := roomVersions[version]; ok {
desc = version
} }
if !desc.Supported { if !desc.Supported {
err = errors.New("unsupported room version") err = errors.New("unsupported room version")