package clientapi import ( "net/http" "github.com/dariuszjaniak/warp/server/internal/httputil" "github.com/dariuszjaniak/warp/server/internal/userapi" ) // DefaultRoomVersion is what this server creates rooms at. // // PLAN.md's decision is to implement the latest stable room version first // and backfill older ones only as federation needs them, so the registry // here has exactly one entry until the event core lands in Phase 2. const DefaultRoomVersion = "11" // roomVersionsCapability is the m.room_versions capability. type roomVersionsCapability struct { Default string `json:"default"` Available map[string]string `json:"available"` } // booleanCapability is the shape of the several capabilities that are only // an on/off switch. type booleanCapability struct { Enabled bool `json:"enabled"` } type capabilitiesResponse struct { Capabilities capabilities `json:"capabilities"` } type capabilities struct { RoomVersions roomVersionsCapability `json:"m.room_versions"` ChangePassword booleanCapability `json:"m.change_password"` SetDisplayName booleanCapability `json:"m.set_displayname"` SetAvatarURL booleanCapability `json:"m.set_avatar_url"` ThreePIDChanges booleanCapability `json:"m.3pid_changes"` } // handleCapabilities implements GET /_matrix/client/v3/capabilities. // // The endpoint needs a token: what a server will let you do depends on who // you are, and the spec makes it authenticated for that reason. // // Every flag here is the truth about this build, not an aspiration. // Password changes and third-party identifiers arrive with the rest of // account management in Phase 9, so they report false and clients hide the // buttons rather than offering something that 404s. func (c *ClientAPI) handleCapabilities(w http.ResponseWriter, _ *http.Request, _ userapi.Authenticated) error { httputil.WriteJSON(w, http.StatusOK, capabilitiesResponse{ Capabilities: capabilities{ RoomVersions: roomVersionsCapability{ Default: DefaultRoomVersion, Available: map[string]string{DefaultRoomVersion: "stable"}, }, ChangePassword: booleanCapability{Enabled: false}, SetDisplayName: booleanCapability{Enabled: true}, SetAvatarURL: booleanCapability{Enabled: true}, ThreePIDChanges: booleanCapability{Enabled: false}, }, }) return nil }