Merge branch 'sumner/bri-2580' into 'main'

async media: add ability to upload media asynchronously

See merge request beeper/discord!5
This commit is contained in:
Gary Kramlich
2022-04-27 18:23:12 +00:00
6 changed files with 36 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/bwmarrin/discordgo"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/appservice"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
@@ -76,13 +77,26 @@ func (p *Portal) downloadMatrixAttachment(eventID id.EventID, content *event.Mes
}
func (p *Portal) uploadMatrixAttachment(intent *appservice.IntentAPI, data []byte, content *event.MessageEventContent) error {
uploaded, err := intent.UploadBytes(data, content.Info.MimeType)
if err != nil {
return err
req := mautrix.ReqUploadMedia{
ContentBytes: data,
ContentType: content.Info.MimeType,
}
var mxc id.ContentURI
if p.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
}
content.URL = uploaded.ContentURI.CUString()
content.URL = mxc.CUString()
content.Info.Size = len(data)
if content.Info.Width == 0 && content.Info.Height == 0 && strings.HasPrefix(content.Info.MimeType, "image/") {

View File

@@ -720,7 +720,7 @@ func (u *User) updateDirectChats(chats map[id.UserID][]id.RoomID) {
var err error
if u.bridge.Config.Homeserver.Asmux {
urlPath := intent.BuildBaseURL("_matrix", "client", "unstable", "com.beeper.asmux", "dms")
urlPath := intent.BuildURL(mautrix.ClientURLPath{"unstable", "com.beeper.asmux", "dms"})
_, err = intent.MakeFullRequest(mautrix.FullRequest{
Method: method,
URL: urlPath,