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,56 +18,74 @@ 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 {
Supported bool Supported bool
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: Supported: true,
desc = RoomVersionDescription{ Stable: true,
Supported: true, StateResolution: state.StateResolutionAlgorithmV1,
Stable: true, EventFormat: EventFormatV1,
StateResolution: state.StateResolutionAlgorithmV1, EnforceSigningKeyValidity: false,
EventFormat: EventFormatV1, },
RoomVersionV2: RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV1,
EnforceSigningKeyValidity: false,
},
RoomVersionV3: RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV2,
EnforceSigningKeyValidity: false,
},
RoomVersionV4: RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV3,
EnforceSigningKeyValidity: false,
},
RoomVersionV5: RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV3,
EnforceSigningKeyValidity: true,
},
}
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
} }
case RoomVersionV2: }
desc = RoomVersionDescription{ return versions
Supported: false, }
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2, func GetSupportedRoomVersion(version RoomVersionID) (desc RoomVersionDescription, err error) {
EventFormat: EventFormatV1, if version, ok := roomVersions[version]; ok {
} desc = version
case RoomVersionV3:
desc = RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV1,
}
case RoomVersionV4:
desc = RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV2,
}
case RoomVersionV5:
desc = RoomVersionDescription{
Supported: false,
Stable: true,
StateResolution: state.StateResolutionAlgorithmV2,
EventFormat: EventFormatV3,
}
default:
} }
if !desc.Supported { if !desc.Supported {
err = errors.New("unsupported room version") err = errors.New("unsupported room version")