Skip to content

Commit

Permalink
client: add support for feature flag for authenticated media
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 1, 2024
1 parent 7939151 commit e7bc21d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ func (cli *Client) State(ctx context.Context, roomID id.RoomID) (stateMap RoomSt
// GetMediaConfig fetches the configuration of the content repository, such as upload limitations.
func (cli *Client) GetMediaConfig(ctx context.Context) (resp *RespMediaConfig, err error) {
var u string
if cli.SpecVersions.ContainsGreaterOrEqual(SpecV111) {
if cli.SpecVersions.Supports(FeatureAuthenticatedMedia) {
u = cli.BuildClientURL("v1", "media", "config")
} else {
u = cli.BuildURL(MediaURLPath{"v3", "config"})
Expand Down Expand Up @@ -1562,7 +1562,7 @@ func (cli *Client) Download(ctx context.Context, mxcURL id.ContentURI) (*http.Re
if ctxLog.GetLevel() == zerolog.Disabled || ctxLog == zerolog.DefaultContextLogger {
ctx = cli.Log.WithContext(ctx)
}
if cli.SpecVersions.ContainsGreaterOrEqual(SpecV111) {
if cli.SpecVersions.Supports(FeatureAuthenticatedMedia) {
_, resp, err := cli.MakeFullRequestWithResp(ctx, FullRequest{
Method: http.MethodGet,
URL: cli.BuildClientURL("v1", "media", "download", mxcURL.Homeserver, mxcURL.FileID),
Expand Down Expand Up @@ -1785,7 +1785,7 @@ func (cli *Client) UploadMedia(ctx context.Context, data ReqUploadMedia) (*RespM
// See https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3preview_url
func (cli *Client) GetURLPreview(ctx context.Context, url string) (*RespPreviewURL, error) {
var urlPath PrefixableURLPath
if cli.SpecVersions.ContainsGreaterOrEqual(SpecV111) {
if cli.SpecVersions.Supports(FeatureAuthenticatedMedia) {
urlPath = ClientURLPath{"v1", "media", "preview_url"}
} else {
urlPath = MediaURLPath{"v3", "preview_url"}
Expand Down
5 changes: 3 additions & 2 deletions versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ type UnstableFeature struct {
}

var (
FeatureAsyncUploads = UnstableFeature{UnstableFlag: "fi.mau.msc2246.stable", SpecVersion: SpecV17}
FeatureAppservicePing = UnstableFeature{UnstableFlag: "fi.mau.msc2659.stable", SpecVersion: SpecV17}
FeatureAsyncUploads = UnstableFeature{UnstableFlag: "fi.mau.msc2246.stable", SpecVersion: SpecV17}
FeatureAppservicePing = UnstableFeature{UnstableFlag: "fi.mau.msc2659.stable", SpecVersion: SpecV17}
FeatureAuthenticatedMedia = UnstableFeature{UnstableFlag: "org.matrix.msc3916.stable", SpecVersion: SpecV111}

BeeperFeatureHungry = UnstableFeature{UnstableFlag: "com.beeper.hungry"}
BeeperFeatureBatchSending = UnstableFeature{UnstableFlag: "com.beeper.batch_sending"}
Expand Down

0 comments on commit e7bc21d

Please sign in to comment.