diff --git a/config/config.go b/config/config.go index b06d50e..f2bf82f 100644 --- a/config/config.go +++ b/config/config.go @@ -34,6 +34,7 @@ type Config struct { Asmux bool `yaml:"asmux"` StatusEndpoint string `yaml:"status_endpoint"` MessageSendCheckpointEndpoint string `yaml:"message_send_checkpoint_endpoint"` + AsyncMedia bool `yaml:"async_media"` } `yaml:"homeserver"` AppService struct { diff --git a/config/upgrade.go b/config/upgrade.go index e98275a..123ea30 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -33,6 +33,7 @@ func (helper *UpgradeHelper) doUpgrade() { helper.Copy(Bool, "homeserver", "asmux") helper.Copy(Str|Null, "homeserver", "status_endpoint") helper.Copy(Str|Null, "homeserver", "message_send_checkpoint_endpoint") + helper.Copy(Bool, "homeserver", "async_media") helper.Copy(Str, "appservice", "address") helper.Copy(Str, "appservice", "hostname") diff --git a/example-config.yaml b/example-config.yaml index f391773..93100a6 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -13,6 +13,8 @@ homeserver: status_endpoint: null # Endpoint for reporting per-message status. message_send_checkpoint_endpoint: null + # Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246? + async_media: false # Application service host/registration related details. # Changing these values requires regeneration of the registration. diff --git a/go.mod b/go.mod index a699be2..64bc03a 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b maunium.net/go/mauflag v1.0.0 maunium.net/go/maulogger/v2 v2.3.2 - maunium.net/go/mautrix v0.10.13-0.20220317230932-15d85fe4d3cc + maunium.net/go/mautrix v0.10.13-0.20220321175701-3b9911029134 ) require ( diff --git a/go.sum b/go.sum index 2f8890b..b819e64 100644 --- a/go.sum +++ b/go.sum @@ -197,5 +197,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M= maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA= maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0= maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A= -maunium.net/go/mautrix v0.10.13-0.20220317230932-15d85fe4d3cc h1:7NNOnyCL03RWifzCko6QhVzn+gqS8DKRRtqCVBIKj7g= -maunium.net/go/mautrix v0.10.13-0.20220317230932-15d85fe4d3cc/go.mod h1:WqW8mruBue+1YrL/f04Ni/4R5yfLcgO8BQhUJzl7sps= +maunium.net/go/mautrix v0.10.13-0.20220321175701-3b9911029134 h1:EYo8hg0p7XL8nXV18dcsSc0f/0NKFQF/+D/Cll1q0rU= +maunium.net/go/mautrix v0.10.13-0.20220321175701-3b9911029134/go.mod h1:WqW8mruBue+1YrL/f04Ni/4R5yfLcgO8BQhUJzl7sps= diff --git a/portal.go b/portal.go index 3adb15f..2765ecf 100644 --- a/portal.go +++ b/portal.go @@ -2108,16 +2108,30 @@ func (portal *Portal) convertMediaMessageContent(intent *appservice.IntentAPI, m func (portal *Portal) uploadMedia(intent *appservice.IntentAPI, data []byte, content *event.MessageEventContent) error { data, uploadMimeType, file := portal.encryptFile(data, content.Info.MimeType) - uploaded, err := intent.UploadBytes(data, uploadMimeType) - if err != nil { - return err + req := mautrix.ReqUploadMedia{ + ContentBytes: data, + ContentType: uploadMimeType, + } + var mxc id.ContentURI + if portal.bridge.Config.Homeserver.AsyncMedia { + uploaded, err := intent.UnstableUploadAsync(req) + if err != nil { + return err + } + mxc = uploaded.ContentURI + } else { + uploaded, err := intent.UploadMedia(req) + if err != nil { + return err + } + mxc = uploaded.ContentURI } if file != nil { - file.URL = uploaded.ContentURI.CUString() + file.URL = mxc.CUString() content.File = file } else { - content.URL = uploaded.ContentURI.CUString() + content.URL = mxc.CUString() } content.Info.Size = len(data)